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

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

Issue 144603003: Experimental parser: better eos 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 | « tools/lexer_generator/lexer_test.py ('k') | tools/lexer_generator/rule_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 233 matching lines...) Expand 10 before | Expand all | Expand 10 after
244 catch_all = TransitionKey.unique('catch_all') 244 catch_all = TransitionKey.unique('catch_all')
245 transitions = state.transitions() 245 transitions = state.transitions()
246 if not catch_all in transitions: 246 if not catch_all in transitions:
247 return 247 return
248 f = lambda acc, state: acc | set(state.epsilon_closure_iter()) 248 f = lambda acc, state: acc | set(state.epsilon_closure_iter())
249 reachable_states = reduce(f, transitions[catch_all], set()) 249 reachable_states = reduce(f, transitions[catch_all], set())
250 f = lambda acc, state: acc | set(state.transitions().keys()) 250 f = lambda acc, state: acc | set(state.transitions().keys())
251 keys = reduce(f, reachable_states, set()) 251 keys = reduce(f, reachable_states, set())
252 keys.discard(TransitionKey.epsilon()) 252 keys.discard(TransitionKey.epsilon())
253 keys.discard(catch_all) 253 keys.discard(catch_all)
254 keys.discard(TransitionKey.unique('eos'))
254 inverse_key = TransitionKey.inverse_key(encoding, keys) 255 inverse_key = TransitionKey.inverse_key(encoding, keys)
255 if inverse_key: 256 if inverse_key:
256 transitions[inverse_key] = transitions[catch_all] 257 transitions[inverse_key] = transitions[catch_all]
257 del transitions[catch_all] 258 del transitions[catch_all]
258 259
259 def nfa(self, graph): 260 def nfa(self, graph):
260 (start, end, nodes_created) = self.__nfa(graph) 261 (start, end, nodes_created) = self.__nfa(graph)
261 262
262 global_end_to_return = self.__global_end_node or end 263 global_end_to_return = self.__global_end_node or end
263 assert global_end_to_return 264 assert global_end_to_return
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
337 338
338 __modifer_map = { 339 __modifer_map = {
339 '+': 'ONE_OR_MORE', 340 '+': 'ONE_OR_MORE',
340 '?': 'ZERO_OR_ONE', 341 '?': 'ZERO_OR_ONE',
341 '*': 'ZERO_OR_MORE', 342 '*': 'ZERO_OR_MORE',
342 } 343 }
343 344
344 @staticmethod 345 @staticmethod
345 def apply_modifier(modifier, graph): 346 def apply_modifier(modifier, graph):
346 return (NfaBuilder.__modifer_map[modifier], graph) 347 return (NfaBuilder.__modifer_map[modifier], graph)
OLDNEW
« no previous file with comments | « tools/lexer_generator/lexer_test.py ('k') | tools/lexer_generator/rule_lexer.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698