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

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

Issue 143643005: Experimental parser: add tests for subgraph handling. (Closed) Base URL: https://v8.googlecode.com/svn/branches/experimental/parser
Patch Set: Created 6 years, 11 months 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/lexer_test.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 161 matching lines...) Expand 10 before | Expand all | Expand 10 after
172 172
173 def matches(self, string): 173 def matches(self, string):
174 valid_states = self.start_set() 174 valid_states = self.start_set()
175 for c in string: 175 for c in string:
176 valid_states = Automaton.__transition_states_for_char(valid_states, c) 176 valid_states = Automaton.__transition_states_for_char(valid_states, c)
177 if not valid_states: 177 if not valid_states:
178 return False 178 return False
179 valid_states = self.epsilon_closure(valid_states) 179 valid_states = self.epsilon_closure(valid_states)
180 return len(self.terminal_set().intersection(valid_states)) > 0 180 return len(self.terminal_set().intersection(valid_states)) > 0
181 181
182 def lex(self, string): 182 def lex(self, string, default_action):
183 last_position = 0 183 last_position = 0
184 valid_states = self.start_set() 184 valid_states = self.start_set()
185 for pos, c in enumerate(string): 185 for pos, c in enumerate(string):
186 transitions = Automaton.__transition_states_for_char(valid_states, c) 186 transitions = Automaton.__transition_states_for_char(valid_states, c)
187 if transitions: 187 if transitions:
188 valid_states = transitions 188 valid_states = transitions
189 continue 189 continue
190 action = Action.dominant_action(valid_states) 190 action = Action.dominant_action(valid_states)
191 assert action # must invoke default action here 191 if not action:
192 assert default_action
193 action = default_action
192 yield (action, last_position, pos) 194 yield (action, last_position, pos)
193 last_position = pos 195 last_position = pos
194 # lex next token 196 # lex next token
195 valid_states = Automaton.__transition_states_for_char(self.start_set(), c) 197 valid_states = Automaton.__transition_states_for_char(self.start_set(), c)
196 assert valid_states 198 assert valid_states
197 valid_states = self.epsilon_closure(valid_states) 199 valid_states = self.epsilon_closure(valid_states)
198 action = Action.dominant_action(valid_states) 200 action = Action.dominant_action(valid_states)
199 assert action # must invoke default action here 201 if not action:
202 assert default_action
203 action = default_action
200 yield (action, last_position, len(string)) 204 yield (action, last_position, len(string))
201 205
202 def to_dot(self): 206 def to_dot(self):
203 207
204 def escape(v): 208 def escape(v):
205 v = str(v) 209 v = str(v)
206 v = v.replace('\r', '\\\\r').replace('\t', '\\\\t').replace('\n', '\\\\n') 210 v = v.replace('\r', '\\\\r').replace('\t', '\\\\t').replace('\n', '\\\\n')
207 v = v.replace('\\', '\\\\').replace('\"', '\\\"') 211 v = v.replace('\\', '\\\\').replace('\"', '\\\"')
208 return v 212 return v
209 213
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
243 node [shape = doublecircle, style=unfilled]; %s 247 node [shape = doublecircle, style=unfilled]; %s
244 node [shape = circle]; 248 node [shape = circle];
245 %s 249 %s
246 %s 250 %s
247 } 251 }
248 ''' % (start_shape, 252 ''' % (start_shape,
249 start_number, 253 start_number,
250 " ".join(terminals), 254 " ".join(terminals),
251 "\n".join(edge_content), 255 "\n".join(edge_content),
252 "\n".join(node_content)) 256 "\n".join(node_content))
OLDNEW
« no previous file with comments | « no previous file | tools/lexer_generator/lexer_test.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698