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 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
148 def p_attribute(self, p): | 148 def p_attribute(self, p): |
149 """attribute : NAME EQUALS evaled_literal | 149 """attribute : NAME EQUALS evaled_literal |
150 | NAME EQUALS NAME""" | 150 | NAME EQUALS NAME""" |
151 p[0] = ast.Attribute(p[1], p[3], filename=self.filename, lineno=p.lineno(1)) | 151 p[0] = ast.Attribute(p[1], p[3], filename=self.filename, lineno=p.lineno(1)) |
152 | 152 |
153 def p_evaled_literal(self, p): | 153 def p_evaled_literal(self, p): |
154 """evaled_literal : literal""" | 154 """evaled_literal : literal""" |
155 # 'eval' the literal to strip the quotes. | 155 # 'eval' the literal to strip the quotes. |
156 p[0] = eval(p[1]) | 156 p[0] = eval(p[1]) |
157 | 157 |
158 def p_struct(self, p): | 158 def p_struct_1(self, p): |
159 """struct : attribute_section STRUCT NAME LBRACE struct_body RBRACE SEMI""" | 159 """struct : attribute_section STRUCT NAME LBRACE struct_body RBRACE SEMI""" |
160 p[0] = ast.Struct(p[3], p[1], p[5]) | 160 p[0] = ast.Struct(p[3], p[1], p[5]) |
161 | 161 |
| 162 def p_struct_2(self, p): |
| 163 """struct : attribute_section STRUCT NAME SEMI""" |
| 164 p[0] = ast.Struct(p[3], p[1], None) |
| 165 |
162 def p_struct_body_1(self, p): | 166 def p_struct_body_1(self, p): |
163 """struct_body : """ | 167 """struct_body : """ |
164 p[0] = ast.StructBody() | 168 p[0] = ast.StructBody() |
165 | 169 |
166 def p_struct_body_2(self, p): | 170 def p_struct_body_2(self, p): |
167 """struct_body : struct_body const | 171 """struct_body : struct_body const |
168 | struct_body enum | 172 | struct_body enum |
169 | struct_body struct_field""" | 173 | struct_body struct_field""" |
170 p[0] = p[1] | 174 p[0] = p[1] |
171 p[0].Append(p[2]) | 175 p[0].Append(p[2]) |
(...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
415 | 419 |
416 def Parse(source, filename): | 420 def Parse(source, filename): |
417 lexer = Lexer(filename) | 421 lexer = Lexer(filename) |
418 parser = Parser(lexer, source, filename) | 422 parser = Parser(lexer, source, filename) |
419 | 423 |
420 lex.lex(object=lexer) | 424 lex.lex(object=lexer) |
421 yacc.yacc(module=parser, debug=0, write_tables=0) | 425 yacc.yacc(module=parser, debug=0, write_tables=0) |
422 | 426 |
423 tree = yacc.parse(source) | 427 tree = yacc.parse(source) |
424 return tree | 428 return tree |
OLD | NEW |