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

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

Issue 136753019: Experimental parser: output alias dot to html (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 | « no previous file | tools/lexer_generator/rule_parser.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 for i, (name, alias) in enumerate(list(rule_processor.alias_iter())):
90 alias_i = "alias_%d" % i
91 dot = alias.to_dot()
92 scripts.append(script_template % (alias_i, dot))
93 loads.append(load_template % ("alias [%s]" % name, alias_i))
89 for i, (name, automata) in enumerate(list(rule_processor.automata_iter())): 94 for i, (name, automata) in enumerate(list(rule_processor.automata_iter())):
90 rule_i = "rule_%d" % i 95 rule_i = "rule_%d" % i
91 dot = automata.rule_term().to_dot() 96 dot = automata.rule_term().to_dot()
92 scripts.append(script_template % (rule_i, dot)) 97 scripts.append(script_template % (rule_i, dot))
93 loads.append(load_template % ("rules [%s]" % name, rule_i)) 98 loads.append(load_template % ("rule [%s]" % name, rule_i))
94 body = "\n".join(scripts) + (load_outer_template % "\n".join(loads)) 99 body = "\n".join(scripts) + (load_outer_template % "\n".join(loads))
95 return file_template % body 100 return file_template % body
96 101
97 def generate_code(rule_processor, minimize_default): 102 def generate_code(rule_processor, minimize_default):
98 return CodeGenerator.rule_processor_to_code(rule_processor, minimize_default) 103 return CodeGenerator.rule_processor_to_code(rule_processor, minimize_default)
99 104
100 def lex(rule_processor, string): 105 def lex(rule_processor, string):
101 for t in rule_processor.default_automata().dfa().lex(string + '\0'): 106 for t in rule_processor.default_automata().dfa().lex(string + '\0'):
102 print t 107 print t
103 108
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
166 code = code_generator.process() 171 code = code_generator.process()
167 with open(code_file, 'w') as f: 172 with open(code_file, 'w') as f:
168 f.write(code) 173 f.write(code)
169 if verbose: 174 if verbose:
170 print "wrote code to %s" % code_file 175 print "wrote code to %s" % code_file
171 176
172 input_file = args.input 177 input_file = args.input
173 if input_file: 178 if input_file:
174 with open(input_file, 'r') as f: 179 with open(input_file, 'r') as f:
175 lex(rule_processor, f.read()) 180 lex(rule_processor, f.read())
OLDNEW
« no previous file with comments | « no previous file | tools/lexer_generator/rule_parser.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698