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

Unified Diff: tools/lexer_generator/nfa.py

Issue 73023005: Experimental lexer generator: random refactoring + comments. (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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « tools/lexer_generator/dfa.py ('k') | tools/lexer_generator/transition_keys.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 24870e5e9036c90b8264b28526842bfa5a5b867f..8f9781dc476bb933462730253139377513f19c39 100644
--- a/tools/lexer_generator/nfa.py
+++ b/tools/lexer_generator/nfa.py
@@ -98,10 +98,12 @@ class NfaState(AutomatonState):
self.__add_transition(TransitionKey.epsilon(), end)
def __matches(self, match_func, value):
- f = lambda acc, (k, vs): acc | vs if match_func(k, value) else acc
+ # f collects states whose corresponding TransitionKey matches 'value'.
+ f = (lambda acc, (key, states):
+ acc | states if match_func(key, value) else acc)
return reduce(f, self.__transitions.items(), set())
- def char_matches(self, value):
+ def next_states_with_char(self, value):
return self.__matches(lambda k, v : k.matches_char(v), value)
def key_matches(self, value):
@@ -136,7 +138,7 @@ class Nfa(Automaton):
def matches(self, string):
valid_states = Nfa.__close(set([self.__start]))
for c in string:
- f = lambda acc, state: acc | state.char_matches(c)
+ f = lambda acc, state: acc | state.next_states_with_char(c)
transitions = reduce(f, valid_states, set())
if not transitions:
return False
« no previous file with comments | « tools/lexer_generator/dfa.py ('k') | tools/lexer_generator/transition_keys.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698