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 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
162 | NAME EQUALS NAME""" | 162 | NAME EQUALS NAME""" |
163 p[0] = ast.Attribute(p[1], p[3], filename=self.filename, lineno=p.lineno(1)) | 163 p[0] = ast.Attribute(p[1], p[3], filename=self.filename, lineno=p.lineno(1)) |
164 | 164 |
165 def p_evaled_literal(self, p): | 165 def p_evaled_literal(self, p): |
166 """evaled_literal : literal""" | 166 """evaled_literal : literal""" |
167 # 'eval' the literal to strip the quotes. | 167 # 'eval' the literal to strip the quotes. |
168 p[0] = eval(p[1]) | 168 p[0] = eval(p[1]) |
169 | 169 |
170 def p_struct(self, p): | 170 def p_struct(self, p): |
171 """struct : attribute_section STRUCT NAME LBRACE struct_body RBRACE SEMI""" | 171 """struct : attribute_section STRUCT NAME LBRACE struct_body RBRACE SEMI""" |
172 p[0] = ('STRUCT', p[3], p[1], p[5]) | 172 p[0] = ast.Struct(p[3], p[1], p[5]) |
173 | 173 |
174 def p_struct_body(self, p): | 174 def p_struct_body_1(self, p): |
175 """struct_body : field struct_body | 175 """struct_body : """ |
176 | enum struct_body | 176 p[0] = ast.StructBody() |
177 | const struct_body | |
178 | """ | |
179 if len(p) > 1: | |
180 p[0] = _ListFromConcat(p[1], p[2]) | |
181 | 177 |
182 def p_field(self, p): | 178 def p_struct_body_2(self, p): |
183 """field : typename NAME ordinal default SEMI""" | 179 """struct_body : struct_body const |
| 180 | struct_body enum |
| 181 | struct_body struct_field""" |
| 182 p[0] = p[1] |
| 183 p[0].Append(p[2]) |
| 184 |
| 185 def p_struct_field(self, p): |
| 186 """struct_field : typename NAME ordinal default SEMI""" |
184 p[0] = ast.StructField(p[2], p[3], p[1], p[4]) | 187 p[0] = ast.StructField(p[2], p[3], p[1], p[4]) |
185 | 188 |
186 def p_default_1(self, p): | 189 def p_default_1(self, p): |
187 """default : """ | 190 """default : """ |
188 p[0] = None | 191 p[0] = None |
189 | 192 |
190 def p_default_2(self, p): | 193 def p_default_2(self, p): |
191 """default : EQUALS constant""" | 194 """default : EQUALS constant""" |
192 p[0] = p[2] | 195 p[0] = p[2] |
193 | 196 |
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
377 | 380 |
378 def Parse(source, filename): | 381 def Parse(source, filename): |
379 lexer = Lexer(filename) | 382 lexer = Lexer(filename) |
380 parser = Parser(lexer, source, filename) | 383 parser = Parser(lexer, source, filename) |
381 | 384 |
382 lex.lex(object=lexer) | 385 lex.lex(object=lexer) |
383 yacc.yacc(module=parser, debug=0, write_tables=0) | 386 yacc.yacc(module=parser, debug=0, write_tables=0) |
384 | 387 |
385 tree = yacc.parse(source) | 388 tree = yacc.parse(source) |
386 return tree | 389 return tree |
OLD | NEW |