Revision: 17616
Author:   [email protected]
Date:     Mon Nov 11 12:23:45 2013 UTC
Log:      Experimental lexer generator: fix actions in graphs.

Actions are now associated to a node, not an edge. So much beautiful.

[email protected].
BUG=

Review URL: https://codereview.chromium.org/68523003
http://code.google.com/p/v8/source/detail?r=17616

Modified:
 /branches/experimental/parser/tools/lexer_generator/automaton.py

=======================================
--- /branches/experimental/parser/tools/lexer_generator/automaton.py Mon Nov 11 07:52:15 2013 UTC +++ /branches/experimental/parser/tools/lexer_generator/automaton.py Mon Nov 11 12:23:45 2013 UTC
@@ -67,27 +67,24 @@
       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 @@
   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))

--
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev
--- You received this message because you are subscribed to the Google Groups "v8-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to