| 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 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 84 return TransitionKey.__cached_any | 84 return TransitionKey.__cached_any |
| 85 | 85 |
| 86 @staticmethod | 86 @staticmethod |
| 87 def single_char(char): | 87 def single_char(char): |
| 88 char = ord(char) | 88 char = ord(char) |
| 89 assert (TransitionKey.__lower_bound <= char and | 89 assert (TransitionKey.__lower_bound <= char and |
| 90 char <= TransitionKey.__latin_1_upper_bound) | 90 char <= TransitionKey.__latin_1_upper_bound) |
| 91 return TransitionKey.__create([(char, char)]) | 91 return TransitionKey.__create([(char, char)]) |
| 92 | 92 |
| 93 @staticmethod | 93 @staticmethod |
| 94 def __process_graph(graph, ranges): | 94 def __process_graph(graph, ranges, key_map): |
| 95 key = graph[0] | 95 key = graph[0] |
| 96 if key == 'RANGE': | 96 if key == 'RANGE': |
| 97 ranges.append((ord(graph[1]), ord(graph[2]))) | 97 ranges.append((ord(graph[1]), ord(graph[2]))) |
| 98 elif key == 'LITERAL': | 98 elif key == 'LITERAL': |
| 99 ranges.append((ord(graph[1]), ord(graph[1]))) | 99 ranges.append((ord(graph[1]), ord(graph[1]))) |
| 100 elif key == 'CAT': |
| 101 for x in [graph[1], graph[2]]: |
| 102 TransitionKey.__process_graph(x, ranges, key_map) |
| 100 elif key == 'CHARACTER_CLASS': | 103 elif key == 'CHARACTER_CLASS': |
| 101 if graph[1] == 'ws': | 104 class_name = graph[1] |
| 105 if class_name == 'ws': |
| 102 ranges.append(TransitionKey.__unicode_whitespace_bounds) | 106 ranges.append(TransitionKey.__unicode_whitespace_bounds) |
| 103 elif graph[1] == 'lit': | 107 elif class_name == 'lit': |
| 104 ranges.append(TransitionKey.__unicode_literal_bounds) | 108 ranges.append(TransitionKey.__unicode_literal_bounds) |
| 109 elif class_name in key_map: |
| 110 ranges += key_map[class_name].__ranges |
| 105 else: | 111 else: |
| 106 raise Exception("unknown character class [%s]" % graph[1]) | 112 raise Exception("unknown character class [%s]" % graph[1]) |
| 107 elif key == 'CAT': | |
| 108 for x in [graph[1], graph[2]]: | |
| 109 TransitionKey.__process_graph(x, ranges) | |
| 110 else: | 113 else: |
| 111 raise Exception("bad key [%s]" % key) | 114 raise Exception("bad key [%s]" % key) |
| 112 | 115 |
| 113 @staticmethod | 116 @staticmethod |
| 114 def character_class(invert, graph): | 117 def character_class(graph, key_map): |
| 115 ranges = [] | 118 ranges = [] |
| 116 TransitionKey.__process_graph(graph, ranges) | 119 assert graph[0] == 'CLASS' or graph[0] == 'NOT_CLASS' |
| 120 invert = graph[0] == 'NOT_CLASS' |
| 121 TransitionKey.__process_graph(graph[1], ranges, key_map) |
| 117 return TransitionKey.__key_from_ranges(invert, ranges) | 122 return TransitionKey.__key_from_ranges(invert, ranges) |
| 118 | 123 |
| 119 def matches_char(self, char): | 124 def matches_char(self, char): |
| 120 char = ord(char) | 125 char = ord(char) |
| 121 # TODO class checks | 126 # TODO class checks |
| 122 for r in self.__ranges: | 127 for r in self.__ranges: |
| 123 if r[0] <= char and char <= r[1]: return True | 128 if r[0] <= char and char <= r[1]: return True |
| 124 return False | 129 return False |
| 125 | 130 |
| 126 def matches_key(self, key): | 131 def matches_key(self, key): |
| (...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 263 elif last[1] + 1 < r[0]: | 268 elif last[1] + 1 < r[0]: |
| 264 inverted.append((last[1] + 1, r[0] - 1)) | 269 inverted.append((last[1] + 1, r[0] - 1)) |
| 265 last = r | 270 last = r |
| 266 if last != None and last[1] < TransitionKey.__latin_1_upper_bound: | 271 if last != None and last[1] < TransitionKey.__latin_1_upper_bound: |
| 267 inverted.append((last[1] + 1, TransitionKey.__latin_1_upper_bound)) | 272 inverted.append((last[1] + 1, TransitionKey.__latin_1_upper_bound)) |
| 268 if not contains_whitespace: | 273 if not contains_whitespace: |
| 269 inverted.append(TransitionKey.__unicode_whitespace_bounds) | 274 inverted.append(TransitionKey.__unicode_whitespace_bounds) |
| 270 if not contains_literal: | 275 if not contains_literal: |
| 271 inverted.append(TransitionKey.__unicode_literal_bounds) | 276 inverted.append(TransitionKey.__unicode_literal_bounds) |
| 272 return inverted | 277 return inverted |
| OLD | NEW |