| 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 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 89 def p_root(self, p): | 89 def p_root(self, p): |
| 90 """root : import root | 90 """root : import root |
| 91 | module | 91 | module |
| 92 | definition_list""" | 92 | definition_list""" |
| 93 if len(p) > 2: | 93 if len(p) > 2: |
| 94 p[0] = _ListFromConcat(p[1], p[2]) | 94 p[0] = _ListFromConcat(p[1], p[2]) |
| 95 else: | 95 else: |
| 96 # Generator expects a module. If one wasn't specified insert one with an | 96 # Generator expects a module. If one wasn't specified insert one with an |
| 97 # empty name. | 97 # empty name. |
| 98 if p[1][0] != 'MODULE': | 98 if p[1][0] != 'MODULE': |
| 99 p[0] = [('MODULE', '', None, p[1])] | 99 p[0] = [('MODULE', None, None, p[1])] |
| 100 else: | 100 else: |
| 101 p[0] = [p[1]] | 101 p[0] = [p[1]] |
| 102 | 102 |
| 103 def p_import(self, p): | 103 def p_import(self, p): |
| 104 """import : IMPORT STRING_LITERAL""" | 104 """import : IMPORT STRING_LITERAL""" |
| 105 # 'eval' the literal to strip the quotes. | 105 # 'eval' the literal to strip the quotes. |
| 106 p[0] = ('IMPORT', eval(p[2])) | 106 p[0] = ('IMPORT', eval(p[2])) |
| 107 | 107 |
| 108 def p_module(self, p): | 108 def p_module(self, p): |
| 109 """module : attribute_section MODULE identifier LBRACE definition_list \ | 109 """module : attribute_section MODULE identifier_wrapped LBRACE \ |
| 110 RBRACE""" | 110 definition_list RBRACE""" |
| 111 p[0] = ('MODULE', p[3], p[1], p[5]) | 111 p[0] = ('MODULE', p[3], p[1], p[5]) |
| 112 | 112 |
| 113 def p_definition_list(self, p): | 113 def p_definition_list(self, p): |
| 114 """definition_list : definition definition_list | 114 """definition_list : definition definition_list |
| 115 | """ | 115 | """ |
| 116 if len(p) > 1: | 116 if len(p) > 1: |
| 117 p[0] = _ListFromConcat(p[1], p[2]) | 117 p[0] = _ListFromConcat(p[1], p[2]) |
| 118 | 118 |
| 119 def p_definition(self, p): | 119 def p_definition(self, p): |
| 120 """definition : struct | 120 """definition : struct |
| (...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 308 | 308 |
| 309 def p_constant(self, p): | 309 def p_constant(self, p): |
| 310 """constant : literal | 310 """constant : literal |
| 311 | identifier_wrapped""" | 311 | identifier_wrapped""" |
| 312 p[0] = p[1] | 312 p[0] = p[1] |
| 313 | 313 |
| 314 def p_identifier_wrapped(self, p): | 314 def p_identifier_wrapped(self, p): |
| 315 """identifier_wrapped : identifier""" | 315 """identifier_wrapped : identifier""" |
| 316 p[0] = ('IDENTIFIER', p[1]) | 316 p[0] = ('IDENTIFIER', p[1]) |
| 317 | 317 |
| 318 # TODO(vtl): Make this produce a "wrapped" identifier (probably as an |
| 319 # |ast.Identifier|, to be added) and get rid of identifier_wrapped. |
| 318 def p_identifier(self, p): | 320 def p_identifier(self, p): |
| 319 """identifier : NAME | 321 """identifier : NAME |
| 320 | NAME DOT identifier""" | 322 | NAME DOT identifier""" |
| 321 p[0] = ''.join(p[1:]) | 323 p[0] = ''.join(p[1:]) |
| 322 | 324 |
| 323 def p_literal(self, p): | 325 def p_literal(self, p): |
| 324 """literal : int | 326 """literal : int |
| 325 | float | 327 | float |
| 326 | TRUE | 328 | TRUE |
| 327 | FALSE | 329 | FALSE |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 361 | 363 |
| 362 def Parse(source, filename): | 364 def Parse(source, filename): |
| 363 lexer = Lexer(filename) | 365 lexer = Lexer(filename) |
| 364 parser = Parser(lexer, source, filename) | 366 parser = Parser(lexer, source, filename) |
| 365 | 367 |
| 366 lex.lex(object=lexer) | 368 lex.lex(object=lexer) |
| 367 yacc.yacc(module=parser, debug=0, write_tables=0) | 369 yacc.yacc(module=parser, debug=0, write_tables=0) |
| 368 | 370 |
| 369 tree = yacc.parse(source) | 371 tree = yacc.parse(source) |
| 370 return tree | 372 return tree |
| OLD | NEW |