| 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 227 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 238 @staticmethod | 238 @staticmethod |
| 239 def __close(states): | 239 def __close(states): |
| 240 f = lambda acc, node: acc | node.epsilon_closure() | 240 f = lambda acc, node: acc | node.epsilon_closure() |
| 241 return reduce(f, states, set(states)) | 241 return reduce(f, states, set(states)) |
| 242 | 242 |
| 243 def matches(self, string): | 243 def matches(self, string): |
| 244 self.__compute_epsilon_closures() | 244 self.__compute_epsilon_closures() |
| 245 valid_states = Nfa.__close(set([self.__start])) | 245 valid_states = Nfa.__close(set([self.__start])) |
| 246 for c in string: | 246 for c in string: |
| 247 f = lambda acc, state: acc | state.char_matches(c) | 247 f = lambda acc, state: acc | state.char_matches(c) |
| 248 valid_states = Nfa.__close(reduce(valid_states, f, set())) | 248 valid_states = Nfa.__close(reduce(f, valid_states, set())) |
| 249 if not valid_states: | 249 if not valid_states: |
| 250 return False | 250 return False |
| 251 return self.__end in valid_states | 251 return self.__end in valid_states |
| 252 | 252 |
| 253 @staticmethod | 253 @staticmethod |
| 254 def __to_dfa(nfa_state_set, builder): | 254 def __to_dfa(nfa_state_set, builder): |
| 255 nfa_state_set = Nfa.__close(nfa_state_set) | 255 nfa_state_set = Nfa.__close(nfa_state_set) |
| 256 name = str([x.node_number() for x in nfa_state_set]) | 256 name = str([x.node_number() for x in nfa_state_set]) |
| 257 (dfa_nodes, end_nodes, end_node) = builder | 257 (dfa_nodes, end_nodes, end_node) = builder |
| 258 if name in dfa_nodes: | 258 if name in dfa_nodes: |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 292 digraph finite_state_machine { | 292 digraph finite_state_machine { |
| 293 rankdir=LR; | 293 rankdir=LR; |
| 294 node [shape = circle, style=filled, bgcolor=lightgrey]; S_%s | 294 node [shape = circle, style=filled, bgcolor=lightgrey]; S_%s |
| 295 node [shape = doublecircle, style=unfilled]; S_%s | 295 node [shape = doublecircle, style=unfilled]; S_%s |
| 296 node [shape = circle]; | 296 node [shape = circle]; |
| 297 %s | 297 %s |
| 298 } | 298 } |
| 299 ''' % (self.__start.node_number(), | 299 ''' % (self.__start.node_number(), |
| 300 self.__end.node_number(), | 300 self.__end.node_number(), |
| 301 "\n".join(node_content)) | 301 "\n".join(node_content)) |
| OLD | NEW |