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

Unified Diff: tools/lexer_generator/regex_parser.py

Issue 59953002: Experimental lexer generator: parse {} in regexps. (Closed) Base URL: https://v8.googlecode.com/svn/branches/experimental/parser
Patch Set: rebased 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « tools/lexer_generator/regex_lexer.py ('k') | tools/lexer_generator/transition_keys.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tools/lexer_generator/regex_parser.py
diff --git a/tools/lexer_generator/regex_parser.py b/tools/lexer_generator/regex_parser.py
index 7049aa51733ef4bed02018b6eeca63585bb0db94..c533215ab863dd535df8b4377c2b869d88f0a5f0 100644
--- a/tools/lexer_generator/regex_parser.py
+++ b/tools/lexer_generator/regex_parser.py
@@ -64,7 +64,10 @@ class RegexParser:
| any maybe_modifier
'''
if p[2] != None:
- p[0] = (p[2], p[1])
+ if isinstance(p[2], tuple) and p[2][0] == 'REPEAT':
+ p[0] = (p[2][0], p[2][1], p[2][2], p[1])
+ else:
+ p[0] = (p[2], p[1])
else:
p[0] = p[1]
@@ -72,11 +75,20 @@ class RegexParser:
'''maybe_modifier : ONE_OR_MORE
| ZERO_OR_ONE
| ZERO_OR_MORE
+ | repetition
| empty'''
p[0] = p[1]
- if p[1] != None:
+ if p[1] in self.token_map:
p[0] = self.token_map[p[1]]
+ def p_repetition(self, p):
+ '''repetition : REPEAT_BEGIN NUMBER REPEAT_END
+ | REPEAT_BEGIN NUMBER COMMA NUMBER REPEAT_END'''
+ if len(p) == 4:
+ p[0] = ("REPEAT", p[2], p[2])
+ else:
+ p[0] = ("REPEAT", p[2], p[4])
+
def p_literal(self, p):
'''literal : LITERAL'''
p[0] = ('LITERAL', p[1])
« no previous file with comments | « tools/lexer_generator/regex_lexer.py ('k') | tools/lexer_generator/transition_keys.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698