| 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 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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 |
| 111 re_file = args.re | 111 re_file = args.re |
| 112 if verbose: | 112 if verbose: |
| 113 print "parsing %s" % re_file | 113 print "parsing %s" % re_file |
| 114 with open(re_file, 'r') as f: | 114 with open(re_file, 'r') as f: |
| 115 rule_processor = RuleProcessor.parse(f.read()) | 115 rule_processor = RuleProcessor.parse(f.read(), args.encoding) |
| 116 | 116 |
| 117 if minimize_default: | 117 if minimize_default: |
| 118 if args.no_verify_default: | 118 if args.no_verify_default: |
| 119 DfaMinimizer.set_verify(False) | 119 DfaMinimizer.set_verify(False) |
| 120 dfa = rule_processor.default_automata().dfa() | 120 dfa = rule_processor.default_automata().dfa() |
| 121 mdfa = rule_processor.default_automata().minimal_dfa() | 121 mdfa = rule_processor.default_automata().minimal_dfa() |
| 122 if verbose: | 122 if verbose: |
| 123 print "nodes reduced from %s to %s" % ( | 123 print "nodes reduced from %s to %s" % ( |
| 124 dfa.node_count(), mdfa.node_count()) | 124 dfa.node_count(), mdfa.node_count()) |
| 125 DfaMinimizer.set_verify(True) | 125 DfaMinimizer.set_verify(True) |
| 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 if code_file: | 136 if code_file: |
| 137 code_generator = CodeGenerator(rule_processor, | 137 code_generator = CodeGenerator(rule_processor, |
| 138 encoding = args.encoding, | |
| 139 minimize_default = minimize_default, | 138 minimize_default = minimize_default, |
| 140 log = verbose, | 139 log = verbose, |
| 141 inline = not args.no_inline, | 140 inline = not args.no_inline, |
| 142 debug_print = args.debug_code) | 141 debug_print = args.debug_code) |
| 143 code = code_generator.process() | 142 code = code_generator.process() |
| 144 with open(code_file, 'w') as f: | 143 with open(code_file, 'w') as f: |
| 145 f.write(code) | 144 f.write(code) |
| 146 if verbose: | 145 if verbose: |
| 147 print "wrote code to %s" % code_file | 146 print "wrote code to %s" % code_file |
| 148 | 147 |
| 149 input_file = args.input | 148 input_file = args.input |
| 150 if input_file: | 149 if input_file: |
| 151 with open(input_file, 'r') as f: | 150 with open(input_file, 'r') as f: |
| 152 lex(rule_processor, f.read()) | 151 lex(rule_processor, f.read()) |
| OLD | NEW |