Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(224)

Unified Diff: tools/lexer_generator/code_generator.jinja

Issue 59983005: Experimental parser: cleanup switch generation (Closed) Base URL: https://v8.googlecode.com/svn/branches/experimental/parser
Patch Set: Created 7 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | tools/lexer_generator/code_generator.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tools/lexer_generator/code_generator.jinja
diff --git a/tools/lexer_generator/code_generator.jinja b/tools/lexer_generator/code_generator.jinja
index fb5d8ea2986f961ef10a6a0aa3d7c2c87091db14..acc2262b0c513ac435f2ed3af685142a96b79a71 100644
--- a/tools/lexer_generator/code_generator.jinja
+++ b/tools/lexer_generator/code_generator.jinja
@@ -83,30 +83,32 @@
fprintf(stderr, "char at hand is %c (%d)\n", yych, yych);
{% endif -%}
+ {%- macro do_transition(transition_state_id) -%}
+ {%- set inline_transition = dfa_states[transition_state_id]['inline'] %}
+ FORWARD();
+ {%- if inline_transition %}
+ {{ do_dfa_state(transition_state_id, True) }}
+ {% else %}
+ goto code_{{transition_state_id}};
+ {% endif %}
+ {%- endmacro -%}
+
{%- if state['switch_transitions'] -%}
switch(yych) {
- {%- for key, transition_state_id in state['switch_transitions'] %}
- case {{key}}:
- {%- set inline_transition = dfa_states[transition_state_id]['inline'] %}
- FORWARD();
- {%- if inline_transition %}
- {{ do_dfa_state(transition_state_id, True) }}
- {% else %}
- goto code_{{transition_state_id}};
- {% endif %}
+ {%- for ranges, transition_state_id in state['switch_transitions'] %}
+ {%- for r in ranges -%}
+ {%- for key in range(r[0], r[1] + 1) -%}
+ case {{key}}:
+ {% endfor %}
+ {%- endfor -%}
+ {{ do_transition(transition_state_id) }}
{% endfor -%}
}
{%- endif -%}
{%- for key, transition_state_id in state.transitions %}
if ({{do_key(key)}}) {
- {%- set inline_transition = dfa_states[transition_state_id]['inline'] %}
- FORWARD();
- {%- if inline_transition %}
- {{ do_dfa_state(transition_state_id, True) }}
- {% else %}
- goto code_{{transition_state_id}};
- {% endif %}
+ {{ do_transition(transition_state_id) }}
}
{% endfor -%}
« no previous file with comments | « no previous file | tools/lexer_generator/code_generator.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698