| 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 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 54 | 54 |
| 55 def set_action(self, action): | 55 def set_action(self, action): |
| 56 assert not self.is_closed() | 56 assert not self.is_closed() |
| 57 assert not self.__action | 57 assert not self.__action |
| 58 self.__action = action | 58 self.__action = action |
| 59 | 59 |
| 60 def transitions(self): | 60 def transitions(self): |
| 61 assert self.is_closed() | 61 assert self.is_closed() |
| 62 return self.__transitions | 62 return self.__transitions |
| 63 | 63 |
| 64 def next_states(self, key_filter): | |
| 65 assert self.is_closed() | |
| 66 f = lambda acc, (k, v) : acc if not key_filter(k) else acc | set(v) | |
| 67 return reduce(f, self.__transitions.items(), set()) | |
| 68 | |
| 69 def __add_transition(self, key, next_state): | 64 def __add_transition(self, key, next_state): |
| 70 if next_state == None: | 65 if next_state == None: |
| 71 assert not self.is_closed(), "already closed" | 66 assert not self.is_closed(), "already closed" |
| 72 self.__unclosed.add(key) | 67 self.__unclosed.add(key) |
| 73 return | 68 return |
| 74 if not key in self.__transitions: | 69 if not key in self.__transitions: |
| 75 self.__transitions[key] = set() | 70 self.__transitions[key] = set() |
| 76 self.__transitions[key].add(next_state) | 71 self.__transitions[key].add(next_state) |
| 77 | 72 |
| 78 def add_unclosed_transition(self, key): | 73 def add_unclosed_transition(self, key): |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 152 f = lambda state: state.transition_state_iter_for_key(key) | 147 f = lambda state: state.transition_state_iter_for_key(key) |
| 153 match_states |= set(chain(*map(f, nfa_state_set))) | 148 match_states |= set(chain(*map(f, nfa_state_set))) |
| 154 transition_state = Nfa.__to_dfa(match_states, dfa_nodes, end_node) | 149 transition_state = Nfa.__to_dfa(match_states, dfa_nodes, end_node) |
| 155 dfa_nodes[name]['transitions'][key] = transition_state | 150 dfa_nodes[name]['transitions'][key] = transition_state |
| 156 return name | 151 return name |
| 157 | 152 |
| 158 def compute_dfa(self): | 153 def compute_dfa(self): |
| 159 dfa_nodes = {} | 154 dfa_nodes = {} |
| 160 start_name = self.__to_dfa(set([self.__start]), dfa_nodes, self.__end) | 155 start_name = self.__to_dfa(set([self.__start]), dfa_nodes, self.__end) |
| 161 return (start_name, dfa_nodes) | 156 return (start_name, dfa_nodes) |
| OLD | NEW |