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

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

Issue 611633002: mojom: Add associative arrays to the mojom language. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Moved test classes to their own shared file. Created 6 years, 2 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
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 219 matching lines...) Expand 10 before | Expand all | Expand 10 after
230 | nonnullable_typename""" 230 | nonnullable_typename"""
231 if len(p) == 2: 231 if len(p) == 2:
232 p[0] = p[1] 232 p[0] = p[1]
233 else: 233 else:
234 p[0] = p[1] + "?" 234 p[0] = p[1] + "?"
235 235
236 def p_nonnullable_typename(self, p): 236 def p_nonnullable_typename(self, p):
237 """nonnullable_typename : basictypename 237 """nonnullable_typename : basictypename
238 | array 238 | array
239 | fixed_array 239 | fixed_array
240 | associative_array
240 | interfacerequest""" 241 | interfacerequest"""
241 p[0] = p[1] 242 p[0] = p[1]
242 243
243 def p_basictypename(self, p): 244 def p_basictypename(self, p):
244 """basictypename : identifier 245 """basictypename : identifier
245 | handletype""" 246 | handletype"""
246 p[0] = p[1] 247 p[0] = p[1]
247 248
248 def p_handletype(self, p): 249 def p_handletype(self, p):
249 """handletype : HANDLE 250 """handletype : HANDLE
(...skipping 18 matching lines...) Expand all
268 269
269 def p_fixed_array(self, p): 270 def p_fixed_array(self, p):
270 """fixed_array : ARRAY LANGLE typename COMMA INT_CONST_DEC RANGLE""" 271 """fixed_array : ARRAY LANGLE typename COMMA INT_CONST_DEC RANGLE"""
271 value = int(p[5]) 272 value = int(p[5])
272 if value == 0 or value > _MAX_ARRAY_SIZE: 273 if value == 0 or value > _MAX_ARRAY_SIZE:
273 raise ParseError(self.filename, "Fixed array size %d invalid" % value, 274 raise ParseError(self.filename, "Fixed array size %d invalid" % value,
274 lineno=p.lineno(5), 275 lineno=p.lineno(5),
275 snippet=self._GetSnippet(p.lineno(5))) 276 snippet=self._GetSnippet(p.lineno(5)))
276 p[0] = p[3] + "[" + p[5] + "]" 277 p[0] = p[3] + "[" + p[5] + "]"
277 278
279 def p_associative_array(self, p):
280 """associative_array : MAP LANGLE identifier COMMA typename RANGLE"""
281 p[0] = p[5] + "{" + p[3] + "}"
282
278 def p_interfacerequest(self, p): 283 def p_interfacerequest(self, p):
279 """interfacerequest : identifier AMP""" 284 """interfacerequest : identifier AMP"""
280 p[0] = p[1] + "&" 285 p[0] = p[1] + "&"
281 286
282 def p_ordinal_1(self, p): 287 def p_ordinal_1(self, p):
283 """ordinal : """ 288 """ordinal : """
284 p[0] = None 289 p[0] = None
285 290
286 def p_ordinal_2(self, p): 291 def p_ordinal_2(self, p):
287 """ordinal : ORDINAL""" 292 """ordinal : ORDINAL"""
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
374 379
375 def Parse(source, filename): 380 def Parse(source, filename):
376 lexer = Lexer(filename) 381 lexer = Lexer(filename)
377 parser = Parser(lexer, source, filename) 382 parser = Parser(lexer, source, filename)
378 383
379 lex.lex(object=lexer) 384 lex.lex(object=lexer)
380 yacc.yacc(module=parser, debug=0, write_tables=0) 385 yacc.yacc(module=parser, debug=0, write_tables=0)
381 386
382 tree = yacc.parse(source) 387 tree = yacc.parse(source)
383 return tree 388 return tree
OLDNEW
« no previous file with comments | « mojo/public/tools/bindings/pylib/mojom/parse/lexer.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