| 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 313 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 324 def postparse(parser): | 324 def postparse(parser): |
| 325 parser.__state = None | 325 parser.__state = None |
| 326 return ParserBuilder.parse( | 326 return ParserBuilder.parse( |
| 327 string, "RuleParser", new_lexer, new_parser, preparse, postparse) | 327 string, "RuleParser", new_lexer, new_parser, preparse, postparse) |
| 328 | 328 |
| 329 class RuleProcessor(object): | 329 class RuleProcessor(object): |
| 330 | 330 |
| 331 def __init__(self, string, encoding_name): | 331 def __init__(self, string, encoding_name): |
| 332 self.__automata = {} | 332 self.__automata = {} |
| 333 self.__default_action = None | 333 self.__default_action = None |
| 334 self.__parser_state = RuleParserState(KeyEncoding.get(encoding_name)) | 334 self.__encoding = KeyEncoding.get(encoding_name) |
| 335 self.__parser_state = RuleParserState(self.__encoding) |
| 335 RuleParser.parse(string, self.__parser_state) | 336 RuleParser.parse(string, self.__parser_state) |
| 336 self.__process_parser_state() | 337 self.__process_parser_state() |
| 337 | 338 |
| 339 def encoding(self): |
| 340 return self.__encoding |
| 341 |
| 338 def alias_iter(self): | 342 def alias_iter(self): |
| 339 return iter(self.__parser_state.aliases.items()) | 343 return iter(self.__parser_state.aliases.items()) |
| 340 | 344 |
| 341 def automata_iter(self): | 345 def automata_iter(self): |
| 342 return iter(self.__automata.items()) | 346 return iter(self.__automata.items()) |
| 343 | 347 |
| 344 def default_automata(self): | 348 def default_automata(self): |
| 345 return self.__automata['default'] | 349 return self.__automata['default'] |
| 346 | 350 |
| 347 def default_action(self): | 351 def default_action(self): |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 399 for tree_name, v in parser_state.rules.items(): | 403 for tree_name, v in parser_state.rules.items(): |
| 400 assert v['trees'], "lexer state %s is empty" % tree_name | 404 assert v['trees'], "lexer state %s is empty" % tree_name |
| 401 rule_map[tree_name] = NfaBuilder.or_terms(v['trees']) | 405 rule_map[tree_name] = NfaBuilder.or_terms(v['trees']) |
| 402 # build the automata | 406 # build the automata |
| 403 for name, tree in rule_map.items(): | 407 for name, tree in rule_map.items(): |
| 404 self.__automata[name] = RuleProcessor.Automata( | 408 self.__automata[name] = RuleProcessor.Automata( |
| 405 parser_state.encoding, parser_state.character_classes, rule_map, name) | 409 parser_state.encoding, parser_state.character_classes, rule_map, name) |
| 406 # process default_action | 410 # process default_action |
| 407 default_action = parser_state.rules['default']['default_action'] | 411 default_action = parser_state.rules['default']['default_action'] |
| 408 self.__default_action = Action(Term.empty_term(), default_action) | 412 self.__default_action = Action(Term.empty_term(), default_action) |
| OLD | NEW |