| 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 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 154 else: | 154 else: |
| 155 raise Exception('bad key [%s]' % key) | 155 raise Exception('bad key [%s]' % key) |
| 156 | 156 |
| 157 @staticmethod | 157 @staticmethod |
| 158 def character_class(graph, key_map): | 158 def character_class(graph, key_map): |
| 159 '''Processes 'graph' (a representation of a character class in the rule | 159 '''Processes 'graph' (a representation of a character class in the rule |
| 160 file), and constructs a TransitionKey based on it. 'key_map' contains | 160 file), and constructs a TransitionKey based on it. 'key_map' contains |
| 161 already constructed aliases for character classes (they can be used in the | 161 already constructed aliases for character classes (they can be used in the |
| 162 new character class). It is a map from strings (character class names) to | 162 new character class). It is a map from strings (character class names) to |
| 163 TransitionKeys. For example, graph might represent the character class | 163 TransitionKeys. For example, graph might represent the character class |
| 164 [a-z:digit:] where 'digit' is a previously constructed characte class found | 164 [a-z:digit:] where 'digit' is a previously constructed character class found |
| 165 in "key_map".''' | 165 in "key_map".''' |
| 166 ranges = [] | 166 ranges = [] |
| 167 assert graph[0] == 'CLASS' or graph[0] == 'NOT_CLASS' | 167 assert graph[0] == 'CLASS' or graph[0] == 'NOT_CLASS' |
| 168 invert = graph[0] == 'NOT_CLASS' | 168 invert = graph[0] == 'NOT_CLASS' |
| 169 TransitionKey.__process_graph(graph[1], ranges, key_map) | 169 TransitionKey.__process_graph(graph[1], ranges, key_map) |
| 170 return TransitionKey.__key_from_ranges(invert, ranges) | 170 return TransitionKey.__key_from_ranges(invert, ranges) |
| 171 | 171 |
| 172 def matches_char(self, char): | 172 def matches_char(self, char): |
| 173 char = ord(char) | 173 char = ord(char) |
| 174 # TODO class checks | 174 # TODO class checks |
| (...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 309 range_map[r[0]] = [] | 309 range_map[r[0]] = [] |
| 310 range_map[r[0]].append(r[1]) | 310 range_map[r[0]].append(r[1]) |
| 311 ranges = TransitionKey.__disjoint_keys(range_map) | 311 ranges = TransitionKey.__disjoint_keys(range_map) |
| 312 TransitionKey.__verify_ranges(ranges, False) | 312 TransitionKey.__verify_ranges(ranges, False) |
| 313 return ranges | 313 return ranges |
| 314 | 314 |
| 315 @staticmethod | 315 @staticmethod |
| 316 def disjoint_keys(key_set): | 316 def disjoint_keys(key_set): |
| 317 '''Takes a set of possibly overlapping TransitionKeys, returns a list of | 317 '''Takes a set of possibly overlapping TransitionKeys, returns a list of |
| 318 TransitionKeys which don't overlap and whose union is the same as the union | 318 TransitionKeys which don't overlap and whose union is the same as the union |
| 319 of the original key_set. key_set is a set of TransitionKeys.''' | 319 of the original key_set. In addition, TransitionKeys are not merged, only |
| 320 split. |
| 321 |
| 322 For example, if key_set contains two TransitionKeys for ranges [1-10] and |
| 323 [5-15], disjoint_keys returns a set of three TransitionKeys: [1-4], [5-10], |
| 324 [11-16].''' |
| 320 ranges = TransitionKey.__disjoint_ranges_from_key_set(key_set) | 325 ranges = TransitionKey.__disjoint_ranges_from_key_set(key_set) |
| 321 return map(lambda x : TransitionKey([x]), ranges) | 326 return map(lambda x : TransitionKey([x]), ranges) |
| 322 | 327 |
| 323 @staticmethod | 328 @staticmethod |
| 324 def inverse_key(key_set): | 329 def inverse_key(key_set): |
| 325 '''Returns a TransitionKey which matches represents the inverse of the union | 330 '''Returns a TransitionKey which matches represents the inverse of the union |
| 326 of 'key_set'. The TransitionKeys contain a set of character ranges and a set | 331 of 'key_set'. The TransitionKeys contain a set of character ranges and a set |
| 327 of classes. The character ranges are inverted in relation to the latin_1 | 332 of classes. The character ranges are inverted in relation to the latin_1 |
| 328 character range, and the character classes are inverted in relation to all | 333 character range, and the character classes are inverted in relation to all |
| 329 character classes in __class_bounds.''' | 334 character classes in __class_bounds.''' |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 389 elif last[1] + 1 < r[0]: | 394 elif last[1] + 1 < r[0]: |
| 390 inverted.append((last[1] + 1, r[0] - 1)) | 395 inverted.append((last[1] + 1, r[0] - 1)) |
| 391 last = r | 396 last = r |
| 392 upper_bound = latin_1[1] | 397 upper_bound = latin_1[1] |
| 393 if last == None: | 398 if last == None: |
| 394 inverted.append(latin_1) | 399 inverted.append(latin_1) |
| 395 elif last[1] < upper_bound: | 400 elif last[1] < upper_bound: |
| 396 inverted.append((last[1] + 1, upper_bound)) | 401 inverted.append((last[1] + 1, upper_bound)) |
| 397 inverted += list(classes) | 402 inverted += list(classes) |
| 398 return inverted | 403 return inverted |
| OLD | NEW |