| 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 228 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 239 except Exception: | 239 except Exception: |
| 240 RuleParser.__static_instance = None | 240 RuleParser.__static_instance = None |
| 241 raise | 241 raise |
| 242 parser.__state = None | 242 parser.__state = None |
| 243 assert parser_state.transitions <= set(parser_state.rules.keys()) | 243 assert parser_state.transitions <= set(parser_state.rules.keys()) |
| 244 | 244 |
| 245 class RuleProcessor(object): | 245 class RuleProcessor(object): |
| 246 | 246 |
| 247 def __init__(self, parser_state): | 247 def __init__(self, parser_state): |
| 248 self.__automata = {} | 248 self.__automata = {} |
| 249 self.__rule_trees = {} |
| 249 self.__process_parser_state(parser_state) | 250 self.__process_parser_state(parser_state) |
| 250 | 251 |
| 251 @staticmethod | 252 @staticmethod |
| 252 def parse(string, encoding_name): | 253 def parse(string, encoding_name): |
| 253 parser_state = RuleParserState(KeyEncoding.get(encoding_name)) | 254 parser_state = RuleParserState(KeyEncoding.get(encoding_name)) |
| 254 RuleParser.parse(string, parser_state) | 255 RuleParser.parse(string, parser_state) |
| 255 return RuleProcessor(parser_state) | 256 return RuleProcessor(parser_state) |
| 256 | 257 |
| 257 def automata_iter(self): | 258 def automata_iter(self): |
| 258 return iter(self.__automata.items()) | 259 return iter(self.__automata.items()) |
| 259 | 260 |
| 260 def default_automata(self): | 261 def default_automata(self): |
| 261 return self.__automata['default'] | 262 return self.__automata['default'] |
| 262 | 263 |
| 264 def rule_tree_dots(self): |
| 265 result = {} |
| 266 for rule in self.__rule_trees: |
| 267 result[rule] = NfaBuilder.rule_tree_dot(self.__rule_trees[rule]) |
| 268 return result |
| 269 |
| 263 class Automata(object): | 270 class Automata(object): |
| 264 | 271 |
| 265 def __init__(self, builder, graph): | 272 def __init__(self, builder, graph): |
| 266 self.__builder = builder | 273 self.__builder = builder |
| 267 self.__graph = graph | 274 self.__graph = graph |
| 268 self.__nfa = None | 275 self.__nfa = None |
| 269 self.__dfa = None | 276 self.__dfa = None |
| 270 self.__minimial_dfa = None | 277 self.__minimial_dfa = None |
| 271 | 278 |
| 272 def nfa(self): | 279 def nfa(self): |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 321 graph = NfaBuilder.or_graphs(graphs) | 328 graph = NfaBuilder.or_graphs(graphs) |
| 322 rule_map[subgraph] = graph | 329 rule_map[subgraph] = graph |
| 323 # process first the subgraphs, then the default graph | 330 # process first the subgraphs, then the default graph |
| 324 for k, v in parser_state.rules.items(): | 331 for k, v in parser_state.rules.items(): |
| 325 if k == 'default': continue | 332 if k == 'default': continue |
| 326 process(k, v) | 333 process(k, v) |
| 327 process('default', parser_state.rules['default']) | 334 process('default', parser_state.rules['default']) |
| 328 # build the automata | 335 # build the automata |
| 329 for rule_name, graph in rule_map.items(): | 336 for rule_name, graph in rule_map.items(): |
| 330 self.__automata[rule_name] = RuleProcessor.Automata(builder, graph) | 337 self.__automata[rule_name] = RuleProcessor.Automata(builder, graph) |
| 338 self.__rule_trees[rule_name] = graph |
| 331 # process default_action | 339 # process default_action |
| 332 default_action = parser_state.rules['default']['default_action'] | 340 default_action = parser_state.rules['default']['default_action'] |
| 333 self.default_action = Action(None, default_action[1]) if default_action else
None | 341 self.default_action = Action(None, default_action[1]) if default_action else
None |
| OLD | NEW |