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

Unified Diff: tools/lexer_generator/rule_parser.py

Issue 48783004: Experimental lexer generator: fixing the rule parser + adding tests. (Closed) Base URL: https://v8.googlecode.com/svn/branches/experimental/parser
Patch Set: Created 7 years, 2 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « tools/lexer_generator/rule_lexer.py ('k') | tools/lexer_generator/rule_parser_test.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tools/lexer_generator/rule_parser.py
diff --git a/tools/lexer_generator/rule_parser.py b/tools/lexer_generator/rule_parser.py
index 96ed09901e6374dc7fbd6805d58d42ee5e233513..a733801baaa66f485413871b0a0f97146e1f7107 100644
--- a/tools/lexer_generator/rule_parser.py
+++ b/tools/lexer_generator/rule_parser.py
@@ -32,8 +32,9 @@ class RuleParser:
tokens = RuleLexer.tokens
- aliases = dict()
- transitions = dict()
+ def __init__(self):
+ self.aliases = dict()
+ self.transitions = dict()
def p_statement_alias(self, p):
'statement : ALIAS EQUALS REGEX'
@@ -41,25 +42,33 @@ class RuleParser:
self.aliases[p[1]] = regex
def p_statement_condition_transition(self, p):
- 'statement : CONDITION_BEGIN CONDITION CONDITION_END REGEX_AND_TRANSITION'
+ 'statement : CONDITION_BEGIN CONDITION CONDITION_END REGEX_TRANSITION'
old_condition = p[2]
- regex = self.lexer.lexer.lexmatch.group('regex')
+ regex = self.lexer.lexer.lexmatch.group('regex').strip()
new_condition = self.lexer.lexer.lexmatch.group('new')
if old_condition not in self.transitions:
- self.transitions[old_condition] = []
- self.transitions[old_condition].append((regex, new_condition))
+ self.transitions[old_condition] = dict()
+ self.transitions[old_condition][regex] = ('condition', new_condition)
def p_statement_condition_body(self, p):
- 'statement : CONDITION_BEGIN CONDITION CONDITION_END REGEX_AND_BODY'
+ 'statement : CONDITION_BEGIN CONDITION CONDITION_END REGEX_BODY'
old_condition = p[2]
- regex = self.lexer.lexer.lexmatch.group('regex')
- body = self.lexer.lexer.lexmatch.group('body')
+ regex = self.lexer.lexer.lexmatch.group('regex').strip()
+ body = self.lexer.lexer.lexmatch.group('body').strip()
if old_condition not in self.transitions:
- self.transitions[old_condition] = []
- self.transitions[old_condition].append((regex, body))
+ self.transitions[old_condition] = dict()
+ self.transitions[old_condition][regex] = ('body', body)
- def p_empty(self, p):
- 'empty :'
+ def p_statement_condition_transition_body(self, p):
+ 'statement : CONDITION_BEGIN CONDITION CONDITION_END REGEX_TRANSITION_BODY'
+ old_condition = p[2]
+ regex = self.lexer.lexer.lexmatch.group('regex').strip()
+ new_condition = self.lexer.lexer.lexmatch.group('new').strip()
+ body = self.lexer.lexer.lexmatch.group('body').strip()
+ if old_condition not in self.transitions:
+ self.transitions[old_condition] = dict()
+ self.transitions[old_condition][regex] = (
+ 'condition_and_body', new_condition, body)
def p_error(self, p):
raise Exception("Syntax error in input '%s'" % p)
« no previous file with comments | « tools/lexer_generator/rule_lexer.py ('k') | tools/lexer_generator/rule_parser_test.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698