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

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

Issue 171713005: Experimental parser: add backtracking (Closed) Base URL: https://v8.googlecode.com/svn/branches/experimental/parser
Patch Set: Created 6 years, 10 months 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/code_generator.jinja ('k') | tools/lexer_generator/dfa.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 275 matching lines...) Expand 10 before | Expand all | Expand 10 after
286 dfa_states = [] 286 dfa_states = []
287 self.__dfa.visit_all_states(lambda state, acc: dfa_states.append(state)) 287 self.__dfa.visit_all_states(lambda state, acc: dfa_states.append(state))
288 encoding = self.__dfa.encoding() 288 encoding = self.__dfa.encoding()
289 f = lambda state : CodeGenerator.__transform_state(encoding, state) 289 f = lambda state : CodeGenerator.__transform_state(encoding, state)
290 dfa_states = map(f, dfa_states) 290 dfa_states = map(f, dfa_states)
291 id_map = {x['original_node_number'] : x for x in dfa_states} 291 id_map = {x['original_node_number'] : x for x in dfa_states}
292 dfa_states = [] 292 dfa_states = []
293 start_node_number = self.__dfa.start_state().node_number() 293 start_node_number = self.__dfa.start_state().node_number()
294 CodeGenerator.__reorder(start_node_number, id_map, dfa_states) 294 CodeGenerator.__reorder(start_node_number, id_map, dfa_states)
295 # store states 295 # store states
296 eos_states = set([]) 296 eos_states = set()
297 remap = lambda state_id : id_map[state_id]['node_number'] 297 remap = lambda state_id : id_map[state_id]['node_number']
298 def f((key, original_node_number)): 298 def f((key, original_node_number)):
299 return (key, remap(original_node_number)) 299 return (key, remap(original_node_number))
300 for state in dfa_states: 300 for state in dfa_states:
301 state['transitions'] = map(f, state['transitions']) 301 state['transitions'] = map(f, state['transitions'])
302 state['unique_transitions'] = {k : remap(v) 302 state['unique_transitions'] = {k : remap(v)
303 for k, v in state['unique_transitions'].items()} 303 for k, v in state['unique_transitions'].items()}
304 if state['omega_transition'] != None: 304 if state['omega_transition'] != None:
305 state['omega_transition'] = remap(state['omega_transition']) 305 state['omega_transition'] = remap(state['omega_transition'])
306 if 'eos' in state['unique_transitions']: 306 if 'eos' in state['unique_transitions']:
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
412 412
413 return template.render( 413 return template.render(
414 start_node_number = 0, 414 start_node_number = 0,
415 debug_print = self.__debug_print, 415 debug_print = self.__debug_print,
416 default_action = default_action, 416 default_action = default_action,
417 dfa_states = dfa_states, 417 dfa_states = dfa_states,
418 jump_table = self.__jump_table, 418 jump_table = self.__jump_table,
419 encoding = encoding.name(), 419 encoding = encoding.name(),
420 char_type = char_type, 420 char_type = char_type,
421 upper_bound = encoding.primary_range()[1]) 421 upper_bound = encoding.primary_range()[1])
OLDNEW
« no previous file with comments | « tools/lexer_generator/code_generator.jinja ('k') | tools/lexer_generator/dfa.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698