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

Unified Diff: tools/lexer_generator/automaton.py

Issue 160443002: Experimental parser: remove match actions (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 | « tools/lexer_generator/action.py ('k') | tools/lexer_generator/code_generator.jinja » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tools/lexer_generator/automaton.py
diff --git a/tools/lexer_generator/automaton.py b/tools/lexer_generator/automaton.py
index 776b88a3d9f0d3cfacfd32f0f7bc92264fbadffb..5bb71f87d7f409cd8400f08dd0d41a7f7546f8bc 100644
--- a/tools/lexer_generator/automaton.py
+++ b/tools/lexer_generator/automaton.py
@@ -109,9 +109,16 @@ class Automaton(object):
return set(chain(iter(states), *map(f, states)))
@staticmethod
- def __transition_states_for_char(valid_states, c):
- f = lambda state : state.transition_state_iter_for_char(c)
- return set(chain(*map(f, Automaton.epsilon_closure(valid_states))))
+ def __omega_closure(states):
+ f = lambda s : s.transition_state_iter_for_key(TransitionKey.omega())
+ new_states = set(chain(*map(f, states)))
+ return set(chain(iter(states), iter(Automaton.epsilon_closure(new_states))))
+
+ @staticmethod
+ def __transition_states_for_char(states, c):
+ f = lambda s : s.transition_state_iter_for_char(c)
+ states = set(chain(*map(f, Automaton.epsilon_closure(states))))
+ return Automaton.__omega_closure(states)
def matches(self, string):
valid_states = self.start_set()
@@ -119,9 +126,13 @@ class Automaton(object):
valid_states = Automaton.__transition_states_for_char(valid_states, c)
if not valid_states:
return False
- valid_states = self.epsilon_closure(valid_states)
+ valid_states = self.__omega_closure(self.epsilon_closure(valid_states))
return len(self.terminal_set().intersection(valid_states)) > 0
+ @staticmethod
+ def dominant_action(states):
+ return Action.dominant_action(map(lambda s: s.action(), states))
+
def lex(self, string, default_action):
last_position = 0
valid_states = self.start_set()
@@ -130,7 +141,8 @@ class Automaton(object):
if transitions:
valid_states = transitions
continue
- action = Action.dominant_action(valid_states)
+ # TODO(dcarney): action collection should walk omega transitions
+ action = self.dominant_action(valid_states)
if not action:
assert default_action
action = default_action
@@ -139,8 +151,8 @@ class Automaton(object):
# lex next token
valid_states = Automaton.__transition_states_for_char(self.start_set(), c)
assert valid_states
- valid_states = self.epsilon_closure(valid_states)
- action = Action.dominant_action(valid_states)
+ valid_states = self.__omega_closure(self.epsilon_closure(valid_states))
+ action = self.dominant_action(valid_states)
if not action:
assert default_action
action = default_action
« no previous file with comments | « tools/lexer_generator/action.py ('k') | tools/lexer_generator/code_generator.jinja » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698