| 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 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 72 return self.__precedence | 72 return self.__precedence |
| 73 | 73 |
| 74 def __nonzero__(self): | 74 def __nonzero__(self): |
| 75 'true <==> self == empty_action' | 75 'true <==> self == empty_action' |
| 76 return bool(self.__term) | 76 return bool(self.__term) |
| 77 | 77 |
| 78 def __eq__(self, other): | 78 def __eq__(self, other): |
| 79 return isinstance(other, self.__class__) and self.__term == other.__term | 79 return isinstance(other, self.__class__) and self.__term == other.__term |
| 80 | 80 |
| 81 def __str__(self): | 81 def __str__(self): |
| 82 return "action <%s>" % ('' if not self.__term else str(self.__term)) | 82 return str(self.__term) |
| 83 | 83 |
| 84 class AutomatonState(object): | 84 class AutomatonState(object): |
| 85 '''A base class for dfa and nfa states. Immutable''' | 85 '''A base class for dfa and nfa states. Immutable''' |
| 86 | 86 |
| 87 __node_number_counter = 0 | 87 __node_number_counter = 0 |
| 88 | 88 |
| 89 def __init__(self): | 89 def __init__(self): |
| 90 self.__node_number = AutomatonState.__node_number_counter | 90 self.__node_number = AutomatonState.__node_number_counter |
| 91 AutomatonState.__node_number_counter += 1 | 91 AutomatonState.__node_number_counter += 1 |
| 92 | 92 |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 201 last_position = pos | 201 last_position = pos |
| 202 # lex next token | 202 # lex next token |
| 203 valid_states = Automaton.__transition_states_for_char(self.start_set(), c) | 203 valid_states = Automaton.__transition_states_for_char(self.start_set(), c) |
| 204 assert valid_states | 204 assert valid_states |
| 205 valid_states = self.__omega_closure(self.epsilon_closure(valid_states)) | 205 valid_states = self.__omega_closure(self.epsilon_closure(valid_states)) |
| 206 action = self.dominant_action(valid_states) | 206 action = self.dominant_action(valid_states) |
| 207 if not action: | 207 if not action: |
| 208 assert default_action | 208 assert default_action |
| 209 action = default_action | 209 action = default_action |
| 210 yield (action, last_position, len(string)) | 210 yield (action, last_position, len(string)) |
| OLD | NEW |