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

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: 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 | associated_array
viettrungluu 2014/09/29 19:34:47 "associated" -> "associative"
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 : typename LBRACKET INT_CONST_DEC RBRACKET""" 271 """fixed_array : typename LBRACKET INT_CONST_DEC RBRACKET"""
271 value = int(p[3]) 272 value = int(p[3])
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(3), 275 lineno=p.lineno(3),
275 snippet=self._GetSnippet(p.lineno(3))) 276 snippet=self._GetSnippet(p.lineno(3)))
276 p[0] = p[1] + "[" + p[3] + "]" 277 p[0] = p[1] + "[" + p[3] + "]"
277 278
279 def p_associated_array(self, p):
280 """associated_array : typename LBRACKET basictypename RBRACKET"""
viettrungluu 2014/09/29 19:34:47 a) It seems dubious/incorrect to allow "handletype
yzshen1 2014/09/29 19:53:24 About the "backward" issue, I am not sure whether
Elliot Glaysher 2014/10/02 19:54:03 Fixed by changing the grammar to look for "identif
281 p[0] = p[1] + "{" + 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

Powered by Google App Engine
This is Rietveld 408576698