| 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 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 58 {%- endif -%} | 58 {%- endif -%} |
| 59 {%- else -%} | 59 {%- else -%} |
| 60 uncompilable code for {{encoding}} {{r[0]}} {{r[1]}} | 60 uncompilable code for {{encoding}} {{r[0]}} {{r[1]}} |
| 61 {%- endif -%} | 61 {%- endif -%} |
| 62 {%- endfor -%} | 62 {%- endfor -%} |
| 63 {%- endmacro -%} | 63 {%- endmacro -%} |
| 64 | 64 |
| 65 | 65 |
| 66 {#- entry actions must not change the value of the cursor | 66 {#- entry actions must not change the value of the cursor |
| 67 unless they jump -#} | 67 unless they jump -#} |
| 68 {% macro dispatch_entry_action(type, value) -%} | 68 {% macro dispatch_entry_action(type, args) -%} |
| 69 {% if type == 'store_token' %} | 69 {% if type == 'store_token' %} |
| 70 stored_token = Token::{{value}}; | 70 stored_token = Token::{{args[0]}}; |
| 71 {% elif type == 'set_marker' %} | 71 {% elif type == 'set_marker' %} |
| 72 marker = cursor_ - {{value}}; | 72 marker = cursor_ - {{args[0]}}; |
| 73 {% elif type == 'set_has_escapes' %} | 73 {% elif type == 'set_has_escapes' %} |
| 74 next_.has_escapes = true; | 74 next_.has_escapes = true; |
| 75 {% elif type == 'octal_inside_string' %} | 75 {% elif type == 'octal_inside_string' %} |
| 76 last_octal_end_ = cursor_; | 76 last_octal_end_ = cursor_; |
| 77 next_.has_escapes = true; | 77 next_.has_escapes = true; |
| 78 {% elif type == 'line_terminator_in_multiline_comment' %} | 78 {% elif type == 'line_terminator_in_multiline_comment' %} |
| 79 has_multiline_comment_before_next_ = true; | 79 has_multiline_comment_before_next_ = true; |
| 80 {% elif type == 'check_escaped_identifier_start' %} | 80 {% elif type == 'check_escaped_identifier_start' %} |
| 81 if (!ValidIdentifierStart()) goto default_action; | 81 if (!ValidIdentifierStart()) goto default_action; |
| 82 next_.has_escapes = true; | 82 next_.has_escapes = true; |
| 83 {% elif type == 'check_escaped_identifier_part' %} | 83 {% elif type == 'check_escaped_identifier_part' %} |
| 84 if (!ValidIdentifierPart()) goto default_action; | 84 if (!ValidIdentifierPart()) goto default_action; |
| 85 next_.has_escapes = true; | 85 next_.has_escapes = true; |
| 86 {% elif type == 'if_line_terminator_backtrack' %} | 86 {% elif type == 'if_line_terminator_backtrack' %} |
| 87 if (!has_line_terminator_before_next_) { | 87 if (!has_line_terminator_before_next_) { |
| 88 {{dispatch_match_action('backtrack', value)}} | 88 {{dispatch_match_action('backtrack', args)}} |
| 89 } | 89 } |
| 90 {% else %} | 90 {% else %} |
| 91 uncompilable code for {{type}} {{value}} | 91 uncompilable code for {{type}} {{args}} |
| 92 {% endif -%} | 92 {% endif -%} |
| 93 {%- endmacro -%} | 93 {%- endmacro -%} |
| 94 | 94 |
| 95 | 95 |
| 96 {#- match actions must all explicitly jump or return -#} | 96 {#- match actions must all explicitly jump or return -#} |
| 97 {% macro dispatch_match_action(type, value) -%} | 97 {% macro dispatch_match_action(type, args) -%} |
| 98 {% if type == 'terminate' %} | 98 {% if type == 'terminate' %} |
| 99 {{dispatch_match_action('backtrack', ('1', 'EOS'))}} | 99 {{dispatch_match_action('backtrack', ('1', 'EOS'))}} |
| 100 {% elif type == 'terminate_illegal' %} | 100 {% elif type == 'terminate_illegal' %} |
| 101 start_ = marker; | 101 start_ = marker; |
| 102 {{dispatch_match_action('backtrack', ('1', 'ILLEGAL'))}} | 102 {{dispatch_match_action('backtrack', ('1', 'ILLEGAL'))}} |
| 103 {% elif type == 'skip' %} | 103 {% elif type == 'skip' %} |
| 104 RESET_START(); | 104 RESET_START(); |
| 105 {%- if encoding == 'utf16'-%} | 105 {%- if encoding == 'utf16'-%} |
| 106 next_.is_onebyte = true; | 106 next_.is_onebyte = true; |
| 107 {%- endif -%} | 107 {%- endif -%} |
| 108 goto state_entry_0; | 108 goto state_entry_0; |
| 109 {% elif type == 'skip_and_terminate' %} | 109 {% elif type == 'skip_and_terminate' %} |
| 110 RESET_START(); | 110 RESET_START(); |
| 111 --start_; | 111 --start_; |
| 112 {{dispatch_match_action('terminate', None)}} | 112 {{dispatch_match_action('terminate', None)}} |
| 113 {% elif type == 'line_terminator' %} | 113 {% elif type == 'line_terminator' %} |
| 114 RESET_START(); | 114 RESET_START(); |
| 115 {%- if encoding == 'utf16'-%} | 115 {%- if encoding == 'utf16'-%} |
| 116 next_.is_onebyte = true; | 116 next_.is_onebyte = true; |
| 117 {%- endif -%} | 117 {%- endif -%} |
| 118 has_line_terminator_before_next_ = true; | 118 has_line_terminator_before_next_ = true; |
| 119 goto state_entry_0; | 119 goto state_entry_0; |
| 120 {% elif type == 'token' %} | 120 {% elif type == 'token' %} |
| 121 DO_TOKEN(Token::{{value}}) | 121 DO_TOKEN(Token::{{args[0]}}) |
| 122 return; | 122 return; |
| 123 {% elif type == 'goto_start' %} | 123 {% elif type == 'goto_start' %} |
| 124 {{ jump(value[0]) }} | 124 {{ jump(args[0]|int) }} |
| 125 {% elif type == 'store_token_and_goto' %} | 125 {% elif type == 'store_token_and_goto' %} |
| 126 stored_token = Token::{{value[0]}}; | 126 stored_token = Token::{{args[0]}}; |
| 127 {{ jump(value[1]) }} | 127 {{ jump(args[1]|int) }} |
| 128 {% elif type == 'do_stored_token' %} | 128 {% elif type == 'do_stored_token' %} |
| 129 DO_TOKEN(stored_token) | 129 DO_TOKEN(stored_token) |
| 130 return; | 130 return; |
| 131 {% elif type == 'do_token_and_go_forward' %} | 131 {% elif type == 'do_token_and_go_forward' %} |
| 132 DO_TOKEN(Token::{{value}}); | 132 DO_TOKEN(Token::{{args[0]}}); |
| 133 FORWARD(); | 133 FORWARD(); |
| 134 RESET_START(); | 134 RESET_START(); |
| 135 return; | 135 return; |
| 136 {% elif type == 'harmony_token' %} | 136 {% elif type == 'harmony_token' %} |
| 137 if (harmony_{{value[0]}}_) { | 137 if (harmony_{{args[0]}}_) { |
| 138 DO_TOKEN(Token::{{value[1]}}); | 138 DO_TOKEN(Token::{{args[1]}}); |
| 139 } else { | 139 } else { |
| 140 DO_TOKEN(Token::{{value[2]}}); | 140 DO_TOKEN(Token::{{args[2]}}); |
| 141 } | 141 } |
| 142 return; | 142 return; |
| 143 {% elif type == 'store_harmony_token_and_goto' %} | 143 {% elif type == 'store_harmony_token_and_goto' %} |
| 144 if (harmony_{{value[0]}}_) { | 144 if (harmony_{{args[0]}}_) { |
| 145 stored_token = Token::{{value[1]}}; | 145 stored_token = Token::{{args[1]}}; |
| 146 } else { | 146 } else { |
| 147 stored_token = Token::{{value[2]}}; | 147 stored_token = Token::{{args[2]}}; |
| 148 } | 148 } |
| 149 {{ jump(value[3]) }} | 149 {{ jump(args[3]|int) }} |
| 150 {% elif type == 'octal_number' %} | 150 {% elif type == 'octal_number' %} |
| 151 last_octal_end_ = cursor_; | 151 last_octal_end_ = cursor_; |
| 152 DO_TOKEN(Token::NUMBER); | 152 DO_TOKEN(Token::NUMBER); |
| 153 return; | 153 return; |
| 154 {% elif type == 'backtrack' %} | 154 {% elif type == 'backtrack' %} |
| 155 BACKWARD({{value[0]}}); | 155 BACKWARD({{args[0]}}); |
| 156 DO_TOKEN(Token::{{value[1]}}); | 156 DO_TOKEN(Token::{{args[1]}}); |
| 157 return; | 157 return; |
| 158 {% else %} | 158 {% else %} |
| 159 uncompilable code for {{type}} {{value}} | 159 uncompilable code for {{type}} {{args}} |
| 160 {% endif -%} | 160 {% endif -%} |
| 161 {%- endmacro -%} | 161 {%- endmacro -%} |
| 162 | 162 |
| 163 | 163 |
| 164 {%- macro long_char_check() -%} | 164 {%- macro long_char_check() -%} |
| 165 {%- if encoding == 'utf16'-%} | 165 {%- if encoding == 'utf16'-%} |
| 166 primary_char > {{upper_bound}} | 166 primary_char > {{upper_bound}} |
| 167 {%- elif encoding == 'utf8'-%} | 167 {%- elif encoding == 'utf8'-%} |
| 168 primary_char < 0 | 168 primary_char < 0 |
| 169 {%- else -%} | 169 {%- else -%} |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 212 | 212 |
| 213 {% if debug_print %} | 213 {% if debug_print %} |
| 214 fprintf(stderr, | 214 fprintf(stderr, |
| 215 "state {{state.node_number}}, start %d, cursor %d\n", | 215 "state {{state.node_number}}, start %d, cursor %d\n", |
| 216 start_ - buffer_, | 216 start_ - buffer_, |
| 217 cursor_ - buffer_); | 217 cursor_ - buffer_); |
| 218 {% endif -%} | 218 {% endif -%} |
| 219 | 219 |
| 220 {%- set entry_action = state.entry_action -%} | 220 {%- set entry_action = state.entry_action -%} |
| 221 {%- if entry_action %} | 221 {%- if entry_action %} |
| 222 {{ dispatch_entry_action(entry_action[0], entry_action[1]) }} | 222 {{ dispatch_entry_action(entry_action.name(), entry_action.args()) }} |
| 223 {%- endif %} | 223 {%- endif %} |
| 224 | 224 |
| 225 {{ write_label('after_entry_code', node_number) }} | 225 {{ write_label('after_entry_code', node_number) }} |
| 226 | 226 |
| 227 {%- if debug_print %} | 227 {%- if debug_print %} |
| 228 fprintf(stderr, "char at hand is %c (%d)\n", primary_char, primary_char); | 228 fprintf(stderr, "char at hand is %c (%d)\n", primary_char, primary_char); |
| 229 {% endif -%} | 229 {% endif -%} |
| 230 | 230 |
| 231 {%- macro do_transition(jump_id) -%} | 231 {%- macro do_transition(jump_id) -%} |
| 232 {%- set transition_state_id = jump_table[jump_id][0] -%} | 232 {%- set transition_state_id = jump_table[jump_id][0] -%} |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 272 {%- for key, jump_id in state['deferred_transitions'] %} | 272 {%- for key, jump_id in state['deferred_transitions'] %} |
| 273 if ({{do_key(key)}}) { // long_char transition | 273 if ({{do_key(key)}}) { // long_char transition |
| 274 {{ do_transition(jump_id) }} | 274 {{ do_transition(jump_id) }} |
| 275 } | 275 } |
| 276 {% endfor -%} | 276 {% endfor -%} |
| 277 } | 277 } |
| 278 {%- endif -%} | 278 {%- endif -%} |
| 279 | 279 |
| 280 {%- set match_action = state.match_action -%} | 280 {%- set match_action = state.match_action -%} |
| 281 {%- if match_action %} | 281 {%- if match_action %} |
| 282 {{ dispatch_match_action(match_action[0], match_action[1]) }} | 282 {{ dispatch_match_action(match_action.name(), match_action.args()) }} |
| 283 CRASH(); | 283 CRASH(); |
| 284 {% else %} | 284 {% else %} |
| 285 goto default_action; | 285 goto default_action; |
| 286 {%- endif %} | 286 {%- endif %} |
| 287 | 287 |
| 288 {%- endmacro %} | 288 {%- endmacro %} |
| 289 | 289 |
| 290 #include "lexer/experimental-scanner.h" | 290 #include "lexer/experimental-scanner.h" |
| 291 | 291 |
| 292 #define RESET_START() { \ | 292 #define RESET_START() { \ |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 336 {%- if not dfa_state['inline'] %} | 336 {%- if not dfa_state['inline'] %} |
| 337 {{ do_dfa_state(dfa_state['node_number']) }} | 337 {{ do_dfa_state(dfa_state['node_number']) }} |
| 338 {%- endif -%} | 338 {%- endif -%} |
| 339 {%- endfor %} | 339 {%- endfor %} |
| 340 | 340 |
| 341 // Execute the default action. | 341 // Execute the default action. |
| 342 default_action: | 342 default_action: |
| 343 {%- if debug_print %} | 343 {%- if debug_print %} |
| 344 fprintf(stderr, "default action\n"); | 344 fprintf(stderr, "default action\n"); |
| 345 {% endif -%} | 345 {% endif -%} |
| 346 {{dispatch_match_action(default_action[0], default_action[1])}} | 346 {{dispatch_match_action(default_action.name(), default_action.args())}} |
| 347 CRASH(); | 347 CRASH(); |
| 348 | 348 |
| 349 if (false) { | 349 if (false) { |
| 350 // force use of stored_token | 350 // force use of stored_token |
| 351 stored_token = Token::ILLEGAL; | 351 stored_token = Token::ILLEGAL; |
| 352 // force use of marker | 352 // force use of marker |
| 353 marker = NULL; | 353 marker = NULL; |
| 354 // force use of state_entry_0 | 354 // force use of state_entry_0 |
| 355 goto state_entry_0; | 355 goto state_entry_0; |
| 356 } | 356 } |
| 357 } | 357 } |
| 358 } } | 358 } } |
| 359 | 359 |
| OLD | NEW |