| 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 |
| 11 # with the distribution. | 11 # with the distribution. |
| 12 # * Neither the name of Google Inc. nor the names of its | 12 # * Neither the name of Google Inc. nor the names of its |
| 13 # contributors may be used to endorse or promote products derived | 13 # contributors may be used to endorse or promote products derived |
| 14 # from this software without specific prior written permission. | 14 # from this software without specific prior written permission. |
| 15 # | 15 # |
| 16 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | 16 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 17 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | 17 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 18 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | 18 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 19 # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | 19 # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 20 # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | 20 # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 21 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | 21 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 22 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 22 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 23 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 23 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 24 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 24 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 25 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 25 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 26 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 26 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 27 | 27 |
| 28 import ply.yacc as yacc | 28 import ply.yacc as yacc |
| 29 from automaton import Action | 29 from automaton import Term, Action |
| 30 from rule_lexer import RuleLexer | 30 from rule_lexer import RuleLexer |
| 31 from regex_parser import RegexParser | 31 from regex_parser import RegexParser |
| 32 from nfa_builder import NfaBuilder | 32 from nfa_builder import NfaBuilder |
| 33 from dfa import Dfa | 33 from dfa import Dfa |
| 34 from dfa_optimizer import DfaOptimizer | 34 from dfa_optimizer import DfaOptimizer |
| 35 from transition_keys import TransitionKey, KeyEncoding | 35 from transition_keys import TransitionKey, KeyEncoding |
| 36 | 36 |
| 37 class RuleParserState: | 37 class RuleParserState: |
| 38 | 38 |
| 39 def __init__(self, encoding): | 39 def __init__(self, encoding): |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 141 def p_maybe_transition(self, p): | 141 def p_maybe_transition(self, p): |
| 142 '''maybe_transition : IDENTIFIER | 142 '''maybe_transition : IDENTIFIER |
| 143 | empty''' | 143 | empty''' |
| 144 p[0] = p[1] | 144 p[0] = p[1] |
| 145 | 145 |
| 146 def p_identifier_action(self, p): | 146 def p_identifier_action(self, p): |
| 147 '''identifier_action : IDENTIFIER | 147 '''identifier_action : IDENTIFIER |
| 148 | IDENTIFIER LEFT_PARENTHESIS RIGHT_PARENTHESIS | 148 | IDENTIFIER LEFT_PARENTHESIS RIGHT_PARENTHESIS |
| 149 | IDENTIFIER LEFT_PARENTHESIS action_params RIGHT_PAREN
THESIS''' | 149 | IDENTIFIER LEFT_PARENTHESIS action_params RIGHT_PAREN
THESIS''' |
| 150 if len(p) == 2 or len(p) == 4: | 150 if len(p) == 2 or len(p) == 4: |
| 151 p[0] = (p[1], None) | 151 p[0] = Term(p[1]) |
| 152 elif len(p) == 5: | 152 elif len(p) == 5: |
| 153 if len(p[3]) == 1: | 153 p[0] = Term(p[1], *p[3]) |
| 154 p[0] = (p[1], p[3][0]) | |
| 155 else: | |
| 156 p[0] = (p[1], p[3]) | |
| 157 else: | 154 else: |
| 158 raise Exception() | 155 raise Exception() |
| 159 | 156 |
| 160 def p_action_params(self, p): | 157 def p_action_params(self, p): |
| 161 '''action_params : IDENTIFIER | 158 '''action_params : IDENTIFIER |
| 162 | IDENTIFIER COMMA action_params''' | 159 | IDENTIFIER COMMA action_params''' |
| 163 if len(p) == 2: | 160 if len(p) == 2: |
| 164 p[0] = (p[1],) | 161 p[0] = (p[1],) |
| 165 elif len(p) == 4: | 162 elif len(p) == 4: |
| 166 p[0] = tuple(([p[1]] + list(p[3]))) | 163 p[0] = tuple(([p[1]] + list(p[3]))) |
| (...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 330 if k == 'default': continue | 327 if k == 'default': continue |
| 331 process(k, v) | 328 process(k, v) |
| 332 process('default', parser_state.rules['default']) | 329 process('default', parser_state.rules['default']) |
| 333 # build the automata | 330 # build the automata |
| 334 for rule_name, graph in rule_map.items(): | 331 for rule_name, graph in rule_map.items(): |
| 335 self.__automata[rule_name] = RuleProcessor.Automata(builder, graph) | 332 self.__automata[rule_name] = RuleProcessor.Automata(builder, graph) |
| 336 self.__rule_trees[rule_name] = graph | 333 self.__rule_trees[rule_name] = graph |
| 337 # process default_action | 334 # process default_action |
| 338 default_action = parser_state.rules['default']['default_action'] | 335 default_action = parser_state.rules['default']['default_action'] |
| 339 self.default_action = Action(None, default_action[1]) if default_action else
None | 336 self.default_action = Action(None, default_action[1]) if default_action else
None |
| OLD | NEW |