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

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

Issue 2741943002: mojo bindings: Support enums with no values (Closed)
Patch Set: new test & template change Created 3 years, 9 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
« no previous file with comments | « mojo/public/tools/bindings/generators/cpp_templates/enum_macros.tmpl ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 328 matching lines...) Expand 10 before | Expand all | Expand 10 after
339 def p_ordinal_2(self, p): 339 def p_ordinal_2(self, p):
340 """ordinal : ORDINAL""" 340 """ordinal : ORDINAL"""
341 value = int(p[1][1:]) 341 value = int(p[1][1:])
342 if value > _MAX_ORDINAL_VALUE: 342 if value > _MAX_ORDINAL_VALUE:
343 raise ParseError(self.filename, "Ordinal value %d too large:" % value, 343 raise ParseError(self.filename, "Ordinal value %d too large:" % value,
344 lineno=p.lineno(1), 344 lineno=p.lineno(1),
345 snippet=self._GetSnippet(p.lineno(1))) 345 snippet=self._GetSnippet(p.lineno(1)))
346 p[0] = ast.Ordinal(value, filename=self.filename, lineno=p.lineno(1)) 346 p[0] = ast.Ordinal(value, filename=self.filename, lineno=p.lineno(1))
347 347
348 def p_enum_1(self, p): 348 def p_enum_1(self, p):
349 """enum : attribute_section ENUM NAME LBRACE nonempty_enum_value_list \ 349 """enum : attribute_section ENUM NAME LBRACE enum_value_list \
350 RBRACE SEMI 350 RBRACE SEMI
351 | attribute_section ENUM NAME LBRACE nonempty_enum_value_list \ 351 | attribute_section ENUM NAME LBRACE nonempty_enum_value_list \
352 COMMA RBRACE SEMI""" 352 COMMA RBRACE SEMI"""
353 p[0] = ast.Enum(p[3], p[1], p[5], filename=self.filename, 353 p[0] = ast.Enum(p[3], p[1], p[5], filename=self.filename,
354 lineno=p.lineno(2)) 354 lineno=p.lineno(2))
355 355
356 def p_enum_2(self, p): 356 def p_enum_2(self, p):
357 """enum : attribute_section ENUM NAME SEMI""" 357 """enum : attribute_section ENUM NAME SEMI"""
358 p[0] = ast.Enum(p[3], p[1], None, filename=self.filename, 358 p[0] = ast.Enum(p[3], p[1], None, filename=self.filename,
359 lineno=p.lineno(2)) 359 lineno=p.lineno(2))
360 360
361 def p_enum_value_list_1(self, p):
362 """enum_value_list : """
363 p[0] = ast.EnumValueList()
364
365 def p_enum_value_list_2(self, p):
366 """enum_value_list : nonempty_enum_value_list"""
367 p[0] = p[1]
368
361 def p_nonempty_enum_value_list_1(self, p): 369 def p_nonempty_enum_value_list_1(self, p):
362 """nonempty_enum_value_list : enum_value""" 370 """nonempty_enum_value_list : enum_value"""
363 p[0] = ast.EnumValueList(p[1]) 371 p[0] = ast.EnumValueList(p[1])
364 372
365 def p_nonempty_enum_value_list_2(self, p): 373 def p_nonempty_enum_value_list_2(self, p):
366 """nonempty_enum_value_list : nonempty_enum_value_list COMMA enum_value""" 374 """nonempty_enum_value_list : nonempty_enum_value_list COMMA enum_value"""
367 p[0] = p[1] 375 p[0] = p[1]
368 p[0].Append(p[3]) 376 p[0].Append(p[3])
369 377
370 def p_enum_value(self, p): 378 def p_enum_value(self, p):
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
444 The AST as a mojom.parse.ast.Mojom object. 452 The AST as a mojom.parse.ast.Mojom object.
445 """ 453 """
446 lexer = Lexer(filename) 454 lexer = Lexer(filename)
447 parser = Parser(lexer, source, filename) 455 parser = Parser(lexer, source, filename)
448 456
449 lex.lex(object=lexer) 457 lex.lex(object=lexer)
450 yacc.yacc(module=parser, debug=0, write_tables=0) 458 yacc.yacc(module=parser, debug=0, write_tables=0)
451 459
452 tree = yacc.parse(source) 460 tree = yacc.parse(source)
453 return tree 461 return tree
OLDNEW
« no previous file with comments | « mojo/public/tools/bindings/generators/cpp_templates/enum_macros.tmpl ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698