| 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 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 159 | 159 |
| 160 def matches_char(self, char): | 160 def matches_char(self, char): |
| 161 char = ord(char) | 161 char = ord(char) |
| 162 # TODO class checks | 162 # TODO class checks |
| 163 for r in self.__ranges: | 163 for r in self.__ranges: |
| 164 if r[0] <= char and char <= r[1]: return True | 164 if r[0] <= char and char <= r[1]: return True |
| 165 return False | 165 return False |
| 166 | 166 |
| 167 def matches_key(self, key): | 167 def matches_key(self, key): |
| 168 assert isinstance(key, self.__class__) | 168 assert isinstance(key, self.__class__) |
| 169 assert key != TransitionKey.epsilon() | 169 assert key != TransitionKey.epsilon() and not key.__is_unique() |
| 170 assert len(key.__ranges) == 1 | 170 assert len(key.__ranges) == 1 |
| 171 subkey = key.__ranges[0] | 171 subkey = key.__ranges[0] |
| 172 matches = False |
| 172 for k in self.__ranges: | 173 for k in self.__ranges: |
| 173 if k[0] <= subkey[0] and k[1] >= subkey[1]: return True | 174 if k[0] <= subkey[0]: |
| 174 # TODO assert disjoint | 175 assert subkey[1] <= k[1] or subkey[0] > k[1] |
| 175 return False | 176 if subkey[0] < k[0]: |
| 177 assert subkey[1] < k[0] |
| 178 if k[0] <= subkey[0] and k[1] >= subkey[1]: |
| 179 assert not matches |
| 180 matches = True |
| 181 return matches |
| 176 | 182 |
| 177 def __hash__(self): | 183 def __hash__(self): |
| 178 if self.__cached_hash == None: | 184 if self.__cached_hash == None: |
| 179 initial_hash = hash((-1, TransitionKey.__upper_bound + 1)) | 185 initial_hash = hash((-1, TransitionKey.__upper_bound + 1)) |
| 180 f = lambda acc, r: acc ^ hash(r) | 186 f = lambda acc, r: acc ^ hash(r) |
| 181 self.__cached_hash = reduce(f, self.__ranges, initial_hash) | 187 self.__cached_hash = reduce(f, self.__ranges, initial_hash) |
| 182 return self.__cached_hash | 188 return self.__cached_hash |
| 183 | 189 |
| 184 def __eq__(self, other): | 190 def __eq__(self, other): |
| 185 return isinstance(other, self.__class__) and self.__ranges == other.__ranges | 191 return isinstance(other, self.__class__) and self.__ranges == other.__ranges |
| (...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 332 elif last[1] + 1 < r[0]: | 338 elif last[1] + 1 < r[0]: |
| 333 inverted.append((last[1] + 1, r[0] - 1)) | 339 inverted.append((last[1] + 1, r[0] - 1)) |
| 334 last = r | 340 last = r |
| 335 upper_bound = latin_1[1] | 341 upper_bound = latin_1[1] |
| 336 if last == None: | 342 if last == None: |
| 337 inverted.append(latin_1) | 343 inverted.append(latin_1) |
| 338 elif last[1] < upper_bound: | 344 elif last[1] < upper_bound: |
| 339 inverted.append((last[1] + 1, upper_bound)) | 345 inverted.append((last[1] + 1, upper_bound)) |
| 340 inverted += list(classes) | 346 inverted += list(classes) |
| 341 return inverted | 347 return inverted |
| OLD | NEW |