| OLD | NEW |
| (Empty) | |
| 1 #include "lexer/even-more-experimental-scanner.h" |
| 2 |
| 3 |
| 4 // TODO implement CLASS checks |
| 5 {%- macro do_key(key) -%} |
| 6 {%- for r in key.range_iter() -%} |
| 7 {%- if not loop.first %} || {% endif -%} |
| 8 {%- if r[0] == 'LATIN_1' -%} |
| 9 ({{r[1][0]}} <= yych && yych <= {{r[1][1]}}) |
| 10 {%- else -%} |
| 11 false |
| 12 {%- endif -%} |
| 13 {%- endfor -%} |
| 14 {%- endmacro -%} |
| 15 |
| 16 |
| 17 {% macro dispatch_action(type, value) -%} |
| 18 {%- if type == 'code' %} |
| 19 {{value}} |
| 20 {% elif type == 'terminate' %} |
| 21 PUSH_TOKEN(Token::EOS); |
| 22 return 0; |
| 23 {% elif type == 'terminate_illegal' %} |
| 24 PUSH_TOKEN(Token::EOS); |
| 25 return 1; |
| 26 {% elif type == 'skip' %} |
| 27 SKIP(); |
| 28 {% elif type == 'skip_and_terminate' %} |
| 29 SKIP(); |
| 30 --start_; |
| 31 {{dispatch_action('terminate', None)}} |
| 32 {% elif type == 'push_line_terminator' %} |
| 33 PUSH_LINE_TERMINATOR(); |
| 34 {% elif type == 'push_token' %} |
| 35 PUSH_TOKEN(Token::{{value}}) |
| 36 {% else %} |
| 37 uncompilable code for {{type}} |
| 38 {% endif -%} |
| 39 {%- endmacro -%} |
| 40 |
| 41 |
| 42 {%- macro do_dfa_state(state) -%} |
| 43 |
| 44 {%- if start_node_number == state.node_number() %} |
| 45 code_start: |
| 46 {% endif %} |
| 47 code_{{state.node_number()}}: |
| 48 |
| 49 {% if debug_print %} |
| 50 fprintf(stderr, "state {{state.node_number()}}\n"); |
| 51 {% endif -%} |
| 52 |
| 53 {%- set entry_action = state.action().entry_action() if state.action() else No
ne -%} |
| 54 {%- if entry_action %} |
| 55 {{ dispatch_action(entry_action[0], entry_action[1]) }} |
| 56 {%- endif %} |
| 57 |
| 58 {%- if debug_print %} |
| 59 fprintf(stderr, "char at hand is %c (%d)\n", yych, yych); |
| 60 {% endif %} |
| 61 |
| 62 // matchers |
| 63 {%- for match_key, match_state in state.transitions().items() %} |
| 64 if ({{do_key(match_key)}}) { |
| 65 FORWARD(); |
| 66 goto code_{{match_state.node_number()}}; |
| 67 } |
| 68 {% endfor -%} |
| 69 |
| 70 {%- set match_action = state.action().match_action() if state.action() else No
ne -%} |
| 71 |
| 72 {%- if match_action %} |
| 73 {{ dispatch_action(match_action[0], match_action[1]) }} |
| 74 goto code_start; |
| 75 {% else %} |
| 76 goto default_action; |
| 77 {%- endif %} |
| 78 |
| 79 {%- endmacro %} |
| 80 |
| 81 |
| 82 #define PUSH_TOKEN(T) { \ |
| 83 send(T); \ |
| 84 start_ = cursor_; \ |
| 85 just_seen_line_terminator_ = false; \ |
| 86 } |
| 87 |
| 88 #define PUSH_LINE_TERMINATOR(s) { \ |
| 89 start_ = cursor_; \ |
| 90 just_seen_line_terminator_ = true; \ |
| 91 } |
| 92 |
| 93 #define FORWARD() { \ |
| 94 yych = *(++cursor_); \ |
| 95 } |
| 96 |
| 97 #define SKIP() { \ |
| 98 start_ = cursor_; \ |
| 99 } |
| 100 |
| 101 namespace v8 { |
| 102 namespace internal { |
| 103 uint32_t EvenMoreExperimentalScanner::DoLex() { |
| 104 // Setup environment. |
| 105 YYCTYPE yych = *cursor_; |
| 106 //FORWARD(); |
| 107 // Jump into the start node |
| 108 // FIXME - put the start code here |
| 109 goto code_{{start_node_number}}; |
| 110 |
| 111 {% for dfa_state in dfa_states -%} |
| 112 {{ do_dfa_state(dfa_state) }} |
| 113 {%- endfor %} |
| 114 |
| 115 // Should never fall off the edge. |
| 116 goto fell_through; |
| 117 // Execute the default action. |
| 118 default_action: |
| 119 {%- if debug_print %} |
| 120 fprintf(stderr, "default action\n"); |
| 121 {% endif -%} |
| 122 {{dispatch_action(default_action[0], default_action[1])}} |
| 123 FORWARD(); |
| 124 goto code_start; |
| 125 return 0; |
| 126 |
| 127 fell_through: |
| 128 CHECK(false); |
| 129 } |
| 130 } } |
| 131 |
| OLD | NEW |