Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(48)

Side by Side Diff: tools/lexer_generator/rule_parser.py

Issue 159853009: Experimental parser: split off dot processing (Closed) Base URL: https://v8.googlecode.com/svn/branches/experimental/parser
Patch Set: Created 6 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « tools/lexer_generator/generator.py ('k') | tools/lexer_generator/transition_keys.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
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)
OLDNEW
« no previous file with comments | « tools/lexer_generator/generator.py ('k') | tools/lexer_generator/transition_keys.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698