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

Unified Diff: tools/lexer_generator/automaton.py

Issue 68523003: Experimental lexer generator: fix actions in graphs. (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 | « no previous file | no next file » | 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 8b1e12772f0a56beb69a897d3a96d884f431e92c..470a918244295d2bcf71d2c427a30a4d7d97b96b 100644
--- a/tools/lexer_generator/automaton.py
+++ b/tools/lexer_generator/automaton.py
@@ -67,27 +67,24 @@ class Automaton(object):
v = str(v).replace('\"', '\\\"')
return v
- def f(node, node_content):
+ def f(node, content):
+ (node_content, edge_content) = content
+ if node.action():
+ action_text = node.action()[1].split('\n')[0]
+ node_content.append(' S_l%s[shape = box, label="%s"];' %
+ (node.node_number(), action_text))
+ node_content.append(' S_%s -> S_l%s [arrowhead = none];' %
+ (node.node_number(), node.node_number()))
for key, values in node.transitions().items():
if key == TransitionKey.epsilon():
key = "ε"
for state in state_iterator(values):
- action = state.action()
- if action:
- content = " S_%s -> S_%s [ label = \"%s {%s}:%d\" ];" % (
- node.node_number(),
- state.node_number(),
- escape(key),
- escape(action[1]),
- action[0])
- else:
- content = " S_%s -> S_%s [ label = \"%s\" ];" % (
- node.node_number(), state.node_number(), escape(key))
- node_content.append(content)
- return node_content
+ edge_content.append(" S_%s -> S_%s [ label = \"%s\" ];" % (
+ node.node_number(), state.node_number(), escape(key)))
+ return (node_content, edge_content)
- node_content = edge_iterator(f, [])
terminals = ["S_%d;" % x.node_number() for x in terminal_set]
+ (node_content, edge_content) = edge_iterator(f, ([], []))
start_number = start_node.node_number()
start_shape = "circle"
if start_node in terminal_set:
@@ -100,8 +97,10 @@ digraph finite_state_machine {
node [shape = doublecircle, style=unfilled]; %s
node [shape = circle];
%s
+%s
}
''' % (start_shape,
start_number,
" ".join(terminals),
+ "\n".join(edge_content),
"\n".join(node_content))
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698