| 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 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 143 return (start, [end]) | 143 return (start, [end]) |
| 144 | 144 |
| 145 def __continue(self, graph): | 145 def __continue(self, graph): |
| 146 (start, ends) = self.__process(graph[1]) | 146 (start, ends) = self.__process(graph[1]) |
| 147 state = self.__peek_state() | 147 state = self.__peek_state() |
| 148 if not state['start_node']: | 148 if not state['start_node']: |
| 149 state['start_node'] = self.__new_state() | 149 state['start_node'] = self.__new_state() |
| 150 self.__patch_ends(ends, state['start_node']) | 150 self.__patch_ends(ends, state['start_node']) |
| 151 return (start, []) | 151 return (start, []) |
| 152 | 152 |
| 153 def __catch_all(self, graph): | 153 def __unique_key(self, graph): |
| 154 return self.__key_state(TransitionKey.unique('catch_all')) | 154 return self.__key_state(TransitionKey.unique(graph[1])) |
| 155 | 155 |
| 156 def __join(self, graph): | 156 def __join(self, graph): |
| 157 (graph, name, subgraph) = graph[1:] | 157 (graph, name, subgraph) = graph[1:] |
| 158 subgraphs = self.__peek_state()['subgraphs'] | 158 subgraphs = self.__peek_state()['subgraphs'] |
| 159 if not name in subgraphs: | 159 if not name in subgraphs: |
| 160 subgraphs[name] = self.__nfa(subgraph) | 160 subgraphs[name] = self.__nfa(subgraph) |
| 161 (subgraph_start, subgraph_end, nodes_in_subgraph) = subgraphs[name] | 161 (subgraph_start, subgraph_end, nodes_in_subgraph) = subgraphs[name] |
| 162 (start, ends) = self.__process(graph) | 162 (start, ends) = self.__process(graph) |
| 163 self.__patch_ends(ends, subgraph_start) | 163 self.__patch_ends(ends, subgraph_start) |
| 164 if subgraph_end: | 164 if subgraph_end: |
| (...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 304 | 304 |
| 305 @staticmethod | 305 @staticmethod |
| 306 def add_action(graph, action): | 306 def add_action(graph, action): |
| 307 return ('ACTION', graph, action) | 307 return ('ACTION', graph, action) |
| 308 | 308 |
| 309 @staticmethod | 309 @staticmethod |
| 310 def add_continue(graph): | 310 def add_continue(graph): |
| 311 return ('CONTINUE', graph) | 311 return ('CONTINUE', graph) |
| 312 | 312 |
| 313 @staticmethod | 313 @staticmethod |
| 314 def catch_all(): | 314 def unique_key(name): |
| 315 return ('CATCH_ALL',) | 315 return ('UNIQUE_KEY', name) |
| 316 | 316 |
| 317 @staticmethod | 317 @staticmethod |
| 318 def join_subgraph(graph, name, subgraph): | 318 def join_subgraph(graph, name, subgraph): |
| 319 return ('JOIN', graph, name, subgraph) | 319 return ('JOIN', graph, name, subgraph) |
| 320 | 320 |
| 321 @staticmethod | 321 @staticmethod |
| 322 def or_graphs(graphs): | 322 def or_graphs(graphs): |
| 323 return reduce(lambda acc, g: ('OR', acc, g), graphs) | 323 return reduce(lambda acc, g: ('OR', acc, g), graphs) |
| 324 | 324 |
| 325 @staticmethod | 325 @staticmethod |
| 326 def cat_graphs(graphs): | 326 def cat_graphs(graphs): |
| 327 return reduce(lambda acc, g: ('CAT', acc, g), graphs) | 327 return reduce(lambda acc, g: ('CAT', acc, g), graphs) |
| 328 | 328 |
| 329 __modifer_map = { | 329 __modifer_map = { |
| 330 '+': 'ONE_OR_MORE', | 330 '+': 'ONE_OR_MORE', |
| 331 '?': 'ZERO_OR_ONE', | 331 '?': 'ZERO_OR_ONE', |
| 332 '*': 'ZERO_OR_MORE', | 332 '*': 'ZERO_OR_MORE', |
| 333 } | 333 } |
| 334 | 334 |
| 335 @staticmethod | 335 @staticmethod |
| 336 def apply_modifier(modifier, graph): | 336 def apply_modifier(modifier, graph): |
| 337 return (NfaBuilder.__modifer_map[modifier], graph) | 337 return (NfaBuilder.__modifer_map[modifier], graph) |
| OLD | NEW |