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

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

Issue 78713002: Experimental lexer generator: generate code for utf-16 character classes. (Closed) Base URL: https://v8.googlecode.com/svn/branches/experimental/parser
Patch Set: Code review (dcarney) 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/transition_key_test.py ('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 23 matching lines...) Expand all
34 (e.g., "whitespace"), defining for which characters the transition 34 (e.g., "whitespace"), defining for which characters the transition
35 happens. When we generate code based on the transition key, the character 35 happens. When we generate code based on the transition key, the character
36 ranges generate simple checks and the class ranges generate more complicated 36 ranges generate simple checks and the class ranges generate more complicated
37 conditions, e.g., function calls.''' 37 conditions, e.g., function calls.'''
38 38
39 __class_bounds = { 39 __class_bounds = {
40 'latin_1' : (1, 255), 40 'latin_1' : (1, 255),
41 # These are not real ranges; they just need to be separate from any real 41 # These are not real ranges; they just need to be separate from any real
42 # ranges. 42 # ranges.
43 'whitespace' : (256, 256), 43 'whitespace' : (256, 256),
44 'literal' : (257, 257), 44 'letter' : (257, 257),
45 'eos' : (258, 258), 45 'identifier_part_not_letter' : (258, 258),
46 'zero' : (259, 259), 46 'eos' : (259, 259),
47 'zero' : (260, 260),
47 } 48 }
48 __lower_bound = 1 49 __lower_bound = 1
49 __upper_bound = max(__class_bounds.values(), key=lambda item: item[1])[1] 50 __upper_bound = max(__class_bounds.values(), key=lambda item: item[1])[1]
50 51
51 __cached_keys = {} 52 __cached_keys = {}
52 53
53 __unique_key_counter = -1 54 __unique_key_counter = -1
54 55
55 @staticmethod 56 @staticmethod
56 def __in_latin_1(char): 57 def __in_latin_1(char):
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
132 key = graph[0] 133 key = graph[0]
133 if key == 'RANGE': 134 if key == 'RANGE':
134 ranges.append((ord(graph[1]), ord(graph[2]))) 135 ranges.append((ord(graph[1]), ord(graph[2])))
135 elif key == 'LITERAL': 136 elif key == 'LITERAL':
136 ranges.append((ord(graph[1]), ord(graph[1]))) 137 ranges.append((ord(graph[1]), ord(graph[1])))
137 elif key == 'CAT': 138 elif key == 'CAT':
138 for x in [graph[1], graph[2]]: 139 for x in [graph[1], graph[2]]:
139 TransitionKey.__process_graph(x, ranges, key_map) 140 TransitionKey.__process_graph(x, ranges, key_map)
140 elif key == 'CHARACTER_CLASS': 141 elif key == 'CHARACTER_CLASS':
141 class_name = graph[1] 142 class_name = graph[1]
142 if class_name == 'ws': 143 if class_name in TransitionKey.__class_bounds.keys():
143 ranges.append(TransitionKey.__class_bounds['whitespace']) 144 ranges.append(TransitionKey.__class_bounds[class_name])
144 elif class_name == 'lit':
145 ranges.append(TransitionKey.__class_bounds['literal'])
146 elif class_name == 'eos':
147 ranges.append(TransitionKey.__class_bounds['eos'])
148 elif class_name == 'zero':
149 ranges.append(TransitionKey.__class_bounds['zero'])
150 elif class_name in key_map: 145 elif class_name in key_map:
151 ranges += key_map[class_name].__ranges 146 ranges += key_map[class_name].__ranges
152 else: 147 else:
153 raise Exception('unknown character class [%s]' % graph[1]) 148 raise Exception('unknown character class [%s]' % graph[1])
154 else: 149 else:
155 raise Exception('bad key [%s]' % key) 150 raise Exception('bad key [%s]' % key)
156 151
157 @staticmethod 152 @staticmethod
158 def character_class(graph, key_map): 153 def character_class(graph, key_map):
159 '''Processes 'graph' (a representation of a character class in the rule 154 '''Processes 'graph' (a representation of a character class in the rule
(...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after
394 elif last[1] + 1 < r[0]: 389 elif last[1] + 1 < r[0]:
395 inverted.append((last[1] + 1, r[0] - 1)) 390 inverted.append((last[1] + 1, r[0] - 1))
396 last = r 391 last = r
397 upper_bound = latin_1[1] 392 upper_bound = latin_1[1]
398 if last == None: 393 if last == None:
399 inverted.append(latin_1) 394 inverted.append(latin_1)
400 elif last[1] < upper_bound: 395 elif last[1] < upper_bound:
401 inverted.append((last[1] + 1, upper_bound)) 396 inverted.append((last[1] + 1, upper_bound))
402 inverted += list(classes) 397 inverted += list(classes)
403 return inverted 398 return inverted
OLDNEW
« no previous file with comments | « tools/lexer_generator/transition_key_test.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698