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

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

Issue 50293010: Experimental parser: parse character classes (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/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 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
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):
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 == 'CHARACTER_CLASS':
101 if graph[1] == 'ws':
102 ranges.append(TransitionKey.__unicode_whitespace_bounds)
103 elif graph[1] == 'lit':
104 ranges.append(TransitionKey.__unicode_literal_bounds)
105 else:
106 assert "unknown character class %s" % graph[1]
100 elif key == 'CAT': 107 elif key == 'CAT':
101 for x in [graph[1], graph[2]]: 108 for x in [graph[1], graph[2]]:
102 TransitionKey.__process_graph(x, ranges) 109 TransitionKey.__process_graph(x, ranges)
103 else: 110 else:
104 assert False, "bad key %s" % key 111 assert False, "bad key %s" % key
105 112
106 @staticmethod 113 @staticmethod
107 def character_class(invert, graph): 114 def character_class(invert, graph):
108 ranges = [] 115 ranges = []
109 TransitionKey.__process_graph(graph, ranges) 116 TransitionKey.__process_graph(graph, ranges)
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after
250 elif last[1] + 1 < r[0]: 257 elif last[1] + 1 < r[0]:
251 inverted.append((last[1] + 1, r[0] - 1)) 258 inverted.append((last[1] + 1, r[0] - 1))
252 last = r 259 last = r
253 if last != None and last[1] < TransitionKey.__latin_1_upper_bound: 260 if last != None and last[1] < TransitionKey.__latin_1_upper_bound:
254 inverted.append((last[1] + 1, TransitionKey.__latin_1_upper_bound)) 261 inverted.append((last[1] + 1, TransitionKey.__latin_1_upper_bound))
255 if not contains_whitespace: 262 if not contains_whitespace:
256 inverted.append(TransitionKey.__unicode_whitespace_bounds) 263 inverted.append(TransitionKey.__unicode_whitespace_bounds)
257 if not contains_literal: 264 if not contains_literal:
258 inverted.append(TransitionKey.__unicode_literal_bounds) 265 inverted.append(TransitionKey.__unicode_literal_bounds)
259 return inverted 266 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