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

Side by Side Diff: tools/lexer_generator/dfa.py

Issue 61683006: Experimental lexer generator: Fix action printing. (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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | tools/lexer_generator/nfa.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 # Copyright 2013 the V8 project authors. All rights reserved. 1 # Copyright 2013 the V8 project authors. All rights reserved.
2 # Redistribution and use in source and binary forms, with or without 2 # Redistribution and use in source and binary forms, with or without
3 # modification, are permitted provided that the following conditions are 3 # modification, are permitted provided that the following conditions are
4 # met: 4 # met:
5 # 5 #
6 # * Redistributions of source code must retain the above copyright 6 # * Redistributions of source code must retain the above copyright
7 # notice, this list of conditions and the following disclaimer. 7 # notice, this list of conditions and the following disclaimer.
8 # * Redistributions in binary form must reproduce the above 8 # * Redistributions in binary form must reproduce the above
9 # copyright notice, this list of conditions and the following 9 # copyright notice, this list of conditions and the following
10 # disclaimer in the documentation and/or other materials provided 10 # disclaimer in the documentation and/or other materials provided
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
114 return actions and actions[-1][0] == 'TERMINATE' 114 return actions and actions[-1][0] == 'TERMINATE'
115 115
116 def to_dot(self): 116 def to_dot(self):
117 117
118 def f(node, node_content): 118 def f(node, node_content):
119 for key, (state, action) in node.transitions().items(): 119 for key, (state, action) in node.transitions().items():
120 key = str(key).replace('\\', '\\\\') 120 key = str(key).replace('\\', '\\\\')
121 if action: 121 if action:
122 node_content.append( 122 node_content.append(
123 " S_%s -> S_%s [ label = \"%s {%s} -> %s\" ];" % 123 " S_%s -> S_%s [ label = \"%s {%s} -> %s\" ];" %
124 (node.node_number(), state.node_number(), key, action[0], 124 (node.node_number(), state.node_number(), key, action[1],
125 action[1])) 125 action[2]))
126 else: 126 else:
127 node_content.append( 127 node_content.append(
128 " S_%s -> S_%s [ label = \"%s\" ];" % 128 " S_%s -> S_%s [ label = \"%s\" ];" %
129 (node.node_number(), state.node_number(), key)) 129 (node.node_number(), state.node_number(), key))
130 return node_content 130 return node_content
131 131
132 node_content = self.__visit_edges(self.__start, f, []) 132 node_content = self.__visit_edges(self.__start, f, [])
133 terminals = ["S_%d;" % x.node_number() for x in self.__terminal_set] 133 terminals = ["S_%d;" % x.node_number() for x in self.__terminal_set]
134 start_number = self.__start.node_number() 134 start_number = self.__start.node_number()
135 start_shape = "circle" 135 start_shape = "circle"
136 if self.__start in self.__terminal_set: 136 if self.__start in self.__terminal_set:
137 start_shape = "doublecircle" 137 start_shape = "doublecircle"
138 138
139 return ''' 139 return '''
140 digraph finite_state_machine { 140 digraph finite_state_machine {
141 rankdir=LR; 141 rankdir=LR;
142 node [shape = %s, style=filled, bgcolor=lightgrey]; S_%s 142 node [shape = %s, style=filled, bgcolor=lightgrey]; S_%s
143 node [shape = doublecircle, style=unfilled]; %s 143 node [shape = doublecircle, style=unfilled]; %s
144 node [shape = circle]; 144 node [shape = circle];
145 %s 145 %s
146 } 146 }
147 ''' % (start_shape, 147 ''' % (start_shape,
148 start_number, 148 start_number,
149 " ".join(terminals), 149 " ".join(terminals),
150 "\n".join(node_content)) 150 "\n".join(node_content))
OLDNEW
« no previous file with comments | « no previous file | tools/lexer_generator/nfa.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698