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

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

Issue 137883006: Experimental parser: use Terms instead of tuples (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.py ('k') | tools/lexer_generator/lexer_test.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 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
79 loads.append(load_template % ("dfa [%s]" % name, dfa_i)) 79 loads.append(load_template % ("dfa [%s]" % name, dfa_i))
80 if mdfa and mdfa.node_count() != dfa.node_count(): 80 if mdfa and mdfa.node_count() != dfa.node_count():
81 scripts.append(script_template % (mdfa_i, mdfa.to_dot())) 81 scripts.append(script_template % (mdfa_i, mdfa.to_dot()))
82 loads.append(load_template % ("mdfa [%s]" % name, mdfa_i)) 82 loads.append(load_template % ("mdfa [%s]" % name, mdfa_i))
83 body = "\n".join(scripts) + (load_outer_template % "\n".join(loads)) 83 body = "\n".join(scripts) + (load_outer_template % "\n".join(loads))
84 return file_template % body 84 return file_template % body
85 85
86 def generate_rule_tree_html(rule_processor): 86 def generate_rule_tree_html(rule_processor):
87 scripts = [] 87 scripts = []
88 loads = [] 88 loads = []
89 rule_tree_dots = rule_processor.rule_tree_dots() 89 for i, (name, automata) in enumerate(list(rule_processor.automata_iter())):
90 for i, (rule, dot) in enumerate(rule_tree_dots.items()):
91 rule_i = "rule_%d" % i 90 rule_i = "rule_%d" % i
91 dot = automata.rule_term().to_dot()
92 scripts.append(script_template % (rule_i, dot)) 92 scripts.append(script_template % (rule_i, dot))
93 loads.append(load_template % ("rules [%s]" % rule, rule_i)) 93 loads.append(load_template % ("rules [%s]" % name, rule_i))
94 body = "\n".join(scripts) + (load_outer_template % "\n".join(loads)) 94 body = "\n".join(scripts) + (load_outer_template % "\n".join(loads))
95 return file_template % body 95 return file_template % body
96 96
97 def generate_code(rule_processor, minimize_default): 97 def generate_code(rule_processor, minimize_default):
98 return CodeGenerator.rule_processor_to_code(rule_processor, minimize_default) 98 return CodeGenerator.rule_processor_to_code(rule_processor, minimize_default)
99 99
100 def lex(rule_processor, string): 100 def lex(rule_processor, string):
101 for t in rule_processor.default_automata().dfa().lex(string + '\0'): 101 for t in rule_processor.default_automata().dfa().lex(string + '\0'):
102 print t 102 print t
103 103
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
166 code = code_generator.process() 166 code = code_generator.process()
167 with open(code_file, 'w') as f: 167 with open(code_file, 'w') as f:
168 f.write(code) 168 f.write(code)
169 if verbose: 169 if verbose:
170 print "wrote code to %s" % code_file 170 print "wrote code to %s" % code_file
171 171
172 input_file = args.input 172 input_file = args.input
173 if input_file: 173 if input_file:
174 with open(input_file, 'r') as f: 174 with open(input_file, 'r') as f:
175 lex(rule_processor, f.read()) 175 lex(rule_processor, f.read())
OLDNEW
« no previous file with comments | « tools/lexer_generator/code_generator.py ('k') | tools/lexer_generator/lexer_test.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698