| 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 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 174 def p_struct_body(self, p): | 174 def p_struct_body(self, p): |
| 175 """struct_body : field struct_body | 175 """struct_body : field struct_body |
| 176 | enum struct_body | 176 | enum struct_body |
| 177 | const struct_body | 177 | const struct_body |
| 178 | """ | 178 | """ |
| 179 if len(p) > 1: | 179 if len(p) > 1: |
| 180 p[0] = _ListFromConcat(p[1], p[2]) | 180 p[0] = _ListFromConcat(p[1], p[2]) |
| 181 | 181 |
| 182 def p_field(self, p): | 182 def p_field(self, p): |
| 183 """field : typename NAME ordinal default SEMI""" | 183 """field : typename NAME ordinal default SEMI""" |
| 184 p[0] = ('FIELD', p[1], p[2], p[3], p[4]) | 184 p[0] = ast.StructField(p[2], p[3], p[1], p[4]) |
| 185 | 185 |
| 186 def p_default(self, p): | 186 def p_default_1(self, p): |
| 187 """default : EQUALS constant | 187 """default : """ |
| 188 | """ | 188 p[0] = None |
| 189 if len(p) > 2: | 189 |
| 190 p[0] = p[2] | 190 def p_default_2(self, p): |
| 191 """default : EQUALS constant""" |
| 192 p[0] = p[2] |
| 191 | 193 |
| 192 def p_interface(self, p): | 194 def p_interface(self, p): |
| 193 """interface : attribute_section INTERFACE NAME LBRACE interface_body \ | 195 """interface : attribute_section INTERFACE NAME LBRACE interface_body \ |
| 194 RBRACE SEMI""" | 196 RBRACE SEMI""" |
| 195 p[0] = ('INTERFACE', p[3], p[1], p[5]) | 197 p[0] = ('INTERFACE', p[3], p[1], p[5]) |
| 196 | 198 |
| 197 def p_interface_body(self, p): | 199 def p_interface_body(self, p): |
| 198 """interface_body : method interface_body | 200 """interface_body : method interface_body |
| 199 | enum interface_body | 201 | enum interface_body |
| 200 | const interface_body | 202 | const interface_body |
| (...skipping 23 matching lines...) Expand all Loading... |
| 224 """nonempty_parameter_list : parameter""" | 226 """nonempty_parameter_list : parameter""" |
| 225 p[0] = ast.ParameterList(p[1]) | 227 p[0] = ast.ParameterList(p[1]) |
| 226 | 228 |
| 227 def p_nonempty_parameter_list_2(self, p): | 229 def p_nonempty_parameter_list_2(self, p): |
| 228 """nonempty_parameter_list : nonempty_parameter_list COMMA parameter""" | 230 """nonempty_parameter_list : nonempty_parameter_list COMMA parameter""" |
| 229 p[0] = p[1] | 231 p[0] = p[1] |
| 230 p[0].Append(p[3]) | 232 p[0].Append(p[3]) |
| 231 | 233 |
| 232 def p_parameter(self, p): | 234 def p_parameter(self, p): |
| 233 """parameter : typename NAME ordinal""" | 235 """parameter : typename NAME ordinal""" |
| 234 p[0] = ast.Parameter(p[1], p[2], p[3], | 236 p[0] = ast.Parameter(p[2], p[3], p[1], |
| 235 filename=self.filename, lineno=p.lineno(2)) | 237 filename=self.filename, lineno=p.lineno(2)) |
| 236 | 238 |
| 237 def p_typename(self, p): | 239 def p_typename(self, p): |
| 238 """typename : basictypename | 240 """typename : basictypename |
| 239 | array | 241 | array |
| 240 | fixed_array | 242 | fixed_array |
| 241 | interfacerequest""" | 243 | interfacerequest""" |
| 242 p[0] = p[1] | 244 p[0] = p[1] |
| 243 | 245 |
| 244 def p_basictypename(self, p): | 246 def p_basictypename(self, p): |
| (...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 375 | 377 |
| 376 def Parse(source, filename): | 378 def Parse(source, filename): |
| 377 lexer = Lexer(filename) | 379 lexer = Lexer(filename) |
| 378 parser = Parser(lexer, source, filename) | 380 parser = Parser(lexer, source, filename) |
| 379 | 381 |
| 380 lex.lex(object=lexer) | 382 lex.lex(object=lexer) |
| 381 yacc.yacc(module=parser, debug=0, write_tables=0) | 383 yacc.yacc(module=parser, debug=0, write_tables=0) |
| 382 | 384 |
| 383 tree = yacc.parse(source) | 385 tree = yacc.parse(source) |
| 384 return tree | 386 return tree |
| OLD | NEW |