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

Side by Side Diff: tools/lexer_generator/generator.py

Issue 66533002: Experimental parser: better generation (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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « src/lexer/lexer_py.re ('k') | tools/lexer_generator/nfa.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 # Copyright 2013 the V8 project authors. All rights reserved. 1 # Copyright 2013 the V8 project authors. All rights reserved.
2 # Redistribution and use in source and binary forms, with or without 2 # Redistribution and use in source and binary forms, with or without
3 # modification, are permitted provided that the following conditions are 3 # modification, are permitted provided that the following conditions are
4 # met: 4 # met:
5 # 5 #
6 # * Redistributions of source code must retain the above copyright 6 # * Redistributions of source code must retain the above copyright
7 # notice, this list of conditions and the following disclaimer. 7 # notice, this list of conditions and the following disclaimer.
8 # * Redistributions in binary form must reproduce the above 8 # * Redistributions in binary form must reproduce the above
9 # copyright notice, this list of conditions and the following 9 # copyright notice, this list of conditions and the following
10 # disclaimer in the documentation and/or other materials provided 10 # disclaimer in the documentation and/or other materials provided
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
83 def process(k, v): 83 def process(k, v):
84 assert 'default' in v 84 assert 'default' in v
85 graphs = [] 85 graphs = []
86 for (graph, action) in v['regex']: 86 for (graph, action) in v['regex']:
87 (precedence, code, transition) = action 87 (precedence, code, transition) = action
88 if code: 88 if code:
89 graph = NfaBuilder.add_action(graph, (precedence, code, None)) 89 graph = NfaBuilder.add_action(graph, (precedence, code, None))
90 if transition == 'continue': 90 if transition == 'continue':
91 if not v['default'][1][2] == 'continue': 91 if not v['default'][1][2] == 'continue':
92 graph = NfaBuilder.add_continue(graph) 92 graph = NfaBuilder.add_continue(graph)
93 else:
94 pass # TODO null key
93 elif (transition == 'break' or 95 elif (transition == 'break' or
94 transition == 'terminate' or 96 transition == 'terminate' or
95 transition == 'terminate_illegal'): 97 transition == 'terminate_illegal'):
96 NfaBuilder.add_action(graph, (-1, transition, None)) 98 graph = NfaBuilder.add_action(graph, (10000, transition, None))
97 else: 99 else:
98 assert k == 'default' 100 assert k == 'default'
99 graph = NfaBuilder.join_subgraph(graph, transition, rule_map[transition] ) 101 graph = NfaBuilder.join_subgraph(graph, transition, rule_map[transition] )
100 graphs.append(graph) 102 graphs.append(graph)
101 graph = NfaBuilder.or_graphs(graphs) 103 graph = NfaBuilder.or_graphs(graphs)
102 # merge default action 104 # merge default action
103 (precedence, code, transition) = v['default'][1] 105 (precedence, code, transition) = v['default'][1]
104 assert transition == 'continue' or transition == 'break' 106 assert transition == 'continue' or transition == 'break'
105 if transition == 'continue': 107 if transition == 'continue':
106 assert k != 'default' 108 assert k != 'default'
107 # graph = NfaBuilder.apply_modifier('*', graph) 109 graph = NfaBuilder.add_incoming_action(graph, (10000, k, None))
108 if code: 110 if code:
109 graph = NfaBuilder.add_incoming_action(graph, (precedence, code, None)) 111 graph = NfaBuilder.add_incoming_action(graph, (precedence, code, None))
110 rule_map[k] = graph 112 rule_map[k] = graph
111 for k, v in parser_state.rules.items(): 113 for k, v in parser_state.rules.items():
112 if k == 'default': continue 114 if k == 'default': continue
113 process(k, v) 115 process(k, v)
114 process('default', parser_state.rules['default']) 116 process('default', parser_state.rules['default'])
115 html_data = [] 117 html_data = []
116 for rule_name, graph in rule_map.items(): 118 for rule_name, graph in rule_map.items():
117 nfa = builder.nfa(graph) 119 nfa = builder.nfa(graph)
(...skipping 15 matching lines...) Expand all
133 with open(re_file, 'r') as f: 135 with open(re_file, 'r') as f:
134 RuleParser.parse(f.read(), parser_state) 136 RuleParser.parse(f.read(), parser_state)
135 html_data = process_rules(parser_state) 137 html_data = process_rules(parser_state)
136 138
137 html_file = args.html 139 html_file = args.html
138 if html_file: 140 if html_file:
139 html = generate_html(html_data) 141 html = generate_html(html_data)
140 with open(args.html, 'w') as f: 142 with open(args.html, 'w') as f:
141 f.write(html) 143 f.write(html)
142 print "wrote html to %s" % html_file 144 print "wrote html to %s" % html_file
OLDNEW
« no previous file with comments | « src/lexer/lexer_py.re ('k') | tools/lexer_generator/nfa.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698