| OLD | NEW |
| 1 // Copyright 2013 the V8 project authors. All rights reserved. | 1 // Copyright 2013 the V8 project authors. All rights reserved. |
| 2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
| 3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
| 4 // met: | 4 // met: |
| 5 // | 5 // |
| 6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
| 7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
| 8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
| 9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
| 10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 88 stored_token = Token::{{args[2]}}; | 88 stored_token = Token::{{args[2]}}; |
| 89 } | 89 } |
| 90 {% elif type == 'check_escaped_identifier_start' %} | 90 {% elif type == 'check_escaped_identifier_start' %} |
| 91 if (!ValidIdentifierStart()) goto default_action; | 91 if (!ValidIdentifierStart()) goto default_action; |
| 92 next_.has_escapes = true; | 92 next_.has_escapes = true; |
| 93 {% elif type == 'check_escaped_identifier_part' %} | 93 {% elif type == 'check_escaped_identifier_part' %} |
| 94 if (!ValidIdentifierPart()) goto default_action; | 94 if (!ValidIdentifierPart()) goto default_action; |
| 95 next_.has_escapes = true; | 95 next_.has_escapes = true; |
| 96 {% elif type == 'if_line_terminator_backtrack' %} | 96 {% elif type == 'if_line_terminator_backtrack' %} |
| 97 if (!has_line_terminator_before_next_) { | 97 if (!has_line_terminator_before_next_) { |
| 98 {{dispatch_match_action('backtrack', args)}} | 98 {{dispatch_match_action('manual_backtrack', args)}} |
| 99 } | 99 } |
| 100 {% elif type == 'store_lexing_state' %} |
| 101 STORE_LEXING_STATE(); |
| 102 {% elif type == 'chain' %} |
| 103 {%- for arg in args %} |
| 104 {{dispatch_entry_action(arg.name(), arg.args())}} |
| 105 {% endfor -%} |
| 100 {% else %} | 106 {% else %} |
| 101 uncompilable code for {{type}} {{args}} | 107 uncompilable code for {{type}} {{args}} |
| 102 {% endif -%} | 108 {% endif -%} |
| 103 {%- endmacro -%} | 109 {%- endmacro -%} |
| 104 | 110 |
| 105 | 111 |
| 106 {#- match actions must all explicitly jump or return -#} | 112 {#- match actions must all explicitly jump or return -#} |
| 107 {% macro dispatch_match_action(type, args) -%} | 113 {% macro dispatch_match_action(type, args) -%} |
| 108 {% if type == 'terminate' %} | 114 {% if type == 'terminate' %} |
| 109 {{dispatch_match_action('backtrack', ('1', 'EOS'))}} | 115 {{dispatch_match_action('manual_backtrack', ('1', 'EOS'))}} |
| 110 {% elif type == 'terminate_illegal' %} | 116 {% elif type == 'terminate_illegal' %} |
| 111 start_ = marker; | 117 start_ = marker; |
| 112 {{dispatch_match_action('backtrack', ('1', 'ILLEGAL'))}} | 118 {{dispatch_match_action('manual_backtrack', ('1', 'ILLEGAL'))}} |
| 113 {% elif type == 'skip' %} | 119 {% elif type == 'skip' %} |
| 114 RESET_START(); | 120 RESET_START(); |
| 115 {%- if encoding == 'utf16'-%} | 121 {%- if encoding == 'utf16'-%} |
| 116 next_.is_onebyte = true; | 122 next_.is_onebyte = true; |
| 117 {%- endif -%} | 123 {%- endif -%} |
| 118 goto state_entry_0; | 124 goto state_entry_0; |
| 119 {% elif type == 'skip_and_terminate' %} | 125 {% elif type == 'skip_and_terminate' %} |
| 120 RESET_START(); | 126 RESET_START(); |
| 121 --start_; | 127 --start_; |
| 122 {{dispatch_match_action('terminate', None)}} | 128 {{dispatch_match_action('terminate', None)}} |
| (...skipping 19 matching lines...) Expand all Loading... |
| 142 if (harmony_{{args[0]}}_) { | 148 if (harmony_{{args[0]}}_) { |
| 143 DO_TOKEN(Token::{{args[1]}}); | 149 DO_TOKEN(Token::{{args[1]}}); |
| 144 } else { | 150 } else { |
| 145 DO_TOKEN(Token::{{args[2]}}); | 151 DO_TOKEN(Token::{{args[2]}}); |
| 146 } | 152 } |
| 147 return; | 153 return; |
| 148 {% elif type == 'octal_number' %} | 154 {% elif type == 'octal_number' %} |
| 149 last_octal_end_ = cursor_; | 155 last_octal_end_ = cursor_; |
| 150 DO_TOKEN(Token::NUMBER); | 156 DO_TOKEN(Token::NUMBER); |
| 151 return; | 157 return; |
| 152 {% elif type == 'backtrack' %} | 158 {% elif type == 'manual_backtrack' %} |
| 153 BACKWARD({{args[0]}}); | 159 BACKWARD({{args[0]}}); |
| 154 DO_TOKEN(Token::{{args[1]}}); | 160 DO_TOKEN(Token::{{args[1]}}); |
| 155 return; | 161 return; |
| 162 {% elif type == 'backtrack' %} |
| 163 RESTORE_LEXING_STATE(); |
| 164 {{dispatch_match_action(args[0].name(), args[0].args())}} |
| 156 {% else %} | 165 {% else %} |
| 157 uncompilable code for {{type}} {{args}} | 166 uncompilable code for {{type}} {{args}} |
| 158 {% endif -%} | 167 {% endif -%} |
| 159 {%- endmacro -%} | 168 {%- endmacro -%} |
| 160 | 169 |
| 161 | 170 |
| 162 {%- macro long_char_check() -%} | 171 {%- macro long_char_check() -%} |
| 163 {%- if encoding == 'utf16'-%} | 172 {%- if encoding == 'utf16'-%} |
| 164 primary_char > {{upper_bound}} | 173 primary_char > {{upper_bound}} |
| 165 {%- elif encoding == 'utf8'-%} | 174 {%- elif encoding == 'utf8'-%} |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 289 goto default_action; {# this is wrong, should be CRASH(); #} | 298 goto default_action; {# this is wrong, should be CRASH(); #} |
| 290 | 299 |
| 291 {%- endmacro %} | 300 {%- endmacro %} |
| 292 | 301 |
| 293 #include "lexer/experimental-scanner.h" | 302 #include "lexer/experimental-scanner.h" |
| 294 | 303 |
| 295 #define RESET_START() { \ | 304 #define RESET_START() { \ |
| 296 start_ = cursor_; \ | 305 start_ = cursor_; \ |
| 297 } | 306 } |
| 298 | 307 |
| 308 #define STORE_LEXING_STATE() { \ |
| 309 stored_marker = marker; \ |
| 310 stored_cursor = cursor_; \ |
| 311 stored_start = start_; \ |
| 312 } |
| 313 |
| 314 #define RESTORE_LEXING_STATE() { \ |
| 315 marker = stored_marker; \ |
| 316 cursor_ = stored_cursor; \ |
| 317 start_ = stored_start; \ |
| 318 } |
| 319 |
| 299 #define DO_TOKEN(T) { \ | 320 #define DO_TOKEN(T) { \ |
| 300 next_.beg_pos = start_ - buffer_; \ | 321 next_.beg_pos = start_ - buffer_; \ |
| 301 next_.end_pos = cursor_ - buffer_; \ | 322 next_.end_pos = cursor_ - buffer_; \ |
| 302 next_.token = T; \ | 323 next_.token = T; \ |
| 303 RESET_START(); \ | 324 RESET_START(); \ |
| 304 } | 325 } |
| 305 | 326 |
| 306 #define FORWARD() { \ | 327 #define FORWARD() { \ |
| 307 cursor_++; \ | 328 cursor_++; \ |
| 308 } | 329 } |
| (...skipping 17 matching lines...) Expand all Loading... |
| 326 namespace internal { | 347 namespace internal { |
| 327 template<> | 348 template<> |
| 328 void ExperimentalScanner<{{char_type}}>::Scan() { | 349 void ExperimentalScanner<{{char_type}}>::Scan() { |
| 329 | 350 |
| 330 // Setup environment. | 351 // Setup environment. |
| 331 next_.has_escapes = false; | 352 next_.has_escapes = false; |
| 332 next_.is_onebyte = true; | 353 next_.is_onebyte = true; |
| 333 Token::Value stored_token; | 354 Token::Value stored_token; |
| 334 const {{char_type}} * marker; | 355 const {{char_type}} * marker; |
| 335 {{char_type}} primary_char; | 356 {{char_type}} primary_char; |
| 357 const {{char_type}} * stored_marker; {# TODO(dcarney): complete this #} |
| 358 const {{char_type}} * stored_cursor; |
| 359 const {{char_type}} * stored_start; |
| 336 | 360 |
| 337 {# first node is start node #} | 361 {# first node is start node #} |
| 338 {% for dfa_state in dfa_states -%} | 362 {% for dfa_state in dfa_states -%} |
| 339 {%- if not dfa_state['inline'] %} | 363 {%- if not dfa_state['inline'] %} |
| 340 {{ do_dfa_state(dfa_state['node_number']) }} | 364 {{ do_dfa_state(dfa_state['node_number']) }} |
| 341 {%- endif -%} | 365 {%- endif -%} |
| 342 {%- endfor %} | 366 {%- endfor %} |
| 343 | 367 |
| 344 // Execute the default action. | 368 // Execute the default action. |
| 345 default_action: | 369 default_action: |
| 346 {%- if debug_print %} | 370 {%- if debug_print %} |
| 347 fprintf(stderr, "default action\n"); | 371 fprintf(stderr, "default action\n"); |
| 348 {% endif -%} | 372 {% endif -%} |
| 349 {%- set action = default_action.term() -%} | 373 {%- set action = default_action.term() -%} |
| 350 {{dispatch_match_action(action.name(), action.args())}} | 374 {{dispatch_match_action(action.name(), action.args())}} |
| 351 CRASH(); | 375 CRASH(); |
| 352 | 376 |
| 353 if (false) { | 377 if (false) { |
| 354 // force use of stored_token | 378 // force use of stored_token |
| 355 stored_token = Token::ILLEGAL; | 379 stored_token = Token::ILLEGAL; |
| 356 // force use of marker | 380 // force use of marker |
| 357 marker = NULL; | 381 marker = NULL; |
| 358 // force use of state_entry_0 | 382 // force use of state_entry_0 |
| 359 goto state_entry_0; | 383 goto state_entry_0; |
| 360 } | 384 } |
| 361 } | 385 } |
| 362 } } | 386 } } |
| 363 | 387 |
| OLD | NEW |