| 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 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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, automata) in enumerate(list(rule_processor.automata_iter())): | 70 for i, (name, automata) in enumerate(list(rule_processor.automata_iter())): |
| 71 (nfa, dfa) = (automata.nfa(), automata.dfa()) | 71 (nfa, dfa) = (automata.nfa(), automata.dfa()) |
| 72 (nfa_i, dfa_i) = ("nfa_%d" % i, "dfa_%d" % i) | 72 mdfa = None if name == 'default' else automata.minimal_dfa() |
| 73 (nfa_i, dfa_i, mdfa_i) = ("nfa_%d" % i, "dfa_%d" % i, "mdfa_%d" % i) |
| 73 scripts.append(script_template % (nfa_i, nfa.to_dot())) | 74 scripts.append(script_template % (nfa_i, nfa.to_dot())) |
| 75 loads.append(load_template % ("nfa [%s]" % name, nfa_i)) |
| 74 scripts.append(script_template % (dfa_i, dfa.to_dot())) | 76 scripts.append(script_template % (dfa_i, dfa.to_dot())) |
| 75 loads.append(load_template % ("nfa [%s]" % name, nfa_i)) | |
| 76 loads.append(load_template % ("dfa [%s]" % name, dfa_i)) | 77 loads.append(load_template % ("dfa [%s]" % name, dfa_i)) |
| 78 if mdfa and mdfa != dfa: |
| 79 scripts.append(script_template % (mdfa_i, mdfa.to_dot())) |
| 80 loads.append(load_template % ("mdfa [%s]" % name, mdfa_i)) |
| 77 body = "\n".join(scripts) + (load_outer_template % "\n".join(loads)) | 81 body = "\n".join(scripts) + (load_outer_template % "\n".join(loads)) |
| 78 return file_template % body | 82 return file_template % body |
| 79 | 83 |
| 80 def generate_code(rule_processor): | 84 def generate_code(rule_processor): |
| 81 return CodeGenerator.rule_processor_to_code(rule_processor) | 85 return CodeGenerator.rule_processor_to_code(rule_processor) |
| 82 | 86 |
| 83 def lex(rule_processor, string): | 87 def lex(rule_processor, string): |
| 84 for t in rule_processor.lex(string + '\0'): | 88 for t in rule_processor.lex(string + '\0'): |
| 85 print t | 89 print t |
| 86 | 90 |
| (...skipping 22 matching lines...) Expand all Loading... |
| 109 if code_file: | 113 if code_file: |
| 110 code = generate_code(rule_processor) | 114 code = generate_code(rule_processor) |
| 111 with open(code_file, 'w') as f: | 115 with open(code_file, 'w') as f: |
| 112 f.write(code) | 116 f.write(code) |
| 113 print "wrote code to %s" % code_file | 117 print "wrote code to %s" % code_file |
| 114 | 118 |
| 115 input_file = args.input | 119 input_file = args.input |
| 116 if input_file: | 120 if input_file: |
| 117 with open(input_file, 'r') as f: | 121 with open(input_file, 'r') as f: |
| 118 lex(rule_processor, f.read()) | 122 lex(rule_processor, f.read()) |
| OLD | NEW |