| 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 284 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 295 if not self.__minimial_dfa: | 295 if not self.__minimial_dfa: |
| 296 self.__minimial_dfa = self.dfa().minimize() | 296 self.__minimial_dfa = self.dfa().minimize() |
| 297 return self.__minimial_dfa | 297 return self.__minimial_dfa |
| 298 | 298 |
| 299 def __process_parser_state(self, parser_state): | 299 def __process_parser_state(self, parser_state): |
| 300 rule_map = {} | 300 rule_map = {} |
| 301 builder = NfaBuilder(parser_state.encoding, parser_state.character_classes) | 301 builder = NfaBuilder(parser_state.encoding, parser_state.character_classes) |
| 302 assert 'default' in parser_state.rules | 302 assert 'default' in parser_state.rules |
| 303 def process(subgraph, v): | 303 def process(subgraph, v): |
| 304 graphs = [] | 304 graphs = [] |
| 305 continues = 0 | |
| 306 for graph, precedence, action in v['regex']: | 305 for graph, precedence, action in v['regex']: |
| 307 (entry_action, match_action, transition) = action | 306 (entry_action, match_action, transition) = action |
| 308 if entry_action or match_action: | 307 if entry_action or match_action: |
| 309 action = Action(entry_action, match_action, precedence) | 308 action = Action(entry_action, match_action, precedence) |
| 310 graph = NfaBuilder.add_action(graph, action) | 309 graph = NfaBuilder.add_action(graph, action) |
| 311 if not transition: | 310 if not transition: |
| 312 pass | 311 pass |
| 313 elif transition == 'continue': | 312 elif transition == 'continue': |
| 314 assert not subgraph == 'default' | 313 assert not subgraph == 'default' |
| 315 continues += 1 | |
| 316 graph = NfaBuilder.add_continue(graph) | 314 graph = NfaBuilder.add_continue(graph) |
| 317 else: | 315 else: |
| 318 assert subgraph == 'default' | 316 assert subgraph == 'default' |
| 319 graph = NfaBuilder.join_subgraph( | 317 graph = NfaBuilder.join_subgraph( |
| 320 graph, transition, rule_map[transition]) | 318 graph, transition, rule_map[transition]) |
| 321 graphs.append(graph) | 319 graphs.append(graph) |
| 322 if continues == len(graphs): | |
| 323 graphs.append(NfaBuilder.epsilon()) | |
| 324 if v['catch_all']: | 320 if v['catch_all']: |
| 325 (precedence, catch_all) = v['catch_all'] | 321 (precedence, catch_all) = v['catch_all'] |
| 326 assert catch_all == (None, None, 'continue'), "unimplemented" | 322 assert catch_all == (None, None, 'continue'), "unimplemented" |
| 327 graphs.append(NfaBuilder.add_continue(NfaBuilder.catch_all())) | 323 graphs.append(NfaBuilder.add_continue(NfaBuilder.catch_all())) |
| 328 graph = NfaBuilder.or_graphs(graphs) | 324 graph = NfaBuilder.or_graphs(graphs) |
| 329 rule_map[subgraph] = graph | 325 rule_map[subgraph] = graph |
| 330 # process first the subgraphs, then the default graph | 326 # process first the subgraphs, then the default graph |
| 331 for k, v in parser_state.rules.items(): | 327 for k, v in parser_state.rules.items(): |
| 332 if k == 'default': continue | 328 if k == 'default': continue |
| 333 process(k, v) | 329 process(k, v) |
| 334 process('default', parser_state.rules['default']) | 330 process('default', parser_state.rules['default']) |
| 335 # build the automata | 331 # build the automata |
| 336 for rule_name, graph in rule_map.items(): | 332 for rule_name, graph in rule_map.items(): |
| 337 self.__automata[rule_name] = RuleProcessor.Automata(builder, graph) | 333 self.__automata[rule_name] = RuleProcessor.Automata(builder, graph) |
| 338 self.__rule_trees[rule_name] = graph | 334 self.__rule_trees[rule_name] = graph |
| 339 # process default_action | 335 # process default_action |
| 340 default_action = parser_state.rules['default']['default_action'] | 336 default_action = parser_state.rules['default']['default_action'] |
| 341 self.default_action = Action(None, default_action[1]) if default_action else
None | 337 self.default_action = Action(None, default_action[1]) if default_action else
None |
| OLD | NEW |