| 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 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 69 loads.append(load_template % ("dfa [%s]" % name, dfa_i)) | 69 loads.append(load_template % ("dfa [%s]" % name, dfa_i)) |
| 70 body = "\n".join(scripts) + (load_outer_template % "\n".join(loads)) | 70 body = "\n".join(scripts) + (load_outer_template % "\n".join(loads)) |
| 71 return file_template % body | 71 return file_template % body |
| 72 | 72 |
| 73 def process_rules(parser_state): | 73 def process_rules(parser_state): |
| 74 rule_map = {} | 74 rule_map = {} |
| 75 builder = NfaBuilder() | 75 builder = NfaBuilder() |
| 76 builder.set_character_classes(parser_state.character_classes) | 76 builder.set_character_classes(parser_state.character_classes) |
| 77 for k, v in parser_state.rules.items(): | 77 for k, v in parser_state.rules.items(): |
| 78 graphs = [] | 78 graphs = [] |
| 79 for (rule_type, graph, identifier, action) in v: | 79 for (graph, code, action) in v['regex']: |
| 80 # graphs.append(NfaBuilder.add_action(graph, (action, identifier))) | 80 # graphs.append(NfaBuilder.add_action(graph, (action, identifier))) |
| 81 graphs.append(graph) | 81 graphs.append(graph) |
| 82 rule_map[k] = builder.nfa(NfaBuilder.or_graphs(graphs)) | 82 rule_map[k] = builder.nfa(NfaBuilder.or_graphs(graphs)) |
| 83 html_data = [] | 83 html_data = [] |
| 84 for rule_name, nfa in rule_map.items(): | 84 for rule_name, nfa in rule_map.items(): |
| 85 (start, dfa_nodes) = nfa.compute_dfa() | 85 (start, dfa_nodes) = nfa.compute_dfa() |
| 86 dfa = Dfa(start, dfa_nodes) | 86 dfa = Dfa(start, dfa_nodes) |
| 87 html_data.append((rule_name, nfa, dfa)) | 87 html_data.append((rule_name, nfa, dfa)) |
| 88 print generate_html(html_data) | 88 print generate_html(html_data) |
| 89 | 89 |
| 90 def parse_file(file_name): | 90 def parse_file(file_name): |
| 91 parser_state = RuleParserState() | 91 parser_state = RuleParserState() |
| 92 with open(file_name, 'r') as f: | 92 with open(file_name, 'r') as f: |
| 93 RuleParser.parse(f.read(), parser_state) | 93 RuleParser.parse(f.read(), parser_state) |
| 94 process_rules(parser_state) | 94 process_rules(parser_state) |
| 95 | 95 |
| 96 if __name__ == '__main__': | 96 if __name__ == '__main__': |
| 97 parse_file('src/lexer/lexer_py.re') | 97 parse_file('src/lexer/lexer_py.re') |
| OLD | NEW |