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 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
190 """default : """ | 190 """default : """ |
191 p[0] = None | 191 p[0] = None |
192 | 192 |
193 def p_default_2(self, p): | 193 def p_default_2(self, p): |
194 """default : EQUALS constant""" | 194 """default : EQUALS constant""" |
195 p[0] = p[2] | 195 p[0] = p[2] |
196 | 196 |
197 def p_interface(self, p): | 197 def p_interface(self, p): |
198 """interface : attribute_section INTERFACE NAME LBRACE interface_body \ | 198 """interface : attribute_section INTERFACE NAME LBRACE interface_body \ |
199 RBRACE SEMI""" | 199 RBRACE SEMI""" |
200 p[0] = ('INTERFACE', p[3], p[1], p[5]) | 200 p[0] = ast.Interface(p[3], p[1], p[5]) |
201 | 201 |
202 def p_interface_body(self, p): | 202 def p_interface_body_1(self, p): |
203 """interface_body : method interface_body | 203 """interface_body : """ |
204 | enum interface_body | 204 p[0] = ast.InterfaceBody() |
205 | const interface_body | |
206 | """ | |
207 if len(p) > 1: | |
208 p[0] = _ListFromConcat(p[1], p[2]) | |
209 | 205 |
210 def p_response(self, p): | 206 def p_interface_body_2(self, p): |
211 """response : RESPONSE LPAREN parameter_list RPAREN | 207 """interface_body : interface_body const |
212 | """ | 208 | interface_body enum |
213 if len(p) > 3: | 209 | interface_body method""" |
214 p[0] = p[3] | 210 p[0] = p[1] |
| 211 p[0].Append(p[2]) |
| 212 |
| 213 def p_response_1(self, p): |
| 214 """response : """ |
| 215 p[0] = None |
| 216 |
| 217 def p_response_2(self, p): |
| 218 """response : RESPONSE LPAREN parameter_list RPAREN""" |
| 219 p[0] = p[3] |
215 | 220 |
216 def p_method(self, p): | 221 def p_method(self, p): |
217 """method : NAME ordinal LPAREN parameter_list RPAREN response SEMI""" | 222 """method : NAME ordinal LPAREN parameter_list RPAREN response SEMI""" |
218 p[0] = ('METHOD', p[1], p[4], p[2], p[6]) | 223 p[0] = ast.Method(p[1], p[2], p[4], p[6]) |
219 | 224 |
220 def p_parameter_list_1(self, p): | 225 def p_parameter_list_1(self, p): |
221 """parameter_list : """ | 226 """parameter_list : """ |
222 p[0] = ast.ParameterList() | 227 p[0] = ast.ParameterList() |
223 | 228 |
224 def p_parameter_list_2(self, p): | 229 def p_parameter_list_2(self, p): |
225 """parameter_list : nonempty_parameter_list""" | 230 """parameter_list : nonempty_parameter_list""" |
226 p[0] = p[1] | 231 p[0] = p[1] |
227 | 232 |
228 def p_nonempty_parameter_list_1(self, p): | 233 def p_nonempty_parameter_list_1(self, p): |
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
380 | 385 |
381 def Parse(source, filename): | 386 def Parse(source, filename): |
382 lexer = Lexer(filename) | 387 lexer = Lexer(filename) |
383 parser = Parser(lexer, source, filename) | 388 parser = Parser(lexer, source, filename) |
384 | 389 |
385 lex.lex(object=lexer) | 390 lex.lex(object=lexer) |
386 yacc.yacc(module=parser, debug=0, write_tables=0) | 391 yacc.yacc(module=parser, debug=0, write_tables=0) |
387 | 392 |
388 tree = yacc.parse(source) | 393 tree = yacc.parse(source) |
389 return tree | 394 return tree |
OLD | NEW |