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

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

Issue 59823004: Exoerimental parser: jinja codegen templates (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/code_generator_test.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 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
90 for t in rule_processor.default_automata().dfa().lex(string + '\0'): 90 for t in rule_processor.default_automata().dfa().lex(string + '\0'):
91 print t 91 print t
92 92
93 if __name__ == '__main__': 93 if __name__ == '__main__':
94 94
95 parser = argparse.ArgumentParser() 95 parser = argparse.ArgumentParser()
96 parser.add_argument('--html') 96 parser.add_argument('--html')
97 parser.add_argument('--re', default='src/lexer/lexer_py.re') 97 parser.add_argument('--re', default='src/lexer/lexer_py.re')
98 parser.add_argument('--input') 98 parser.add_argument('--input')
99 parser.add_argument('--code') 99 parser.add_argument('--code')
100 parser.add_argument('--minimize-default', action='store_true') 100 parser.add_argument('--no-minimize-default', action='store_true')
101 parser.add_argument('--no-verify-default', action='store_true') 101 parser.add_argument('--no-verify-default', action='store_true')
102 parser.add_argument('--verbose', action='store_true')
103 parser.add_argument('--debug-code', action='store_true')
102 args = parser.parse_args() 104 args = parser.parse_args()
103 105
106 minimize_default = not args.no_minimize_default
107 verbose = args.verbose
108
104 re_file = args.re 109 re_file = args.re
105 print "parsing %s" % re_file 110 if verbose:
111 print "parsing %s" % re_file
106 with open(re_file, 'r') as f: 112 with open(re_file, 'r') as f:
107 rule_processor = RuleProcessor.parse(f.read()) 113 rule_processor = RuleProcessor.parse(f.read())
108 114
109 if args.minimize_default: 115 if minimize_default:
110 if args.no_verify_default: 116 if args.no_verify_default:
111 DfaMinimizer.set_verify(False) 117 DfaMinimizer.set_verify(False)
112 dfa = rule_processor.default_automata().dfa() 118 dfa = rule_processor.default_automata().dfa()
113 mdfa = rule_processor.default_automata().minimal_dfa() 119 mdfa = rule_processor.default_automata().minimal_dfa()
114 print "nodes reduced from %s to %s" % (dfa.node_count(), mdfa.node_count()) 120 if verbose:
121 print "nodes reduced from %s to %s" % (
122 dfa.node_count(), mdfa.node_count())
115 DfaMinimizer.set_verify(True) 123 DfaMinimizer.set_verify(True)
116 124
117 html_file = args.html 125 html_file = args.html
118 if html_file: 126 if html_file:
119 html = generate_html(rule_processor, args.minimize_default) 127 html = generate_html(rule_processor, minimize_default)
120 with open(args.html, 'w') as f: 128 with open(args.html, 'w') as f:
121 f.write(html) 129 f.write(html)
122 print "wrote html to %s" % html_file 130 if verbose:
131 print "wrote html to %s" % html_file
123 132
124 code_file = args.code 133 code_file = args.code
125 if code_file: 134 if code_file:
126 code = generate_code(rule_processor, args.minimize_default) 135 code_generator = CodeGenerator(rule_processor,
136 minimize_default,
137 args.debug_code)
138 code = code_generator.process()
127 with open(code_file, 'w') as f: 139 with open(code_file, 'w') as f:
128 f.write(code) 140 f.write(code)
129 print "wrote code to %s" % code_file 141 if verbose:
142 print "wrote code to %s" % code_file
130 143
131 input_file = args.input 144 input_file = args.input
132 if input_file: 145 if input_file:
133 with open(input_file, 'r') as f: 146 with open(input_file, 'r') as f:
134 lex(rule_processor, f.read()) 147 lex(rule_processor, f.read())
OLDNEW
« no previous file with comments | « tools/lexer_generator/code_generator_test.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698