Revision: 17905
Author: [email protected]
Date: Wed Nov 20 10:42:41 2013 UTC
Log: Experimental parser: cleanup transition iteration a little
[email protected]
BUG=
Review URL: https://codereview.chromium.org/78133002
http://code.google.com/p/v8/source/detail?r=17905
Modified:
/branches/experimental/parser/tools/lexer_generator/dfa.py
/branches/experimental/parser/tools/lexer_generator/nfa.py
=======================================
--- /branches/experimental/parser/tools/lexer_generator/dfa.py Wed Nov 20
10:31:17 2013 UTC
+++ /branches/experimental/parser/tools/lexer_generator/dfa.py Wed Nov 20
10:42:41 2013 UTC
@@ -59,10 +59,8 @@
# TODO abstract state matching
def __matches(self, match_func, value):
- # f collects states whose corresponding TransitionKey matches 'value'.
- f = (lambda acc, (key, state):
- acc | set([state]) if match_func(key, value) else acc)
- return reduce(f, self.__transitions.items(), set())
+ items = self.__transitions.items()
+ return [state for (key, state) in items if match_func(key, value)]
def transition_state_iter_for_char(self, value):
return iter(self.__matches(lambda k, v : k.matches_char(v), value))
@@ -76,7 +74,7 @@
return None
# Since this is a dfa, we should have at most one such state. Return
it.
assert len(matches) == 1
- return iter(matches).next()
+ return matches[0]
class Dfa(Automaton):
=======================================
--- /branches/experimental/parser/tools/lexer_generator/nfa.py Wed Nov 20
10:06:26 2013 UTC
+++ /branches/experimental/parser/tools/lexer_generator/nfa.py Wed Nov 20
10:42:41 2013 UTC
@@ -99,15 +99,15 @@
def __matches(self, match_func, value):
# 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())
+ items = self.__transitions.items()
+ iters = [iter(states) for (key, states) in items if match_func(key,
value)]
+ return chain(*iters)
def transition_state_iter_for_char(self, value):
- return iter(self.__matches(lambda k, v : k.matches_char(v), value))
+ return self.__matches(lambda k, v : k.matches_char(v), value)
def transition_state_iter_for_key(self, value):
- return iter(self.__matches(lambda k, v : k.is_superset_of_key(v),
value))
+ return self.__matches(lambda k, v : k.is_superset_of_key(v), value)
class Nfa(Automaton):
--
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev
---
You received this message because you are subscribed to the Google Groups "v8-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.