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

Unified Diff: tools/lexer_generator/action.py

Issue 158823002: Experimental parser: refactor TransitionKey to use Term (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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | tools/lexer_generator/automata_test.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tools/lexer_generator/action.py
diff --git a/tools/lexer_generator/action.py b/tools/lexer_generator/action.py
index 8a854640bfbf7c5481a1d83e10e1494b7b2ae8f9..40a3fd37041deb9ece7bbb106b44e3813c2aff8b 100644
--- a/tools/lexer_generator/action.py
+++ b/tools/lexer_generator/action.py
@@ -28,9 +28,9 @@
from types import StringType, IntType
class Term(object):
- '''A class representing a function and its arguments.
+ '''An immutable class representing a function and its arguments.
f(a,b,c) would be represented as ('f', a, b, c) where
- a, b, and c are strings or Terms.'''
+ a, b, and c are strings, integers or Terms.'''
__empty_term = None
@@ -45,8 +45,8 @@ class Term(object):
if not name:
assert not args, 'empty term must not have args'
for v in args:
- if type(v) == StringType:
- assert v, 'string args must be non empty'
+ if type(v) == IntType or type(v) == StringType:
+ continue
else:
assert isinstance(v, Term)
self.__tuple = tuple([name] + list(args))
@@ -62,6 +62,7 @@ class Term(object):
return hash(self.__tuple)
def __nonzero__(self):
+ 'true <==> self == empty_term'
return bool(self.__tuple[0])
def __eq__(self, other):
@@ -80,16 +81,16 @@ class Term(object):
nodes = []
edges = []
- def escape(v):
+ def escape(v): # TODO(dcarney): abstract into utilities
v = str(v)
v = v.replace('\r', '\\\\r').replace('\t', '\\\\t').replace('\n', '\\\\n')
v = v.replace('\\', '\\\\').replace('\"', '\\\"')
return v
def process(term):
- if isinstance(term, str):
+ if type(term) == StringType or type(term) == IntType:
node_ix[0] += 1
- nodes.append(node_template % (escape(term), node_ix[0]))
+ nodes.append(node_template % (escape(str(term)), node_ix[0]))
return node_ix[0]
elif isinstance(term, Term):
child_ixs = map(process, term.args())
« no previous file with comments | « no previous file | tools/lexer_generator/automata_test.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698