| OLD | NEW |
| 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 Loading... |
| 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('--char-type') | 100 parser.add_argument('--encoding') |
| 101 parser.add_argument('--no-minimize-default', action='store_true') | 101 parser.add_argument('--no-minimize-default', action='store_true') |
| 102 parser.add_argument('--no-verify-default', action='store_true') | 102 parser.add_argument('--no-verify-default', action='store_true') |
| 103 parser.add_argument('--no-inline', action='store_true') | 103 parser.add_argument('--no-inline', action='store_true') |
| 104 parser.add_argument('--verbose', action='store_true') | 104 parser.add_argument('--verbose', action='store_true') |
| 105 parser.add_argument('--debug-code', action='store_true') | 105 parser.add_argument('--debug-code', action='store_true') |
| 106 args = parser.parse_args() | 106 args = parser.parse_args() |
| 107 | 107 |
| 108 minimize_default = not args.no_minimize_default | 108 minimize_default = not args.no_minimize_default |
| 109 verbose = args.verbose | 109 verbose = args.verbose |
| 110 | 110 |
| (...skipping 15 matching lines...) Expand all Loading... |
| 126 | 126 |
| 127 html_file = args.html | 127 html_file = args.html |
| 128 if html_file: | 128 if html_file: |
| 129 html = generate_html(rule_processor, minimize_default) | 129 html = generate_html(rule_processor, minimize_default) |
| 130 with open(args.html, 'w') as f: | 130 with open(args.html, 'w') as f: |
| 131 f.write(html) | 131 f.write(html) |
| 132 if verbose: | 132 if verbose: |
| 133 print "wrote html to %s" % html_file | 133 print "wrote html to %s" % html_file |
| 134 | 134 |
| 135 code_file = args.code | 135 code_file = args.code |
| 136 char_type = args.char_type | 136 encoding = args.encoding |
| 137 if not char_type: | 137 if not encoding: |
| 138 char_type = 'uint8_t' | 138 encoding = 'latin1' |
| 139 | 139 |
| 140 if code_file: | 140 if code_file: |
| 141 code_generator = CodeGenerator(rule_processor, | 141 code_generator = CodeGenerator(rule_processor, |
| 142 char_type, | 142 encoding, |
| 143 minimize_default = minimize_default, | 143 minimize_default = minimize_default, |
| 144 log = verbose, | 144 log = verbose, |
| 145 inline = not args.no_inline, | 145 inline = not args.no_inline, |
| 146 debug_print = args.debug_code) | 146 debug_print = args.debug_code) |
| 147 code = code_generator.process() | 147 code = code_generator.process() |
| 148 with open(code_file, 'w') as f: | 148 with open(code_file, 'w') as f: |
| 149 f.write(code) | 149 f.write(code) |
| 150 if verbose: | 150 if verbose: |
| 151 print "wrote code to %s" % code_file | 151 print "wrote code to %s" % code_file |
| 152 | 152 |
| 153 input_file = args.input | 153 input_file = args.input |
| 154 if input_file: | 154 if input_file: |
| 155 with open(input_file, 'r') as f: | 155 with open(input_file, 'r') as f: |
| 156 lex(rule_processor, f.read()) | 156 lex(rule_processor, f.read()) |
| OLD | NEW |