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

Unified Diff: tools/lexer_generator/nfa.py

Issue 68343006: Experimental parser: add break instruction (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/generator.py ('k') | no next file » | 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 e818a7da5cb6b8300b691ca2c1488bb0f938b04e..30fade56de7c400184e8621bd34d53264e9cdffa 100644
--- a/tools/lexer_generator/nfa.py
+++ b/tools/lexer_generator/nfa.py
@@ -221,6 +221,14 @@ class NfaBuilder:
end.add_epsilon_transition(state['start_node'])
return (start, ends)
+ def __break(self, graph):
+ (start, ends) = self.__process(graph[1])
+ self.__peek_state()['unpatched_ends'] += ends
+ new_end = self.__new_state()
+ for end in ends:
+ end.add_epsilon_transition(new_end)
+ return (start, [new_end])
+
def __join(self, graph):
(graph, name, subgraph, modifier) = graph[1:]
subgraphs = self.__peek_state()['subgraphs']
@@ -254,6 +262,7 @@ class NfaBuilder:
self.__states.append({
'start_node' : None,
'subgraphs' : {},
+ 'unpatched_ends' : [],
})
def __pop_state(self):
@@ -273,6 +282,10 @@ class NfaBuilder:
for k, subgraph in state['subgraphs'].items():
subgraph[1].close(None)
end = self.__new_state()
+ if self.__states:
+ self.__peek_state()['unpatched_ends'] += state['unpatched_ends']
+ else:
+ self.__patch_ends(state['unpatched_ends'], end)
self.__patch_ends(ends, end)
return (start, end, self.__node_number - start_node_number)
@@ -290,6 +303,10 @@ class NfaBuilder:
return ('CONTINUE', graph)
@staticmethod
+ def add_break(graph):
+ return ('BREAK', graph)
+
+ @staticmethod
def join_subgraph(graph, name, subgraph, modifier):
if modifier:
modifier = NfaBuilder.__modifer_map[modifier]
« no previous file with comments | « tools/lexer_generator/generator.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698