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

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

Issue 70103016: Experimental parser: small cleanup (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 | « tools/lexer_generator/dfa.py ('k') | no next file » | 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 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
141 | empty''' 141 | empty'''
142 p[0] = p[1] 142 p[0] = p[1]
143 143
144 def p_identifier_action(self, p): 144 def p_identifier_action(self, p):
145 '''identifier_action : IDENTIFIER 145 '''identifier_action : IDENTIFIER
146 | IDENTIFIER LEFT_PARENTHESIS IDENTIFIER RIGHT_PARENTHE SIS''' 146 | IDENTIFIER LEFT_PARENTHESIS IDENTIFIER RIGHT_PARENTHE SIS'''
147 assert p[1] != 'code' 147 assert p[1] != 'code'
148 if len(p) == 2: 148 if len(p) == 2:
149 p[0] = (p[1], None) 149 p[0] = (p[1], None)
150 elif len(p) == 5: 150 elif len(p) == 5:
151 p[0] = (p[1], p[2]) 151 p[0] = (p[1], p[3])
152 else: 152 else:
153 raise Exception() 153 raise Exception()
154 154
155 def p_composite_regex(self, p): 155 def p_composite_regex(self, p):
156 '''composite_regex : regex_parts OR regex_parts 156 '''composite_regex : regex_parts OR regex_parts
157 | regex_parts''' 157 | regex_parts'''
158 if len(p) == 2: 158 if len(p) == 2:
159 p[0] = p[1] 159 p[0] = p[1]
160 else: 160 else:
161 p[0] = NfaBuilder.or_graphs([p[1], p[3]]) 161 p[0] = NfaBuilder.or_graphs([p[1], p[3]])
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after
312 graph = NfaBuilder.join_subgraph( 312 graph = NfaBuilder.join_subgraph(
313 graph, transition, rule_map[transition], subgraph_modifier) 313 graph, transition, rule_map[transition], subgraph_modifier)
314 graphs.append(graph) 314 graphs.append(graph)
315 if continues == len(graphs): 315 if continues == len(graphs):
316 graphs.append(NfaBuilder.epsilon()) 316 graphs.append(NfaBuilder.epsilon())
317 if v['catch_all']: 317 if v['catch_all']:
318 (precedence, catch_all) = v['catch_all'] 318 (precedence, catch_all) = v['catch_all']
319 assert catch_all == (None, None, 'continue'), "unimplemented" 319 assert catch_all == (None, None, 'continue'), "unimplemented"
320 graphs.append(NfaBuilder.add_continue(NfaBuilder.catch_all())) 320 graphs.append(NfaBuilder.add_continue(NfaBuilder.catch_all()))
321 graph = NfaBuilder.or_graphs(graphs) 321 graph = NfaBuilder.or_graphs(graphs)
322 rule_map[k] = graph 322 rule_map[subgraph] = graph
323 # process first the subgraphs, then the default graph 323 # process first the subgraphs, then the default graph
324 for k, v in parser_state.rules.items(): 324 for k, v in parser_state.rules.items():
325 if k == 'default': continue 325 if k == 'default': continue
326 process(k, v) 326 process(k, v)
327 process('default', parser_state.rules['default']) 327 process('default', parser_state.rules['default'])
328 # build the automata 328 # build the automata
329 for rule_name, graph in rule_map.items(): 329 for rule_name, graph in rule_map.items():
330 self.__automata[rule_name] = RuleProcessor.Automata(builder, graph) 330 self.__automata[rule_name] = RuleProcessor.Automata(builder, graph)
331 # process default_action 331 # process default_action
332 default_action = parser_state.rules['default']['default_action'] 332 default_action = parser_state.rules['default']['default_action']
333 self.default_action = Action(None, default_action[1]) if default_action else None 333 self.default_action = Action(None, default_action[1]) if default_action else None
OLDNEW
« no previous file with comments | « tools/lexer_generator/dfa.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698