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

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

Issue 83633002: Experimental parser: continue unifying the API with Scanner. (Closed) Base URL: https://v8.googlecode.com/svn/branches/experimental/parser
Patch Set: Created 7 years 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 172 matching lines...) Expand 10 before | Expand all | Expand 10 after
183 {%- if match_action %} 183 {%- if match_action %}
184 {{ dispatch_action(match_action[0], match_action[1]) }} 184 {{ dispatch_action(match_action[0], match_action[1]) }}
185 goto code_start; 185 goto code_start;
186 {% else %} 186 {% else %}
187 goto default_action; 187 goto default_action;
188 {%- endif %} 188 {%- endif %}
189 189
190 {%- endmacro %} 190 {%- endmacro %}
191 191
192 #define PREPARE_PUSH_TOKEN() { \ 192 #define PREPARE_PUSH_TOKEN() { \
193 *beg_pos_to_return = start_ - buffer_; \ 193 next_.beg_pos = start_ - buffer_; \
194 *end_pos_to_return = cursor_ - buffer_; \ 194 next_.end_pos = cursor_ - buffer_; \
195 start_ = cursor_; \ 195 start_ = cursor_; \
196 just_seen_line_terminator_ = false; \ 196 just_seen_line_terminator_ = false; \
197 } 197 }
198 198
199 #define PUSH_TOKEN(T) { \ 199 #define PUSH_TOKEN(T) { \
200 PREPARE_PUSH_TOKEN(); \ 200 PREPARE_PUSH_TOKEN(); \
201 return T; \ 201 next_.token = T; \
202 return; \
202 } 203 }
203 204
204 #define PUSH_TOKEN_AND_GO_FORWARD(T) {\ 205 #define PUSH_TOKEN_AND_GO_FORWARD(T) {\
205 PREPARE_PUSH_TOKEN(); \ 206 PREPARE_PUSH_TOKEN(); \
206 FORWARD(); \ 207 FORWARD(); \
207 return T; \ 208 next_.token = T; \
209 return; \
208 } 210 }
209 211
210 #define PUSH_EOS() { \ 212 #define PUSH_EOS() { \
211 cursor_ -= 1; \ 213 cursor_ -= 1; \
212 PUSH_TOKEN(Token::EOS); \ 214 PUSH_TOKEN(Token::EOS); \
213 } 215 }
214 216
215 #define PUSH_LINE_TERMINATOR(s) { \ 217 #define PUSH_LINE_TERMINATOR(s) { \
216 start_ = cursor_; \ 218 start_ = cursor_; \
217 just_seen_line_terminator_ = true; \ 219 just_seen_line_terminator_ = true; \
(...skipping 10 matching lines...) Expand all
228 else primary_char = *(cursor_); \ 230 else primary_char = *(cursor_); \
229 } 231 }
230 232
231 #define SKIP() { \ 233 #define SKIP() { \
232 start_ = cursor_; \ 234 start_ = cursor_; \
233 } 235 }
234 236
235 namespace v8 { 237 namespace v8 {
236 namespace internal { 238 namespace internal {
237 template<> 239 template<>
238 Token::Value ExperimentalScanner<{{char_type}}>::Next(int* beg_pos_to_return, 240 void ExperimentalScanner<{{char_type}}>::Scan() {
239 int* end_pos_to_return) {
240 // Setup environment. 241 // Setup environment.
241 {{char_type}} primary_char; 242 {{char_type}} primary_char;
242 if (cursor_ >= buffer_end_) primary_char = 0; 243 if (cursor_ >= buffer_end_) primary_char = 0;
243 else primary_char = *(cursor_); 244 else primary_char = *(cursor_);
244 245
245 {# first node is start node #} 246 {# first node is start node #}
246 {% for dfa_state in dfa_states -%} 247 {% for dfa_state in dfa_states -%}
247 {%- set inline = dfa_state['inline'] -%} 248 {%- set inline = dfa_state['inline'] -%}
248 {%- if not inline %} 249 {%- if not inline %}
249 {{ do_dfa_state(dfa_state['node_number'], False) }} 250 {{ do_dfa_state(dfa_state['node_number'], False) }}
250 {%- endif -%} 251 {%- endif -%}
251 {%- endfor %} 252 {%- endfor %}
252 253
253 // Should never fall off the edge. 254 // Should never fall off the edge.
254 goto fell_through; 255 goto fell_through;
255 // Execute the default action. 256 // Execute the default action.
256 default_action: 257 default_action:
257 {%- if debug_print %} 258 {%- if debug_print %}
258 fprintf(stderr, "default action\n"); 259 fprintf(stderr, "default action\n");
259 {% endif -%} 260 {% endif -%}
260 {{dispatch_action(default_action[0], default_action[1])}} 261 {{dispatch_action(default_action[0], default_action[1])}}
261 FORWARD(); 262 FORWARD();
262 goto code_start; 263 goto code_start;
263 264
264 fell_through: 265 fell_through:
265 CHECK(false); 266 CHECK(false);
266 } 267 }
267 } } 268 } }
268 269
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