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

Side by Side Diff: tools/lexer_generator/regex_parser.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/regex_lexer.py ('k') | tools/lexer_generator/transition_key_test.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 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
93 else: 93 else:
94 p[0] = ("NOT_CLASS", p[3]) 94 p[0] = ("NOT_CLASS", p[3])
95 95
96 def p_group(self, p): 96 def p_group(self, p):
97 '''group : GROUP_BEGIN start GROUP_END''' 97 '''group : GROUP_BEGIN start GROUP_END'''
98 p[0] = p[2] 98 p[0] = p[2]
99 99
100 def p_class_content(self, p): 100 def p_class_content(self, p):
101 '''class_content : CLASS_LITERAL RANGE CLASS_LITERAL maybe_class_content 101 '''class_content : CLASS_LITERAL RANGE CLASS_LITERAL maybe_class_content
102 | CLASS_LITERAL maybe_class_content 102 | CLASS_LITERAL maybe_class_content
103 | CHARACTER_CLASS maybe_class_content
103 ''' 104 '''
104 if len(p) == 5: 105 if len(p) == 5:
105 left = ("RANGE", p[1], p[3]) 106 left = ("RANGE", p[1], p[3])
106 else: 107 else:
107 left = ('LITERAL', p[1]) 108 if len(p[1]) == 1:
109 left = ('LITERAL', p[1])
110 else:
111 left = ('CHARACTER_CLASS', p[1:-1])
108 p[0] = self.__cat(left, p[len(p)-1]) 112 p[0] = self.__cat(left, p[len(p)-1])
109 113
110 def p_maybe_class_content(self, p): 114 def p_maybe_class_content(self, p):
111 '''maybe_class_content : class_content 115 '''maybe_class_content : class_content
112 | empty''' 116 | empty'''
113 p[0] = p[1] 117 p[0] = p[1]
114 118
115 def p_empty(self, p): 119 def p_empty(self, p):
116 'empty :' 120 'empty :'
117 121
118 def p_error(self, p): 122 def p_error(self, p):
119 raise Exception("Syntax error in input '%s'" % p) 123 raise Exception("Syntax error in input '%s'" % p)
120 124
121 @staticmethod 125 @staticmethod
122 def __cat(left, right): 126 def __cat(left, right):
123 if right == None: 127 if right == None:
124 return left 128 return left
125 return ('CAT', left, right) 129 return ('CAT', left, right)
126 130
127 def build(self, **kwargs): 131 def build(self, **kwargs):
128 self.parser = yacc.yacc(module=self, debug=0, write_tables=0, **kwargs) 132 self.parser = yacc.yacc(module=self, debug=0, write_tables=0, **kwargs)
129 self.lexer = RegexLexer() 133 self.lexer = RegexLexer()
130 self.lexer.build(**kwargs) 134 self.lexer.build(**kwargs)
131 135
132 @staticmethod 136 @staticmethod
133 def parse(data): 137 def parse(data):
134 parser = RegexParser() 138 parser = RegexParser()
135 parser.build() 139 parser.build()
136 return parser.parser.parse(data, lexer=parser.lexer.lexer) 140 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/transition_key_test.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698