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

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

Issue 59033005: Experimental parser: build regex parse trees for all rules (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/rule_parser.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 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
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': 100 elif key == 'CHARACTER_CLASS':
101 if graph[1] == 'ws': 101 if graph[1] == 'ws':
102 ranges.append(TransitionKey.__unicode_whitespace_bounds) 102 ranges.append(TransitionKey.__unicode_whitespace_bounds)
103 elif graph[1] == 'lit': 103 elif graph[1] == 'lit':
104 ranges.append(TransitionKey.__unicode_literal_bounds) 104 ranges.append(TransitionKey.__unicode_literal_bounds)
105 else: 105 else:
106 assert "unknown character class %s" % graph[1] 106 raise Exception("unknown character class [%s]" % graph[1])
107 elif key == 'CAT': 107 elif key == 'CAT':
108 for x in [graph[1], graph[2]]: 108 for x in [graph[1], graph[2]]:
109 TransitionKey.__process_graph(x, ranges) 109 TransitionKey.__process_graph(x, ranges)
110 else: 110 else:
111 assert False, "bad key %s" % key 111 raise Exception("bad key [%s]" % key)
112 112
113 @staticmethod 113 @staticmethod
114 def character_class(invert, graph): 114 def character_class(invert, graph):
115 ranges = [] 115 ranges = []
116 TransitionKey.__process_graph(graph, ranges) 116 TransitionKey.__process_graph(graph, ranges)
117 return TransitionKey.__key_from_ranges(invert, ranges) 117 return TransitionKey.__key_from_ranges(invert, ranges)
118 118
119 def matches_char(self, char): 119 def matches_char(self, char):
120 char = ord(char) 120 char = ord(char)
121 # TODO class checks 121 # TODO class checks
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after
262 elif last[1] + 1 < r[0]: 262 elif last[1] + 1 < r[0]:
263 inverted.append((last[1] + 1, r[0] - 1)) 263 inverted.append((last[1] + 1, r[0] - 1))
264 last = r 264 last = r
265 if last != None and last[1] < TransitionKey.__latin_1_upper_bound: 265 if last != None and last[1] < TransitionKey.__latin_1_upper_bound:
266 inverted.append((last[1] + 1, TransitionKey.__latin_1_upper_bound)) 266 inverted.append((last[1] + 1, TransitionKey.__latin_1_upper_bound))
267 if not contains_whitespace: 267 if not contains_whitespace:
268 inverted.append(TransitionKey.__unicode_whitespace_bounds) 268 inverted.append(TransitionKey.__unicode_whitespace_bounds)
269 if not contains_literal: 269 if not contains_literal:
270 inverted.append(TransitionKey.__unicode_literal_bounds) 270 inverted.append(TransitionKey.__unicode_literal_bounds)
271 return inverted 271 return inverted
OLDNEW
« no previous file with comments | « tools/lexer_generator/rule_parser.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698