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

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

Issue 59903027: Experimental parser: more escaping (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_lexer.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 151 matching lines...) Expand 10 before | Expand all | Expand 10 after
162 162
163 def p_regex_string_literal(self, p): 163 def p_regex_string_literal(self, p):
164 'regex_string_literal : STRING' 164 'regex_string_literal : STRING'
165 string = p[1][1:-1] 165 string = p[1][1:-1]
166 escape_char = lambda string, char: string.replace(char, "\\" + char) 166 escape_char = lambda string, char: string.replace(char, "\\" + char)
167 string = reduce(escape_char, "+?*|.[](){}", string).replace("\\\"", "\"") 167 string = reduce(escape_char, "+?*|.[](){}", string).replace("\\\"", "\"")
168 p[0] = RegexParser.parse(string) 168 p[0] = RegexParser.parse(string)
169 169
170 def p_regex(self, p): 170 def p_regex(self, p):
171 'regex : REGEX' 171 'regex : REGEX'
172 p[0] = RegexParser.parse(p[1][1:-1]) 172 string = p[1][1:-1].replace("\\/", "/")
173 p[0] = RegexParser.parse(string)
173 174
174 def p_regex_class(self, p): 175 def p_regex_class(self, p):
175 'regex_class : CHARACTER_CLASS_REGEX' 176 'regex_class : CHARACTER_CLASS_REGEX'
176 p[0] = RegexParser.parse(p[1]) 177 p[0] = RegexParser.parse(p[1])
177 178
178 def p_regex_alias(self, p): 179 def p_regex_alias(self, p):
179 'regex_alias : IDENTIFIER' 180 'regex_alias : IDENTIFIER'
180 p[0] = self.__state.aliases[p[1]] 181 p[0] = self.__state.aliases[p[1]]
181 182
182 def p_modifier(self, p): 183 def p_modifier(self, p):
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
310 for k, v in parser_state.rules.items(): 311 for k, v in parser_state.rules.items():
311 if k == 'default': continue 312 if k == 'default': continue
312 process(k, v) 313 process(k, v)
313 process('default', parser_state.rules['default']) 314 process('default', parser_state.rules['default'])
314 # build the automata 315 # build the automata
315 for rule_name, graph in rule_map.items(): 316 for rule_name, graph in rule_map.items():
316 self.__automata[rule_name] = RuleProcessor.Automata(builder, graph) 317 self.__automata[rule_name] = RuleProcessor.Automata(builder, graph)
317 318
318 default_action = parser_state.rules['default']['default_action'] 319 default_action = parser_state.rules['default']['default_action']
319 self.default_action = Action(default_action[0], default_action[1]) if defaul t_action else None 320 self.default_action = Action(default_action[0], default_action[1]) if defaul t_action else None
OLDNEW
« no previous file with comments | « tools/lexer_generator/rule_lexer.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698