| 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 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 127 'default_action : ACTION_OPEN action_part ACTION_CLOSE' | 127 'default_action : ACTION_OPEN action_part ACTION_CLOSE' |
| 128 p[0] = (None, p[2], None) | 128 p[0] = (None, p[2], None) |
| 129 | 129 |
| 130 def p_maybe_action_part(self, p): | 130 def p_maybe_action_part(self, p): |
| 131 '''maybe_action_part : action_part | 131 '''maybe_action_part : action_part |
| 132 | empty''' | 132 | empty''' |
| 133 p[0] = p[1] | 133 p[0] = p[1] |
| 134 | 134 |
| 135 def p_action_part(self, p): | 135 def p_action_part(self, p): |
| 136 '''action_part : code | 136 '''action_part : code |
| 137 | identifier_action''' | 137 | identifier_action''' |
| 138 p[0] = p[1] | 138 p[0] = p[1] |
| 139 | 139 |
| 140 def p_maybe_transition(self, p): | 140 def p_maybe_transition(self, p): |
| 141 '''maybe_transition : IDENTIFIER | 141 '''maybe_transition : IDENTIFIER |
| 142 | empty''' | 142 | empty''' |
| 143 p[0] = p[1] | 143 p[0] = p[1] |
| 144 | 144 |
| 145 def p_identifier_action(self, p): | 145 def p_identifier_action(self, p): |
| 146 '''identifier_action : IDENTIFIER | 146 '''identifier_action : IDENTIFIER |
| 147 | IDENTIFIER LEFT_PARENTHESIS RIGHT_PARENTHESIS | 147 | IDENTIFIER LEFT_PARENTHESIS RIGHT_PARENTHESIS |
| 148 | IDENTIFIER LEFT_PARENTHESIS action_params RIGHT_PAREN
THESIS''' | 148 | IDENTIFIER LEFT_PARENTHESIS action_params RIGHT_PAREN
THESIS''' |
| 149 assert p[1] != 'code' | 149 assert p[1] != 'code' |
| 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] = (p[1], None) |
| 152 elif len(p) == 5: | 152 elif len(p) == 5: |
| 153 p[0] = (p[1], p[3]) | 153 if len(p[3]) == 1: |
| 154 p[0] = (p[1], p[3][0]) |
| 155 else: |
| 156 p[0] = (p[1], p[3]) |
| 154 else: | 157 else: |
| 155 raise Exception() | 158 raise Exception() |
| 156 | 159 |
| 157 def p_action_params(self, p): | 160 def p_action_params(self, p): |
| 158 '''action_params : IDENTIFIER | 161 '''action_params : IDENTIFIER |
| 159 | IDENTIFIER COMMA action_params''' | 162 | IDENTIFIER COMMA action_params''' |
| 160 if len(p) == 2: | 163 if len(p) == 2: |
| 161 p[0] = p[1] | 164 p[0] = (p[1],) |
| 162 elif len(p) == 4: | 165 elif len(p) == 4: |
| 163 p[0] = (p[1], p[3]) | 166 p[0] = tuple(([p[1]] + list(p[3]))) |
| 164 else: | 167 else: |
| 165 raise Exception() | 168 raise Exception() |
| 166 | 169 |
| 167 def p_composite_regex(self, p): | 170 def p_composite_regex(self, p): |
| 168 '''composite_regex : regex_parts OR regex_parts | 171 '''composite_regex : regex_parts OR regex_parts |
| 169 | regex_parts''' | 172 | regex_parts''' |
| 170 if len(p) == 2: | 173 if len(p) == 2: |
| 171 p[0] = p[1] | 174 p[0] = p[1] |
| 172 else: | 175 else: |
| 173 p[0] = NfaBuilder.or_graphs([p[1], p[3]]) | 176 p[0] = NfaBuilder.or_graphs([p[1], p[3]]) |
| (...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 338 for k, v in parser_state.rules.items(): | 341 for k, v in parser_state.rules.items(): |
| 339 if k == 'default': continue | 342 if k == 'default': continue |
| 340 process(k, v) | 343 process(k, v) |
| 341 process('default', parser_state.rules['default']) | 344 process('default', parser_state.rules['default']) |
| 342 # build the automata | 345 # build the automata |
| 343 for rule_name, graph in rule_map.items(): | 346 for rule_name, graph in rule_map.items(): |
| 344 self.__automata[rule_name] = RuleProcessor.Automata(builder, graph) | 347 self.__automata[rule_name] = RuleProcessor.Automata(builder, graph) |
| 345 # process default_action | 348 # process default_action |
| 346 default_action = parser_state.rules['default']['default_action'] | 349 default_action = parser_state.rules['default']['default_action'] |
| 347 self.default_action = Action(None, default_action[1]) if default_action else
None | 350 self.default_action = Action(None, default_action[1]) if default_action else
None |
| OLD | NEW |