| OLD | NEW |
| 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 316 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 327 | 327 |
| 328 def p_ordinal_2(self, p): | 328 def p_ordinal_2(self, p): |
| 329 """ordinal : ORDINAL""" | 329 """ordinal : ORDINAL""" |
| 330 value = int(p[1][1:]) | 330 value = int(p[1][1:]) |
| 331 if value > _MAX_ORDINAL_VALUE: | 331 if value > _MAX_ORDINAL_VALUE: |
| 332 raise ParseError(self.filename, "Ordinal value %d too large:" % value, | 332 raise ParseError(self.filename, "Ordinal value %d too large:" % value, |
| 333 lineno=p.lineno(1), | 333 lineno=p.lineno(1), |
| 334 snippet=self._GetSnippet(p.lineno(1))) | 334 snippet=self._GetSnippet(p.lineno(1))) |
| 335 p[0] = ast.Ordinal(value, filename=self.filename, lineno=p.lineno(1)) | 335 p[0] = ast.Ordinal(value, filename=self.filename, lineno=p.lineno(1)) |
| 336 | 336 |
| 337 def p_enum(self, p): | 337 def p_enum_1(self, p): |
| 338 """enum : attribute_section ENUM NAME LBRACE nonempty_enum_value_list \ | 338 """enum : attribute_section ENUM NAME LBRACE nonempty_enum_value_list \ |
| 339 RBRACE SEMI | 339 RBRACE SEMI |
| 340 | attribute_section ENUM NAME LBRACE nonempty_enum_value_list \ | 340 | attribute_section ENUM NAME LBRACE nonempty_enum_value_list \ |
| 341 COMMA RBRACE SEMI""" | 341 COMMA RBRACE SEMI""" |
| 342 p[0] = ast.Enum(p[3], p[1], p[5], filename=self.filename, | 342 p[0] = ast.Enum(p[3], p[1], p[5], filename=self.filename, |
| 343 lineno=p.lineno(2)) | 343 lineno=p.lineno(2)) |
| 344 | 344 |
| 345 def p_enum_2(self, p): |
| 346 """enum : attribute_section ENUM NAME SEMI""" |
| 347 p[0] = ast.Enum(p[3], p[1], None, filename=self.filename, |
| 348 lineno=p.lineno(2)) |
| 349 |
| 345 def p_nonempty_enum_value_list_1(self, p): | 350 def p_nonempty_enum_value_list_1(self, p): |
| 346 """nonempty_enum_value_list : enum_value""" | 351 """nonempty_enum_value_list : enum_value""" |
| 347 p[0] = ast.EnumValueList(p[1]) | 352 p[0] = ast.EnumValueList(p[1]) |
| 348 | 353 |
| 349 def p_nonempty_enum_value_list_2(self, p): | 354 def p_nonempty_enum_value_list_2(self, p): |
| 350 """nonempty_enum_value_list : nonempty_enum_value_list COMMA enum_value""" | 355 """nonempty_enum_value_list : nonempty_enum_value_list COMMA enum_value""" |
| 351 p[0] = p[1] | 356 p[0] = p[1] |
| 352 p[0].Append(p[3]) | 357 p[0].Append(p[3]) |
| 353 | 358 |
| 354 def p_enum_value(self, p): | 359 def p_enum_value(self, p): |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 419 | 424 |
| 420 def Parse(source, filename): | 425 def Parse(source, filename): |
| 421 lexer = Lexer(filename) | 426 lexer = Lexer(filename) |
| 422 parser = Parser(lexer, source, filename) | 427 parser = Parser(lexer, source, filename) |
| 423 | 428 |
| 424 lex.lex(object=lexer) | 429 lex.lex(object=lexer) |
| 425 yacc.yacc(module=parser, debug=0, write_tables=0) | 430 yacc.yacc(module=parser, debug=0, write_tables=0) |
| 426 | 431 |
| 427 tree = yacc.parse(source) | 432 tree = yacc.parse(source) |
| 428 return tree | 433 return tree |
| OLD | NEW |