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

Unified Diff: tools/lexer_generator/nfa.py

Issue 71313002: Experimental parser: action refactor (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/lexer_test.py ('k') | 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 284c88d6edea8ba20d101bbf94c6d2fc2e82a720..73ff0ceb4f6bdcf05a7dda4adf2910138d6f8c0b 100644
--- a/tools/lexer_generator/nfa.py
+++ b/tools/lexer_generator/nfa.py
@@ -30,8 +30,8 @@ from automaton import *
class NfaState(AutomatonState):
- def __init__(self, node_number):
- super(NfaState, self).__init__(node_number)
+ def __init__(self):
+ super(NfaState, self).__init__()
self.__transitions = {}
self.__unclosed = set()
self.__epsilon_closure = None
@@ -150,24 +150,31 @@ class Nfa(Automaton):
return TransitionKey.disjoint_keys(keys)
@staticmethod
+ def __gather_actions(states):
+ action = None
+ for state in states:
+ if not state.action():
+ continue
+ if not action:
+ action = state.action()
+ continue
+ if state.action().precedence() == action.precedence():
+ assert state.action() == action
+ elif state.action().precedence() < action.precedence():
+ action = state.action()
+ return action
+
+ @staticmethod
def __to_dfa(nfa_state_set, dfa_nodes, end_node):
nfa_state_set = Nfa.__close(nfa_state_set)
assert nfa_state_set
name = ".".join(str(x.node_number()) for x in sorted(nfa_state_set))
if name in dfa_nodes:
return name
- def gather_actions(states):
- actions = set()
- for state in states:
- if state.action():
- actions.add(state.action())
- actions = list(actions)
- actions.sort()
- return actions
dfa_nodes[name] = {
'transitions': {},
'terminal': end_node in nfa_state_set,
- 'actions' : gather_actions(nfa_state_set)}
+ 'action' : Nfa.__gather_actions(nfa_state_set)}
for key in Nfa.__gather_transition_keys(nfa_state_set):
match_states = set()
f = lambda acc, state: acc | state.key_matches(key)
« no previous file with comments | « tools/lexer_generator/lexer_test.py ('k') | tools/lexer_generator/nfa_builder.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698