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

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

Issue 62223002: Experimental lexer generator: transfer actions across epsilon transitions correctly when constructi… (Closed) Base URL: https://v8.googlecode.com/svn/branches/experimental/parser
Patch Set: . Created 7 years, 1 month 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
« tools/lexer_generator/nfa.py ('K') | « tools/lexer_generator/nfa.py ('k') | no next file » | 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 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
43 43
44 def parse(self, string): 44 def parse(self, string):
45 return RuleParser.parse(string, self) 45 return RuleParser.parse(string, self)
46 46
47 class RuleParser: 47 class RuleParser:
48 48
49 tokens = RuleLexer.tokens 49 tokens = RuleLexer.tokens
50 50
51 def __init__(self): 51 def __init__(self):
52 self.__state = None 52 self.__state = None
53 self.__rule_precedence_counter = 0
dcarney 2013/11/07 08:08:54 should either be class static or go in RuleParserS
marja 2013/11/07 08:25:41 Done.
53 54
54 def p_statements(self, p): 55 def p_statements(self, p):
55 'statements : aliases rules' 56 'statements : aliases rules'
56 57
57 def p_aliases(self, p): 58 def p_aliases(self, p):
58 '''aliases : alias_rule aliases 59 '''aliases : alias_rule aliases
59 | empty''' 60 | empty'''
60 61
61 def p_alias_rule(self, p): 62 def p_alias_rule(self, p):
62 'alias_rule : IDENTIFIER EQUALS composite_regex SEMICOLON' 63 'alias_rule : IDENTIFIER EQUALS composite_regex SEMICOLON'
(...skipping 25 matching lines...) Expand all
88 89
89 def p_transition_rules(self, p): 90 def p_transition_rules(self, p):
90 '''transition_rules : transition_rule transition_rules 91 '''transition_rules : transition_rule transition_rules
91 | empty''' 92 | empty'''
92 93
93 def p_transition_rule(self, p): 94 def p_transition_rule(self, p):
94 '''transition_rule : composite_regex_or_default code action 95 '''transition_rule : composite_regex_or_default code action
95 | composite_regex_or_default empty action 96 | composite_regex_or_default empty action
96 | composite_regex_or_default code empty''' 97 | composite_regex_or_default code empty'''
97 rules = self.__state.rules[self.__state.current_state] 98 rules = self.__state.rules[self.__state.current_state]
98 rule = (p[1], p[2], p[3]) 99 rule = (p[1], p[2], p[3], self.__rule_precedence_counter)
100 self.__rule_precedence_counter+=1
99 if p[1] == 'default': 101 if p[1] == 'default':
100 assert not rules['default'] 102 assert not rules['default']
101 rules['default'] = rule 103 rules['default'] = rule
102 else: 104 else:
103 rules['regex'].append(rule) 105 rules['regex'].append(rule)
104 106
105 def p_action(self, p): 107 def p_action(self, p):
106 'action : ACTION_OPEN IDENTIFIER ACTION_CLOSE' 108 'action : ACTION_OPEN IDENTIFIER ACTION_CLOSE'
107 p[0] = p[2] 109 p[0] = p[2]
108 110
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
187 __static_instance = None 189 __static_instance = None
188 @staticmethod 190 @staticmethod
189 def parse(data, parser_state): 191 def parse(data, parser_state):
190 if not RuleParser.__static_instance: 192 if not RuleParser.__static_instance:
191 RuleParser.__static_instance = RuleParser() 193 RuleParser.__static_instance = RuleParser()
192 RuleParser.__static_instance.build() 194 RuleParser.__static_instance.build()
193 parser = RuleParser.__static_instance 195 parser = RuleParser.__static_instance
194 parser.__state = parser_state 196 parser.__state = parser_state
195 parser.parser.parse(data, lexer=parser.lexer.lexer) 197 parser.parser.parse(data, lexer=parser.lexer.lexer)
196 parser.__state = None 198 parser.__state = None
OLDNEW
« tools/lexer_generator/nfa.py ('K') | « tools/lexer_generator/nfa.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698