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/automaton.py

Issue 59663004: Experimental parser: add html arg to generator (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 | tools/lexer_generator/generator.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 43ca95d18cab2754a7b14933cf3f8a0f4d3bf4da..b3c08158143ef8edee1c28d9fdabe693e26e3440 100644
--- a/tools/lexer_generator/automaton.py
+++ b/tools/lexer_generator/automaton.py
@@ -56,24 +56,32 @@ class Automaton(object):
@staticmethod
def generate_dot(start_node, terminal_set, edge_iterator):
+ def escape(v):
+ v = str(v).replace('\r', '\\\\r')
+ v = str(v).replace('\t', '\\\\t')
+ v = str(v).replace('\n', '\\\\n')
+ v = str(v).replace('\\', '\\\\')
+ return v
+
def f(node, node_content):
for key, values in node.transitions().items():
if key == TransitionKey.epsilon():
key = "ε"
- key = str(key).replace('\\', '\\\\')
# TODO pass this action as parameter
if type(values) == TupleType:
values = [values]
for (state, action) in values:
if action:
- node_content.append(
- " S_%s -> S_%s [ label = \"%s {%s} -> %s\" ];" %
- (node.node_number(), state.node_number(), key, action[1],
- action[2]))
+ content = " S_%s -> S_%s [ label = \"%s {%s} -> %s\" ];" % (
+ node.node_number(),
+ state.node_number(),
+ escape(key),
+ escape(action[1]),
+ escape(action[2]))
else:
- node_content.append(
- " S_%s -> S_%s [ label = \"%s\" ];" %
- (node.node_number(), state.node_number(), key))
+ content = " S_%s -> S_%s [ label = \"%s\" ];" % (
+ node.node_number(), state.node_number(), escape(key))
+ node_content.append(content)
return node_content
node_content = edge_iterator(f, [])
« no previous file with comments | « no previous file | tools/lexer_generator/generator.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698