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

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

Issue 59263003: Experimental lexer generator: parse \000 etc. inside char 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/regex_lexer.py ('k') | tools/lexer_generator/rule_parser.py » ('j') | 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 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
106 p[0] = ("NOT_CLASS", p[3]) 106 p[0] = ("NOT_CLASS", p[3])
107 107
108 def p_group(self, p): 108 def p_group(self, p):
109 '''group : GROUP_BEGIN start GROUP_END''' 109 '''group : GROUP_BEGIN start GROUP_END'''
110 p[0] = p[2] 110 p[0] = p[2]
111 111
112 def p_class_content(self, p): 112 def p_class_content(self, p):
113 '''class_content : CLASS_LITERAL RANGE CLASS_LITERAL maybe_class_content 113 '''class_content : CLASS_LITERAL RANGE CLASS_LITERAL maybe_class_content
114 | CLASS_LITERAL maybe_class_content 114 | CLASS_LITERAL maybe_class_content
115 | CHARACTER_CLASS maybe_class_content 115 | CHARACTER_CLASS maybe_class_content
116 | CLASS_LITERAL_AS_OCTAL maybe_class_content
116 ''' 117 '''
117 if len(p) == 5: 118 if len(p) == 5:
118 left = ("RANGE", p[1], p[3]) 119 left = ("RANGE", p[1], p[3])
119 else: 120 else:
120 if len(p[1]) == 1: 121 if len(p[1]) == 1:
121 left = ('LITERAL', p[1]) 122 left = ('LITERAL', p[1])
123 elif p[1][0] == '\\':
124 left = ('LITERAL', chr(int(p[1][1:], 8)))
122 else: 125 else:
123 left = ('CHARACTER_CLASS', p[1][1:-1]) 126 left = ('CHARACTER_CLASS', p[1][1:-1])
124 p[0] = self.__cat(left, p[len(p)-1]) 127 p[0] = self.__cat(left, p[len(p)-1])
125 128
126 def p_maybe_class_content(self, p): 129 def p_maybe_class_content(self, p):
127 '''maybe_class_content : class_content 130 '''maybe_class_content : class_content
128 | empty''' 131 | empty'''
129 p[0] = p[1] 132 p[0] = p[1]
130 133
131 def p_empty(self, p): 134 def p_empty(self, p):
(...skipping 11 matching lines...) Expand all
143 def build(self, **kwargs): 146 def build(self, **kwargs):
144 self.parser = yacc.yacc(module=self, debug=0, write_tables=0, **kwargs) 147 self.parser = yacc.yacc(module=self, debug=0, write_tables=0, **kwargs)
145 self.lexer = RegexLexer() 148 self.lexer = RegexLexer()
146 self.lexer.build(**kwargs) 149 self.lexer.build(**kwargs)
147 150
148 @staticmethod 151 @staticmethod
149 def parse(data): 152 def parse(data):
150 parser = RegexParser() 153 parser = RegexParser()
151 parser.build() 154 parser.build()
152 return parser.parser.parse(data, lexer=parser.lexer.lexer) 155 return parser.parser.parse(data, lexer=parser.lexer.lexer)
OLDNEW
« no previous file with comments | « tools/lexer_generator/regex_lexer.py ('k') | tools/lexer_generator/rule_parser.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698