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

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

Issue 132693018: Experimental parser: handling unique keys in merges (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/rule_parser.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 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
143 return (start, [end]) 143 return (start, [end])
144 144
145 def __continue(self, graph): 145 def __continue(self, graph):
146 (start, ends) = self.__process(graph[1]) 146 (start, ends) = self.__process(graph[1])
147 state = self.__peek_state() 147 state = self.__peek_state()
148 if not state['start_node']: 148 if not state['start_node']:
149 state['start_node'] = self.__new_state() 149 state['start_node'] = self.__new_state()
150 self.__patch_ends(ends, state['start_node']) 150 self.__patch_ends(ends, state['start_node'])
151 return (start, []) 151 return (start, [])
152 152
153 def __catch_all(self, graph): 153 def __unique_key(self, graph):
154 return self.__key_state(TransitionKey.unique('catch_all')) 154 return self.__key_state(TransitionKey.unique(graph[1]))
155 155
156 def __join(self, graph): 156 def __join(self, graph):
157 (graph, name, subgraph) = graph[1:] 157 (graph, name, subgraph) = graph[1:]
158 subgraphs = self.__peek_state()['subgraphs'] 158 subgraphs = self.__peek_state()['subgraphs']
159 if not name in subgraphs: 159 if not name in subgraphs:
160 subgraphs[name] = self.__nfa(subgraph) 160 subgraphs[name] = self.__nfa(subgraph)
161 (subgraph_start, subgraph_end, nodes_in_subgraph) = subgraphs[name] 161 (subgraph_start, subgraph_end, nodes_in_subgraph) = subgraphs[name]
162 (start, ends) = self.__process(graph) 162 (start, ends) = self.__process(graph)
163 self.__patch_ends(ends, subgraph_start) 163 self.__patch_ends(ends, subgraph_start)
164 if subgraph_end: 164 if subgraph_end:
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after
304 304
305 @staticmethod 305 @staticmethod
306 def add_action(graph, action): 306 def add_action(graph, action):
307 return ('ACTION', graph, action) 307 return ('ACTION', graph, action)
308 308
309 @staticmethod 309 @staticmethod
310 def add_continue(graph): 310 def add_continue(graph):
311 return ('CONTINUE', graph) 311 return ('CONTINUE', graph)
312 312
313 @staticmethod 313 @staticmethod
314 def catch_all(): 314 def unique_key(name):
315 return ('CATCH_ALL',) 315 return ('UNIQUE_KEY', name)
316 316
317 @staticmethod 317 @staticmethod
318 def join_subgraph(graph, name, subgraph): 318 def join_subgraph(graph, name, subgraph):
319 return ('JOIN', graph, name, subgraph) 319 return ('JOIN', graph, name, subgraph)
320 320
321 @staticmethod 321 @staticmethod
322 def or_graphs(graphs): 322 def or_graphs(graphs):
323 return reduce(lambda acc, g: ('OR', acc, g), graphs) 323 return reduce(lambda acc, g: ('OR', acc, g), graphs)
324 324
325 @staticmethod 325 @staticmethod
326 def cat_graphs(graphs): 326 def cat_graphs(graphs):
327 return reduce(lambda acc, g: ('CAT', acc, g), graphs) 327 return reduce(lambda acc, g: ('CAT', acc, g), graphs)
328 328
329 __modifer_map = { 329 __modifer_map = {
330 '+': 'ONE_OR_MORE', 330 '+': 'ONE_OR_MORE',
331 '?': 'ZERO_OR_ONE', 331 '?': 'ZERO_OR_ONE',
332 '*': 'ZERO_OR_MORE', 332 '*': 'ZERO_OR_MORE',
333 } 333 }
334 334
335 @staticmethod 335 @staticmethod
336 def apply_modifier(modifier, graph): 336 def apply_modifier(modifier, graph):
337 return (NfaBuilder.__modifer_map[modifier], graph) 337 return (NfaBuilder.__modifer_map[modifier], graph)
OLDNEW
« no previous file with comments | « no previous file | tools/lexer_generator/rule_parser.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698