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

Unified Diff: tools/lexer_generator/rule_parser.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/nfa_builder.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/rule_parser.py
diff --git a/tools/lexer_generator/rule_parser.py b/tools/lexer_generator/rule_parser.py
index 76bd1fe0fe132fef4d13548ec5a829abe89b2d8e..f9787f7ba95d8d1f4812c33901ef398a4a88a2a8 100644
--- a/tools/lexer_generator/rule_parser.py
+++ b/tools/lexer_generator/rule_parser.py
@@ -26,6 +26,7 @@
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
import ply.yacc as yacc
+from automaton import Action
from rule_lexer import RuleLexer
from regex_parser import RegexParser
from nfa_builder import NfaBuilder
@@ -116,7 +117,7 @@ class RuleParser:
assert not rules['catch_all']
rules['catch_all'] = transition
else:
- rule = (p[1], (RuleParser.__rule_precedence_counter, code, transition))
+ rule = (p[1], RuleParser.__rule_precedence_counter, code, transition)
rules['regex'].append(rule)
def p_action(self, p):
@@ -244,11 +245,11 @@ class RuleProcessor(object):
def process(k, v):
graphs = []
continues = 0
- for (graph, (precedence, code, transition)) in v['regex']:
+ for (graph, precedence, code, transition) in v['regex']:
default_code = v['default_action']
- action = code if code else default_code
- if action:
- graph = NfaBuilder.add_action(graph, (precedence, action))
+ if code or default_code:
+ action = Action('code', code if code else default_code, precedence)
+ graph = NfaBuilder.add_action(graph, action)
if not transition or transition == 'break':
pass
elif transition == 'continue':
@@ -258,7 +259,7 @@ class RuleProcessor(object):
elif (transition == 'terminate' or
transition == 'terminate_illegal'):
assert not code
- graph = NfaBuilder.add_action(graph, (-1, transition))
+ graph = NfaBuilder.add_action(graph, Action(transition, None, -1))
else:
assert k == 'default'
subgraph_modifier = '*' if code else None
« no previous file with comments | « tools/lexer_generator/nfa_builder.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698