| 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 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 92 } | 92 } |
| 93 p[0] = state.current_state | 93 p[0] = state.current_state |
| 94 | 94 |
| 95 def p_transition_rules(self, p): | 95 def p_transition_rules(self, p): |
| 96 '''transition_rules : transition_rule transition_rules | 96 '''transition_rules : transition_rule transition_rules |
| 97 | empty''' | 97 | empty''' |
| 98 | 98 |
| 99 def p_transition_rule(self, p): | 99 def p_transition_rule(self, p): |
| 100 '''transition_rule : composite_regex action | 100 '''transition_rule : composite_regex action |
| 101 | DEFAULT_ACTION default_action | 101 | DEFAULT_ACTION default_action |
| 102 | EOS eos |
| 102 | CATCH_ALL action''' | 103 | CATCH_ALL action''' |
| 103 precedence = RuleParser.__rule_precedence_counter | 104 precedence = RuleParser.__rule_precedence_counter |
| 104 RuleParser.__rule_precedence_counter += 1 | 105 RuleParser.__rule_precedence_counter += 1 |
| 105 action = p[2] | 106 action = p[2] |
| 106 (entry_action, match_action, transition) = action | 107 (entry_action, match_action, transition) = action |
| 107 if transition and not transition in self.__keyword_transitions: | 108 if transition and not transition in self.__keyword_transitions: |
| 108 assert not transition == 'default', "can't append default graph" | 109 assert not transition == 'default', "can't append default graph" |
| 109 self.__state.transitions.add(transition) | 110 self.__state.transitions.add(transition) |
| 110 rules = self.__state.rules[self.__state.current_state] | 111 rules = self.__state.rules[self.__state.current_state] |
| 111 if p[1] == 'default_action': | 112 if p[1] == 'default_action': |
| 112 assert self.__state.current_state == 'default' | 113 assert self.__state.current_state == 'default' |
| 113 assert not rules['default_action'] | 114 assert not rules['default_action'] |
| 114 rules['default_action'] = action | 115 rules['default_action'] = action |
| 115 elif p[1] == 'catch_all': | 116 elif p[1] == 'eos' or p[1] == 'catch_all': |
| 116 assert p[1] not in rules['uniques'] | 117 assert p[1] not in rules['uniques'] |
| 117 rules['uniques'][p[1]] = True | 118 rules['uniques'][p[1]] = True |
| 118 rules['regex'].append((NfaBuilder.unique_key(p[1]), precedence, action)) | 119 rules['regex'].append((NfaBuilder.unique_key(p[1]), precedence, action)) |
| 119 else: | 120 else: |
| 120 regex = p[1] | 121 regex = p[1] |
| 121 rules['regex'].append((regex, precedence, action)) | 122 rules['regex'].append((regex, precedence, action)) |
| 122 | 123 |
| 123 def p_action(self, p): | 124 def p_action(self, p): |
| 124 '''action : ACTION_OPEN maybe_identifier_action OR maybe_identifier_action O
R maybe_transition ACTION_CLOSE''' | 125 '''action : ACTION_OPEN maybe_identifier_action OR maybe_identifier_action O
R maybe_transition ACTION_CLOSE''' |
| 125 p[0] = (p[2], p[4], p[6]) | 126 p[0] = (p[2], p[4], p[6]) |
| 126 | 127 |
| 127 def p_default_action(self, p): | 128 def p_default_action(self, p): |
| 128 'default_action : ACTION_OPEN identifier_action ACTION_CLOSE' | 129 'default_action : ACTION_OPEN identifier_action ACTION_CLOSE' |
| 129 p[0] = (None, p[2], None) | 130 p[0] = (None, p[2], None) |
| 130 | 131 |
| 132 def p_eos(self, p): |
| 133 'eos : ACTION_OPEN identifier_action ACTION_CLOSE' |
| 134 p[0] = (None, p[2], None) |
| 135 |
| 131 def p_maybe_identifier_action(self, p): | 136 def p_maybe_identifier_action(self, p): |
| 132 '''maybe_identifier_action : identifier_action | 137 '''maybe_identifier_action : identifier_action |
| 133 | empty''' | 138 | empty''' |
| 134 p[0] = p[1] | 139 p[0] = p[1] |
| 135 | 140 |
| 136 def p_maybe_transition(self, p): | 141 def p_maybe_transition(self, p): |
| 137 '''maybe_transition : IDENTIFIER | 142 '''maybe_transition : IDENTIFIER |
| 138 | empty''' | 143 | empty''' |
| 139 p[0] = p[1] | 144 p[0] = p[1] |
| 140 | 145 |
| (...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 325 if k == 'default': continue | 330 if k == 'default': continue |
| 326 process(k, v) | 331 process(k, v) |
| 327 process('default', parser_state.rules['default']) | 332 process('default', parser_state.rules['default']) |
| 328 # build the automata | 333 # build the automata |
| 329 for rule_name, graph in rule_map.items(): | 334 for rule_name, graph in rule_map.items(): |
| 330 self.__automata[rule_name] = RuleProcessor.Automata(builder, graph) | 335 self.__automata[rule_name] = RuleProcessor.Automata(builder, graph) |
| 331 self.__rule_trees[rule_name] = graph | 336 self.__rule_trees[rule_name] = graph |
| 332 # process default_action | 337 # process default_action |
| 333 default_action = parser_state.rules['default']['default_action'] | 338 default_action = parser_state.rules['default']['default_action'] |
| 334 self.default_action = Action(None, default_action[1]) if default_action else
None | 339 self.default_action = Action(None, default_action[1]) if default_action else
None |
| OLD | NEW |