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 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
81 def p_import_list_1(self, p): | 81 def p_import_list_1(self, p): |
82 """import_list : """ | 82 """import_list : """ |
83 p[0] = ast.ImportList() | 83 p[0] = ast.ImportList() |
84 | 84 |
85 def p_import_list_2(self, p): | 85 def p_import_list_2(self, p): |
86 """import_list : import_list import""" | 86 """import_list : import_list import""" |
87 p[0] = p[1] | 87 p[0] = p[1] |
88 p[0].Append(p[2]) | 88 p[0].Append(p[2]) |
89 | 89 |
90 def p_import(self, p): | 90 def p_import(self, p): |
91 """import : IMPORT STRING_LITERAL""" | 91 """import : IMPORT STRING_LITERAL SEMI""" |
92 # 'eval' the literal to strip the quotes. | 92 # 'eval' the literal to strip the quotes. |
93 # TODO(vtl): This eval is dubious. We should unquote/unescape ourselves. | 93 # TODO(vtl): This eval is dubious. We should unquote/unescape ourselves. |
94 p[0] = ast.Import(eval(p[2])) | 94 p[0] = ast.Import(eval(p[2])) |
95 | 95 |
96 def p_module(self, p): | 96 def p_module(self, p): |
97 """module : attribute_section MODULE identifier_wrapped """ | 97 """module : attribute_section MODULE identifier_wrapped """ |
98 p[0] = ast.Module(p[3], p[1], filename=self.filename, lineno=p.lineno(2)) | 98 p[0] = ast.Module(p[3], p[1], filename=self.filename, lineno=p.lineno(2)) |
99 | 99 |
100 def p_definition_list(self, p): | 100 def p_definition_list(self, p): |
101 """definition_list : definition definition_list | 101 """definition_list : definition definition_list |
(...skipping 277 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
379 | 379 |
380 def Parse(source, filename): | 380 def Parse(source, filename): |
381 lexer = Lexer(filename) | 381 lexer = Lexer(filename) |
382 parser = Parser(lexer, source, filename) | 382 parser = Parser(lexer, source, filename) |
383 | 383 |
384 lex.lex(object=lexer) | 384 lex.lex(object=lexer) |
385 yacc.yacc(module=parser, debug=0, write_tables=0) | 385 yacc.yacc(module=parser, debug=0, write_tables=0) |
386 | 386 |
387 tree = yacc.parse(source) | 387 tree = yacc.parse(source) |
388 return tree | 388 return tree |
OLD | NEW |