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

Side by Side Diff: mojo/public/tools/bindings/pylib/mojom/parse/parser.py

Issue 365993006: Mojo: bindings generator: Add AST types for attributes and attribute lists. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebased Created 6 years, 5 months 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
OLDNEW
1 # Copyright 2014 The Chromium Authors. All rights reserved. 1 # Copyright 2014 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be 2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file. 3 # found in the LICENSE file.
4 4
5 """Generates a syntax tree from a Mojo IDL file.""" 5 """Generates a syntax tree from a Mojo IDL file."""
6 6
7 import imp 7 import imp
8 import os.path 8 import os.path
9 import sys 9 import sys
10 10
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
122 | enum 122 | enum
123 | const""" 123 | const"""
124 p[0] = p[1] 124 p[0] = p[1]
125 125
126 def p_attribute_section(self, p): 126 def p_attribute_section(self, p):
127 """attribute_section : LBRACKET attribute_list RBRACKET 127 """attribute_section : LBRACKET attribute_list RBRACKET
128 | """ 128 | """
129 if len(p) > 3: 129 if len(p) > 3:
130 p[0] = p[2] 130 p[0] = p[2]
131 131
132 def p_attribute_list(self, p): 132 def p_attribute_list_1(self, p):
133 """attribute_list : attribute 133 """attribute_list : """
134 | attribute COMMA attribute_list 134 p[0] = ast.AttributeList()
135 | """ 135
136 if len(p) == 2: 136 def p_attribute_list_2(self, p):
137 p[0] = _ListFromConcat(p[1]) 137 """attribute_list : nonempty_attribute_list"""
138 elif len(p) > 3: 138 p[0] = p[1]
139 p[0] = _ListFromConcat(p[1], p[3]) 139
140 def p_nonempty_attribute_list_1(self, p):
141 """nonempty_attribute_list : attribute"""
142 p[0] = ast.AttributeList(p[1])
143
144 def p_nonempty_attribute_list_2(self, p):
145 """nonempty_attribute_list : nonempty_attribute_list COMMA attribute"""
146 p[0] = p[1]
147 p[0].Append(p[3])
140 148
141 def p_attribute(self, p): 149 def p_attribute(self, p):
142 """attribute : NAME EQUALS evaled_literal 150 """attribute : NAME EQUALS evaled_literal
143 | NAME EQUALS NAME""" 151 | NAME EQUALS NAME"""
144 p[0] = ('ATTRIBUTE', p[1], p[3]) 152 p[0] = ast.Attribute(p[1], p[3], filename=self.filename, lineno=p.lineno(1))
145 153
146 def p_evaled_literal(self, p): 154 def p_evaled_literal(self, p):
147 """evaled_literal : literal""" 155 """evaled_literal : literal"""
148 # 'eval' the literal to strip the quotes. 156 # 'eval' the literal to strip the quotes.
149 p[0] = eval(p[1]) 157 p[0] = eval(p[1])
150 158
151 def p_struct(self, p): 159 def p_struct(self, p):
152 """struct : attribute_section STRUCT NAME LBRACE struct_body RBRACE SEMI""" 160 """struct : attribute_section STRUCT NAME LBRACE struct_body RBRACE SEMI"""
153 p[0] = ('STRUCT', p[3], p[1], p[5]) 161 p[0] = ('STRUCT', p[3], p[1], p[5])
154 162
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
206 p[0] = ast.ParameterList(p[1]) 214 p[0] = ast.ParameterList(p[1])
207 215
208 def p_nonempty_parameter_list_2(self, p): 216 def p_nonempty_parameter_list_2(self, p):
209 """nonempty_parameter_list : nonempty_parameter_list COMMA parameter""" 217 """nonempty_parameter_list : nonempty_parameter_list COMMA parameter"""
210 p[0] = p[1] 218 p[0] = p[1]
211 p[0].Append(p[3]) 219 p[0].Append(p[3])
212 220
213 def p_parameter(self, p): 221 def p_parameter(self, p):
214 """parameter : typename NAME ordinal""" 222 """parameter : typename NAME ordinal"""
215 p[0] = ast.Parameter(p[1], p[2], p[3], 223 p[0] = ast.Parameter(p[1], p[2], p[3],
216 filename=self.filename, lineno=p.lineno(1)) 224 filename=self.filename, lineno=p.lineno(2))
217 225
218 def p_typename(self, p): 226 def p_typename(self, p):
219 """typename : basictypename 227 """typename : basictypename
220 | array 228 | array
221 | fixed_array 229 | fixed_array
222 | interfacerequest""" 230 | interfacerequest"""
223 p[0] = p[1] 231 p[0] = p[1]
224 232
225 def p_basictypename(self, p): 233 def p_basictypename(self, p):
226 """basictypename : identifier 234 """basictypename : identifier
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
348 356
349 def Parse(source, filename): 357 def Parse(source, filename):
350 lexer = Lexer(filename) 358 lexer = Lexer(filename)
351 parser = Parser(lexer, source, filename) 359 parser = Parser(lexer, source, filename)
352 360
353 lex.lex(object=lexer) 361 lex.lex(object=lexer)
354 yacc.yacc(module=parser, debug=0, write_tables=0) 362 yacc.yacc(module=parser, debug=0, write_tables=0)
355 363
356 tree = yacc.parse(source) 364 tree = yacc.parse(source)
357 return tree 365 return tree
OLDNEW
« no previous file with comments | « mojo/public/tools/bindings/pylib/mojom/parse/ast.py ('k') | mojo/public/tools/bindings/pylib/mojom/parse/translate.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698