| 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 381 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 392 if action: | 392 if action: |
| 393 actions.append(action) | 393 actions.append(action) |
| 394 | 394 |
| 395 # Pull in actions which can be taken with an epsilon transition from the | 395 # Pull in actions which can be taken with an epsilon transition from the |
| 396 # match state. | 396 # match state. |
| 397 e = TransitionKey.epsilon() | 397 e = TransitionKey.epsilon() |
| 398 if e in state.transitions(): | 398 if e in state.transitions(): |
| 399 for e_trans in state.transitions()[e]: | 399 for e_trans in state.transitions()[e]: |
| 400 if e_trans[1]: | 400 if e_trans[1]: |
| 401 actions.append(e_trans[1]) | 401 actions.append(e_trans[1]) |
| 402 for s in state.epsilon_closure(): |
| 403 if e in s.transitions(): |
| 404 for e_trans in s.transitions()[e]: |
| 405 if e_trans[1]: |
| 406 actions.append(e_trans[1]) |
| 402 | 407 |
| 403 assert len(match_states) == len(transitions) | 408 assert len(match_states) == len(transitions) |
| 404 | 409 |
| 405 actions.sort() | 410 actions.sort() |
| 406 action = actions[0] if actions else None | 411 action = actions[0] if actions else None |
| 407 transition_state = Nfa.__to_dfa(match_states, dfa_nodes, end_node) | 412 transition_state = Nfa.__to_dfa(match_states, dfa_nodes, end_node) |
| 408 dfa_nodes[name]['transitions'][key] = (transition_state, action) | 413 dfa_nodes[name]['transitions'][key] = (transition_state, action) |
| 409 return name | 414 return name |
| 410 | 415 |
| 411 def compute_dfa(self): | 416 def compute_dfa(self): |
| 412 self.__compute_epsilon_closures() | 417 self.__compute_epsilon_closures() |
| 413 dfa_nodes = {} | 418 dfa_nodes = {} |
| 414 start_name = self.__to_dfa(set([self.__start]), dfa_nodes, self.__end) | 419 start_name = self.__to_dfa(set([self.__start]), dfa_nodes, self.__end) |
| 415 return (start_name, dfa_nodes) | 420 return (start_name, dfa_nodes) |
| 416 | 421 |
| 417 def to_dot(self): | 422 def to_dot(self): |
| 418 iterator = lambda visitor, state: self.__visit_all_edges(visitor, state) | 423 iterator = lambda visitor, state: self.__visit_all_edges(visitor, state) |
| 419 return self.generate_dot(self.__start, set([self.__end]), iterator) | 424 return self.generate_dot(self.__start, set([self.__end]), iterator) |
| OLD | NEW |