Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(66)

Side by Side Diff: tools/lexer_generator/transition_keys.py

Issue 64023004: Experimental lexer generator: Misc fixes. (Closed) Base URL: https://v8.googlecode.com/svn/branches/experimental/parser
Patch Set: Created 7 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « tools/lexer_generator/code_generator.jinja ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 12 matching lines...) Expand all
23 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
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" : (1, 255),
34 # These are not "real" ranges; they just need to be separate. 34 # These are not "real" ranges; they just need to be separate.
35 "whitespace" : (256, 256), 35 "whitespace" : (256, 256),
36 "literal" : (257, 257), 36 "literal" : (257, 257),
37 "eof" : (258, 258), 37 "eos" : (258, 258),
38 "zero" : (259, 259),
38 } 39 }
39 __lower_bound = 0 40 __lower_bound = 1
40 __upper_bound = reduce(lambda acc, (k, v): max(acc, v[1]), __class_bounds.item s(), 0) 41 __upper_bound = reduce(lambda acc, (k, v): max(acc, v[1]), __class_bounds.item s(), 0)
41 42
42 __cached_keys = {} 43 __cached_keys = {}
43 44
44 __unique_key_counter = -1 45 __unique_key_counter = -1
45 46
46 @staticmethod 47 @staticmethod
47 def __in_latin_1(char): 48 def __in_latin_1(char):
48 bound = TransitionKey.__class_bounds["latin_1"] 49 bound = TransitionKey.__class_bounds["latin_1"]
49 return (bound[0] <= char and char <= bound[1]) 50 return (bound[0] <= char and char <= bound[1])
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
128 if key == 'RANGE': 129 if key == 'RANGE':
129 ranges.append((ord(graph[1]), ord(graph[2]))) 130 ranges.append((ord(graph[1]), ord(graph[2])))
130 elif key == 'LITERAL': 131 elif key == 'LITERAL':
131 ranges.append((ord(graph[1]), ord(graph[1]))) 132 ranges.append((ord(graph[1]), ord(graph[1])))
132 elif key == 'CAT': 133 elif key == 'CAT':
133 for x in [graph[1], graph[2]]: 134 for x in [graph[1], graph[2]]:
134 TransitionKey.__process_graph(x, ranges, key_map) 135 TransitionKey.__process_graph(x, ranges, key_map)
135 elif key == 'CHARACTER_CLASS': 136 elif key == 'CHARACTER_CLASS':
136 class_name = graph[1] 137 class_name = graph[1]
137 if class_name == 'ws': 138 if class_name == 'ws':
138 ranges.append(TransitionKey.__class_bounds["whitespace"]) 139 ranges.append(TransitionKey.__class_bounds['whitespace'])
139 elif class_name == 'lit': 140 elif class_name == 'lit':
140 ranges.append(TransitionKey.__class_bounds["literal"]) 141 ranges.append(TransitionKey.__class_bounds['literal'])
141 elif class_name == 'eof': 142 elif class_name == 'eos':
142 ranges.append(TransitionKey.__class_bounds["eof"]) 143 ranges.append(TransitionKey.__class_bounds['eos'])
144 elif class_name == 'zero':
145 ranges.append(TransitionKey.__class_bounds['zero'])
143 elif class_name in key_map: 146 elif class_name in key_map:
144 ranges += key_map[class_name].__ranges 147 ranges += key_map[class_name].__ranges
145 else: 148 else:
146 raise Exception("unknown character class [%s]" % graph[1]) 149 raise Exception("unknown character class [%s]" % graph[1])
147 else: 150 else:
148 raise Exception("bad key [%s]" % key) 151 raise Exception("bad key [%s]" % key)
149 152
150 @staticmethod 153 @staticmethod
151 def character_class(graph, key_map): 154 def character_class(graph, key_map):
152 ranges = [] 155 ranges = []
(...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after
350 elif last[1] + 1 < r[0]: 353 elif last[1] + 1 < r[0]:
351 inverted.append((last[1] + 1, r[0] - 1)) 354 inverted.append((last[1] + 1, r[0] - 1))
352 last = r 355 last = r
353 upper_bound = latin_1[1] 356 upper_bound = latin_1[1]
354 if last == None: 357 if last == None:
355 inverted.append(latin_1) 358 inverted.append(latin_1)
356 elif last[1] < upper_bound: 359 elif last[1] < upper_bound:
357 inverted.append((last[1] + 1, upper_bound)) 360 inverted.append((last[1] + 1, upper_bound))
358 inverted += list(classes) 361 inverted += list(classes)
359 return inverted 362 return inverted
OLDNEW
« no previous file with comments | « tools/lexer_generator/code_generator.jinja ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698