| 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 13 matching lines...) Expand all Loading... |
| 24 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 24 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 25 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 25 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 26 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 26 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 27 | 27 |
| 28 from string import printable | 28 from string import printable |
| 29 | 29 |
| 30 class TransitionKey: | 30 class TransitionKey: |
| 31 | 31 |
| 32 __class_bounds = { | 32 __class_bounds = { |
| 33 "latin_1" : (0, 255), | 33 "latin_1" : (0, 255), |
| 34 # These are not "real" ranges; they just need to be separate. |
| 34 "whitespace" : (256, 256), | 35 "whitespace" : (256, 256), |
| 35 "literal" : (257, 257), | 36 "literal" : (257, 257), |
| 37 "eof" : (258, 258), |
| 36 } | 38 } |
| 37 __lower_bound = 0 | 39 __lower_bound = 0 |
| 38 __upper_bound = reduce(lambda acc, (k, v): max(acc, v[1]), __class_bounds.item
s(), 0) | 40 __upper_bound = reduce(lambda acc, (k, v): max(acc, v[1]), __class_bounds.item
s(), 0) |
| 39 | 41 |
| 40 __cached_keys = {} | 42 __cached_keys = {} |
| 41 | 43 |
| 42 __unique_key_counter = -1 | 44 __unique_key_counter = -1 |
| 43 | 45 |
| 44 @staticmethod | 46 @staticmethod |
| 45 def __in_latin_1(char): | 47 def __in_latin_1(char): |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 129 ranges.append((ord(graph[1]), ord(graph[1]))) | 131 ranges.append((ord(graph[1]), ord(graph[1]))) |
| 130 elif key == 'CAT': | 132 elif key == 'CAT': |
| 131 for x in [graph[1], graph[2]]: | 133 for x in [graph[1], graph[2]]: |
| 132 TransitionKey.__process_graph(x, ranges, key_map) | 134 TransitionKey.__process_graph(x, ranges, key_map) |
| 133 elif key == 'CHARACTER_CLASS': | 135 elif key == 'CHARACTER_CLASS': |
| 134 class_name = graph[1] | 136 class_name = graph[1] |
| 135 if class_name == 'ws': | 137 if class_name == 'ws': |
| 136 ranges.append(TransitionKey.__class_bounds["whitespace"]) | 138 ranges.append(TransitionKey.__class_bounds["whitespace"]) |
| 137 elif class_name == 'lit': | 139 elif class_name == 'lit': |
| 138 ranges.append(TransitionKey.__class_bounds["literal"]) | 140 ranges.append(TransitionKey.__class_bounds["literal"]) |
| 141 elif class_name == 'eof': |
| 142 ranges.append(TransitionKey.__class_bounds["eof"]) |
| 139 elif class_name in key_map: | 143 elif class_name in key_map: |
| 140 ranges += key_map[class_name].__ranges | 144 ranges += key_map[class_name].__ranges |
| 141 else: | 145 else: |
| 142 raise Exception("unknown character class [%s]" % graph[1]) | 146 raise Exception("unknown character class [%s]" % graph[1]) |
| 143 else: | 147 else: |
| 144 raise Exception("bad key [%s]" % key) | 148 raise Exception("bad key [%s]" % key) |
| 145 | 149 |
| 146 @staticmethod | 150 @staticmethod |
| 147 def character_class(graph, key_map): | 151 def character_class(graph, key_map): |
| 148 ranges = [] | 152 ranges = [] |
| (...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 346 elif last[1] + 1 < r[0]: | 350 elif last[1] + 1 < r[0]: |
| 347 inverted.append((last[1] + 1, r[0] - 1)) | 351 inverted.append((last[1] + 1, r[0] - 1)) |
| 348 last = r | 352 last = r |
| 349 upper_bound = latin_1[1] | 353 upper_bound = latin_1[1] |
| 350 if last == None: | 354 if last == None: |
| 351 inverted.append(latin_1) | 355 inverted.append(latin_1) |
| 352 elif last[1] < upper_bound: | 356 elif last[1] < upper_bound: |
| 353 inverted.append((last[1] + 1, upper_bound)) | 357 inverted.append((last[1] + 1, upper_bound)) |
| 354 inverted += list(classes) | 358 inverted += list(classes) |
| 355 return inverted | 359 return inverted |
| OLD | NEW |