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

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

Issue 61003003: Experimental parser: cleanup rule processing result (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') | 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 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
60 60
61 load_template = ''' draw('%s', '%s');''' 61 load_template = ''' draw('%s', '%s');'''
62 62
63 load_outer_template = ''' <script> 63 load_outer_template = ''' <script>
64 %s 64 %s
65 </script>''' 65 </script>'''
66 66
67 def generate_html(rule_processor): 67 def generate_html(rule_processor):
68 scripts = [] 68 scripts = []
69 loads = [] 69 loads = []
70 for i, (name, (nfa, dfa)) in enumerate(list(rule_processor.automata_iter())): 70 for i, (name, automata) in enumerate(list(rule_processor.automata_iter())):
71 if name == 'Normal': continue 71 (nfa, dfa) = (automata.nfa(), automata.dfa())
72 (nfa_i, dfa_i) = ("nfa_%d" % i, "dfa_%d" % i) 72 (nfa_i, dfa_i) = ("nfa_%d" % i, "dfa_%d" % i)
73 scripts.append(script_template % (nfa_i, nfa.to_dot())) 73 scripts.append(script_template % (nfa_i, nfa.to_dot()))
74 scripts.append(script_template % (dfa_i, dfa.to_dot())) 74 scripts.append(script_template % (dfa_i, dfa.to_dot()))
75 loads.append(load_template % ("nfa [%s]" % name, nfa_i)) 75 loads.append(load_template % ("nfa [%s]" % name, nfa_i))
76 loads.append(load_template % ("dfa [%s]" % name, dfa_i)) 76 loads.append(load_template % ("dfa [%s]" % name, dfa_i))
77 body = "\n".join(scripts) + (load_outer_template % "\n".join(loads)) 77 body = "\n".join(scripts) + (load_outer_template % "\n".join(loads))
78 return file_template % body 78 return file_template % body
79 79
80 def generate_code(rule_processor): 80 def generate_code(rule_processor):
81 (nfa, dfa) = rule_processor.default_automata() 81 dfa = rule_processor.default_automata().dfa()
82 return CodeGenerator.dfa_to_code(dfa) 82 return CodeGenerator.dfa_to_code(dfa)
83 83
84 def lex(rule_processor, string): 84 def lex(rule_processor, string):
85 for t in rule_processor.lex(string + '\0'): 85 for t in rule_processor.lex(string + '\0'):
86 print t 86 print t
87 87
88 if __name__ == '__main__': 88 if __name__ == '__main__':
89 89
90 parser = argparse.ArgumentParser() 90 parser = argparse.ArgumentParser()
91 parser.add_argument('--html') 91 parser.add_argument('--html')
(...skipping 18 matching lines...) Expand all
110 if code_file: 110 if code_file:
111 code = generate_code(rule_processor) 111 code = generate_code(rule_processor)
112 with open(code_file, 'w') as f: 112 with open(code_file, 'w') as f:
113 f.write(code) 113 f.write(code)
114 print "wrote code to %s" % code_file 114 print "wrote code to %s" % code_file
115 115
116 input_file = args.input 116 input_file = args.input
117 if input_file: 117 if input_file:
118 with open(input_file, 'r') as f: 118 with open(input_file, 'r') as f:
119 lex(rule_processor, f.read()) 119 lex(rule_processor, f.read())
OLDNEW
« no previous file with comments | « tools/lexer_generator/dfa.py ('k') | tools/lexer_generator/rule_parser.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698