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

Unified Diff: tools/lexer_generator/automaton.py

Issue 68343004: Experimental parser: better actions (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 | « src/lexer/lexer_py.re ('k') | tools/lexer_generator/dfa.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tools/lexer_generator/automaton.py
diff --git a/tools/lexer_generator/automaton.py b/tools/lexer_generator/automaton.py
index 093f5ad17e547813573f17776875893f4ec5e506..8b1e12772f0a56beb69a897d3a96d884f431e92c 100644
--- a/tools/lexer_generator/automaton.py
+++ b/tools/lexer_generator/automaton.py
@@ -39,6 +39,9 @@ class AutomatonState(object):
def node_number(self):
return self.__node_number
+ def __str__(self):
+ return "%s(%d)" % (type(self), self.node_number())
+
class Automaton(object):
@staticmethod
@@ -54,7 +57,7 @@ class Automaton(object):
return state
@staticmethod
- def generate_dot(start_node, terminal_set, edge_iterator):
+ def generate_dot(start_node, terminal_set, edge_iterator, state_iterator):
def escape(v):
v = str(v).replace('\r', '\\\\r')
@@ -68,17 +71,15 @@ class Automaton(object):
for key, values in node.transitions().items():
if key == TransitionKey.epsilon():
key = "ε"
- # TODO pass this action as parameter
- if type(values) == TupleType:
- values = [values]
- for (state, action) in values:
+ for state in state_iterator(values):
+ action = state.action()
if action:
- content = " S_%s -> S_%s [ label = \"%s {%s} -> %s\" ];" % (
+ content = " S_%s -> S_%s [ label = \"%s {%s}:%d\" ];" % (
node.node_number(),
state.node_number(),
escape(key),
escape(action[1]),
- escape(action[2]))
+ action[0])
else:
content = " S_%s -> S_%s [ label = \"%s\" ];" % (
node.node_number(), state.node_number(), escape(key))
« no previous file with comments | « src/lexer/lexer_py.re ('k') | tools/lexer_generator/dfa.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698