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

Side by Side Diff: tools/lexer_generator/code_generator.jinja

Issue 83583002: Experimental parser: utf8 added to build (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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « src/lexer/lexer-shell.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #include "lexer/experimental-scanner.h" 1 #include "lexer/experimental-scanner.h"
2 2
3 {%- macro do_key(key) -%} 3 {%- macro do_key(key) -%}
4 {%- for r in key -%} 4 {%- for r in key -%}
5 {%- if not loop.first %} || {% endif -%} 5 {%- if not loop.first %} || {% endif -%}
6 {%- if r[0] == 'PRIMARY_RANGE' -%} 6 {%- if r[0] == 'PRIMARY_RANGE' -%}
7 {%- if r[1][0] == r[1][1] -%} 7 {%- if r[1][0] == r[1][1] -%}
8 primary_char == {{r[1][0]}} 8 primary_char == {{r[1][0]}}
9 {%- elif r[1][0] == 0 -%} 9 {%- elif r[1][0] == 0 -%}
10 primary_char <= {{r[1][1]}} 10 primary_char <= {{r[1][1]}}
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
67 PUSH_TOKEN(Token::{{value[1][1]}}); 67 PUSH_TOKEN(Token::{{value[1][1]}});
68 } 68 }
69 {% elif type == 'set_marker' %} 69 {% elif type == 'set_marker' %}
70 marker_ = cursor_ - {{value}}; 70 marker_ = cursor_ - {{value}};
71 {% else %} 71 {% else %}
72 uncompilable code for {{type}} 72 uncompilable code for {{type}}
73 {% endif -%} 73 {% endif -%}
74 {%- endmacro -%} 74 {%- endmacro -%}
75 75
76 76
77 {%- macro long_char_check() -%}
78 {%- if encoding == 'utf16'-%}
79 primary_char > {{upper_bound}}
80 {%- elif encoding == 'utf8'-%}
81 primary_char < 0
82 {%- else -%}
83 uncompilable code for {{encoding}}
84 {%- endif -%}
85 {%- endmacro -%}
86
87
88 {%- macro long_char_create() -%}
89 {%- if encoding == 'utf16'-%}
90 const uint32_t long_char = primary_char;
91 {%- elif encoding == 'utf8'-%}
92 unsigned bytes_read = 0;
93 const uint32_t long_char = unibrow::Utf8::CalculateValue(
94 reinterpret_cast<uint8_t*>(cursor_),
95 buffer_end_ - cursor_,
96 &bytes_read);
97 cursor_ += bytes_read;
98 if (long_char == unibrow::Utf8::kBadChar) goto default_action;
99 {%- else -%}
100 uncompilable code for {{encoding}}
101 {%- endif -%}
102 {%- endmacro -%}
103
104
77 {%- macro do_dfa_state(node_number, inline) -%} 105 {%- macro do_dfa_state(node_number, inline) -%}
78 106
79 {%- set state = dfa_states[node_number] -%} 107 {%- set state = dfa_states[node_number] -%}
80 108
81 {%- if not inline -%} 109 {%- if not inline -%}
82 {%- if state['inline'] -%} 110 {%- if state['inline'] -%}
83 bad generated code for {{node_number}} 111 bad generated code for {{node_number}}
84 {%- endif -%} 112 {%- endif -%}
85 {%- if start_node_number == node_number -%} 113 {%- if start_node_number == node_number -%}
86 code_start: 114 code_start:
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
133 } 161 }
134 {% endfor -%} 162 {% endfor -%}
135 163
136 {%- for key, transition_state_id in state['deferred_transitions'] %} 164 {%- for key, transition_state_id in state['deferred_transitions'] %}
137 if ({{do_key(key)}}) { // deferred transition 165 if ({{do_key(key)}}) { // deferred transition
138 {{ do_transition(transition_state_id) }} 166 {{ do_transition(transition_state_id) }}
139 } 167 }
140 {% endfor -%} 168 {% endfor -%}
141 169
142 {%- if state['long_char_transitions'] -%} 170 {%- if state['long_char_transitions'] -%}
143 {# TODO macro this up for utf8 #} 171 if ({{long_char_check()}}) {
144 if (primary_char > {{upper_bound}}) { 172 {{long_char_create()}}
145 uint32_t long_char = primary_char;
146 {%- for key, transition_state_id in state['long_char_transitions'] %} 173 {%- for key, transition_state_id in state['long_char_transitions'] %}
147 if ({{do_key(key)}}) { // long_char transition 174 if ({{do_key(key)}}) { // long_char transition
148 {{ do_transition(transition_state_id) }} 175 {{ do_transition(transition_state_id) }}
149 } 176 }
150 {% endfor -%} 177 {% endfor -%}
151 } 178 }
152 {%- endif-%} 179 {%- endif-%}
153 180
154 {%- set match_action = state.match_action -%} 181 {%- set match_action = state.match_action -%}
155 182
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
232 {% endif -%} 259 {% endif -%}
233 {{dispatch_action(default_action[0], default_action[1])}} 260 {{dispatch_action(default_action[0], default_action[1])}}
234 FORWARD(); 261 FORWARD();
235 goto code_start; 262 goto code_start;
236 263
237 fell_through: 264 fell_through:
238 CHECK(false); 265 CHECK(false);
239 } 266 }
240 } } 267 } }
241 268
OLDNEW
« no previous file with comments | « src/lexer/lexer-shell.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698