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

Unified Diff: tools/lexer_generator/transition_keys.py

Issue 66333008: Experimental parser: move code gen to own class (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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « tools/lexer_generator/generator.py ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tools/lexer_generator/transition_keys.py
diff --git a/tools/lexer_generator/transition_keys.py b/tools/lexer_generator/transition_keys.py
index bbdf45e3d1705ab153bb0ca151b22a5a67408006..f3c80fce6992ac2591de13ac51da64378c059d1f 100644
--- a/tools/lexer_generator/transition_keys.py
+++ b/tools/lexer_generator/transition_keys.py
@@ -190,25 +190,19 @@ class TransitionKey:
def __eq__(self, other):
return isinstance(other, self.__class__) and self.__ranges == other.__ranges
- def to_code(self):
- code = 'if ('
- first = True
+ @staticmethod
+ def __class_name(r):
+ for name, v in TransitionKey.__class_bounds.items():
+ if r == v: return name
+ assert False
+
+ def range_iter(self):
+ assert not self == TransitionKey.epsilon() and not self.__is_unique()
for r in self.__ranges:
- if r[0] >= 256: # FIXME: add class checks
- continue
- if not first:
- code += ' || '
- if r[0] == r[1]:
- code += 'yych == %s' % r[0]
- elif r[0] == 0:
- code += 'yych <= %s' % r[1]
- elif r[1] == 255: # FIXME: this should depend on the char type maybe??
- code += 'yych >= %s' % r[0]
+ if self.__is_class_range(r):
+ yield ('CLASS', TransitionKey.__class_name(r))
else:
- code += '(yych >= %s && yych <= %s)' % (r[0], r[1])
- first = False
- code += ')'
- return code
+ yield ('LATIN_1', r)
__printable_cache = {
ord('\t') : '\\t',
@@ -219,9 +213,7 @@ class TransitionKey:
@staticmethod
def __range_str(r):
if TransitionKey.__is_class_range(r):
- for name, v in TransitionKey.__class_bounds.items():
- if r == v: return name
- assert False
+ return TransitionKey.__class_name(r)
def to_str(x):
assert TransitionKey.__in_latin_1(x)
if not x in TransitionKey.__printable_cache:
« no previous file with comments | « tools/lexer_generator/generator.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698