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

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

Issue 59033005: Experimental parser: build regex parse trees for all rules (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/regex_lexer.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 196 matching lines...) Expand 10 before | Expand all | Expand 10 after
207 return ('ACTION', graph, action) 207 return ('ACTION', graph, action)
208 208
209 @staticmethod 209 @staticmethod
210 def or_graphs(graphs): 210 def or_graphs(graphs):
211 return reduce(lambda acc, g: ('OR', acc, g), graphs) 211 return reduce(lambda acc, g: ('OR', acc, g), graphs)
212 212
213 @staticmethod 213 @staticmethod
214 def cat_graphs(graphs): 214 def cat_graphs(graphs):
215 return reduce(lambda acc, g: ('CAT', acc, g), graphs) 215 return reduce(lambda acc, g: ('CAT', acc, g), graphs)
216 216
217 __modifer_map = {
218 '+': 'ONE_OR_MORE',
219 '?': 'ZERO_OR_ONE',
220 '*': 'ZERO_OR_MORE',
221 }
222
223 @staticmethod
224 def apply_modifier(modifier, graph):
225 return (NfaBuilder.__modifer_map[modifier], graph)
226
217 class Nfa: 227 class Nfa:
218 228
219 def __init__(self, start, end, nodes_created): 229 def __init__(self, start, end, nodes_created):
220 self.__start = start 230 self.__start = start
221 self.__end = end 231 self.__end = end
222 self.__epsilon_closure_computed = False 232 self.__epsilon_closure_computed = False
223 self.__verify(nodes_created) 233 self.__verify(nodes_created)
224 234
225 @staticmethod 235 @staticmethod
226 def __visit_edges(edge, compute_next_edge, visitor, state): 236 def __visit_edges(edge, compute_next_edge, visitor, state):
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
328 digraph finite_state_machine { 338 digraph finite_state_machine {
329 rankdir=LR; 339 rankdir=LR;
330 node [shape = circle, style=filled, bgcolor=lightgrey]; S_%s 340 node [shape = circle, style=filled, bgcolor=lightgrey]; S_%s
331 node [shape = doublecircle, style=unfilled]; S_%s 341 node [shape = doublecircle, style=unfilled]; S_%s
332 node [shape = circle]; 342 node [shape = circle];
333 %s 343 %s
334 } 344 }
335 ''' % (self.__start.node_number(), 345 ''' % (self.__start.node_number(),
336 self.__end.node_number(), 346 self.__end.node_number(),
337 "\n".join(node_content)) 347 "\n".join(node_content))
OLDNEW
« no previous file with comments | « no previous file | tools/lexer_generator/regex_lexer.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698