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

Unified Diff: tools/lexer_generator/nfa.py

Issue 148293022: Experimental parser: make nfa nodes immutable (Closed) Base URL: https://v8.googlecode.com/svn/branches/experimental/parser
Patch Set: Created 6 years, 10 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | tools/lexer_generator/nfa_builder.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tools/lexer_generator/nfa.py
diff --git a/tools/lexer_generator/nfa.py b/tools/lexer_generator/nfa.py
index cf887304a7fdc6cbe12872c5b5444787c606706d..8aa2b69088fd8f7c2a17092a888db16359b167f8 100644
--- a/tools/lexer_generator/nfa.py
+++ b/tools/lexer_generator/nfa.py
@@ -55,9 +55,19 @@ class NfaState(AutomatonState):
assert isinstance(action, Action)
self.__action = action
- def transitions(self):
+ def state_iter_for_key(self, key):
assert self.is_closed()
- return self.__transitions
+ if not key in self.__transitions:
+ return iter([])
+ return iter(self.__transitions[key])
+
+ def swap_key(self, old_key, new_key):
+ 'this is one of the few mutations allowed after closing'
+ assert self.is_closed()
+ assert not new_key == TransitionKey.epsilon(), "changes epsilon closure"
+ value = self.__transitions[old_key]
+ del self.__transitions[old_key]
+ self.__transitions[new_key] = value
def __add_transition(self, key, next_state):
assert key != None
@@ -97,6 +107,7 @@ class NfaState(AutomatonState):
state_filter = lambda x: True,
match_func = lambda x, y: True,
yield_func = lambda x, y: (x, y)):
+ assert self.is_closed()
for key, states in self.__transitions.items():
if key_filter(key):
for state in states:
« no previous file with comments | « no previous file | tools/lexer_generator/nfa_builder.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698