| 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 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 98 self.__add_transition(TransitionKey.epsilon(), end) | 98 self.__add_transition(TransitionKey.epsilon(), end) |
| 99 | 99 |
| 100 def __matches(self, match_func, value): | 100 def __matches(self, match_func, value): |
| 101 f = lambda acc, (k, vs): acc | vs if match_func(k, value) else acc | 101 f = lambda acc, (k, vs): acc | vs if match_func(k, value) else acc |
| 102 return reduce(f, self.__transitions.items(), set()) | 102 return reduce(f, self.__transitions.items(), set()) |
| 103 | 103 |
| 104 def char_matches(self, value): | 104 def char_matches(self, value): |
| 105 return self.__matches(lambda k, v : k.matches_char(v), value) | 105 return self.__matches(lambda k, v : k.matches_char(v), value) |
| 106 | 106 |
| 107 def key_matches(self, value): | 107 def key_matches(self, value): |
| 108 return self.__matches(lambda k, v : k.matches_key(v), value) | 108 return self.__matches(lambda k, v : k.is_superset_of_key(v), value) |
| 109 | 109 |
| 110 class Nfa(Automaton): | 110 class Nfa(Automaton): |
| 111 | 111 |
| 112 def __init__(self, start, end, nodes_created): | 112 def __init__(self, start, end, nodes_created): |
| 113 super(Nfa, self).__init__() | 113 super(Nfa, self).__init__() |
| 114 self.__start = start | 114 self.__start = start |
| 115 self.__end = end | 115 self.__end = end |
| 116 self.__verify(nodes_created) | 116 self.__verify(nodes_created) |
| 117 | 117 |
| 118 def start_set(self): | 118 def start_set(self): |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 181 for state in reduce(f, nfa_state_set, set()): | 181 for state in reduce(f, nfa_state_set, set()): |
| 182 match_states.add(state) | 182 match_states.add(state) |
| 183 transition_state = Nfa.__to_dfa(match_states, dfa_nodes, end_node) | 183 transition_state = Nfa.__to_dfa(match_states, dfa_nodes, end_node) |
| 184 dfa_nodes[name]['transitions'][key] = transition_state | 184 dfa_nodes[name]['transitions'][key] = transition_state |
| 185 return name | 185 return name |
| 186 | 186 |
| 187 def compute_dfa(self): | 187 def compute_dfa(self): |
| 188 dfa_nodes = {} | 188 dfa_nodes = {} |
| 189 start_name = self.__to_dfa(set([self.__start]), dfa_nodes, self.__end) | 189 start_name = self.__to_dfa(set([self.__start]), dfa_nodes, self.__end) |
| 190 return (start_name, dfa_nodes) | 190 return (start_name, dfa_nodes) |
| OLD | NEW |