| OLD | NEW |
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
| 2 # Copyright 2013 The Chromium Authors. All rights reserved. | 2 # Copyright 2013 The Chromium Authors. All rights reserved. |
| 3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be |
| 4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
| 5 | 5 |
| 6 """Generates a syntax tree from a Mojo IDL file.""" | 6 """Generates a syntax tree from a Mojo IDL file.""" |
| 7 | 7 |
| 8 | 8 |
| 9 import sys | 9 import sys |
| 10 import os.path | 10 import os.path |
| (...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 177 p[0] = ListFromConcat(p[1]) | 177 p[0] = ListFromConcat(p[1]) |
| 178 elif len(p) > 3: | 178 elif len(p) > 3: |
| 179 p[0] = ListFromConcat(p[1], p[3]) | 179 p[0] = ListFromConcat(p[1], p[3]) |
| 180 | 180 |
| 181 def p_attribute(self, p): | 181 def p_attribute(self, p): |
| 182 """attribute : NAME EQUALS NUMBER | 182 """attribute : NAME EQUALS NUMBER |
| 183 | NAME EQUALS NAME""" | 183 | NAME EQUALS NAME""" |
| 184 p[0] = ('ATTRIBUTE', p[1], p[3]) | 184 p[0] = ('ATTRIBUTE', p[1], p[3]) |
| 185 | 185 |
| 186 def p_struct(self, p): | 186 def p_struct(self, p): |
| 187 """struct : attribute_section STRUCT NAME LCURLY fields RCURLY SEMICOLON""" | 187 """struct : attribute_section STRUCT NAME LCURLY struct_body RCURLY SEMICOLO
N""" |
| 188 p[0] = ('STRUCT', p[3], p[1], p[5]) | 188 p[0] = ('STRUCT', p[3], p[1], p[5]) |
| 189 | 189 |
| 190 def p_fields(self, p): | 190 def p_struct_body(self, p): |
| 191 """fields : field fields | 191 """struct_body : field struct_body |
| 192 |""" | 192 | enum struct_body |
| 193 |""" |
| 193 if len(p) > 1: | 194 if len(p) > 1: |
| 194 p[0] = ListFromConcat(p[1], p[2]) | 195 p[0] = ListFromConcat(p[1], p[2]) |
| 195 | 196 |
| 196 def p_field(self, p): | 197 def p_field(self, p): |
| 197 """field : typename NAME ordinal SEMICOLON""" | 198 """field : typename NAME ordinal SEMICOLON""" |
| 198 p[0] = ('FIELD', p[1], p[2], p[3]) | 199 p[0] = ('FIELD', p[1], p[2], p[3]) |
| 199 | 200 |
| 200 def p_interface(self, p): | 201 def p_interface(self, p): |
| 201 """interface : attribute_section INTERFACE NAME LCURLY methods RCURLY SEMICO
LON""" | 202 """interface : attribute_section INTERFACE NAME LCURLY interface_body RCURLY
SEMICOLON""" |
| 202 p[0] = ('INTERFACE', p[3], p[1], p[5]) | 203 p[0] = ('INTERFACE', p[3], p[1], p[5]) |
| 203 | 204 |
| 204 def p_methods(self, p): | 205 def p_interface_body(self, p): |
| 205 """methods : method methods | 206 """interface_body : method interface_body |
| 206 | """ | 207 | enum interface_body |
| 208 | """ |
| 207 if len(p) > 1: | 209 if len(p) > 1: |
| 208 p[0] = ListFromConcat(p[1], p[2]) | 210 p[0] = ListFromConcat(p[1], p[2]) |
| 209 | 211 |
| 210 def p_method(self, p): | 212 def p_method(self, p): |
| 211 """method : VOID NAME LPAREN parameters RPAREN ordinal SEMICOLON""" | 213 """method : VOID NAME LPAREN parameters RPAREN ordinal SEMICOLON""" |
| 212 p[0] = ('METHOD', p[2], p[4], p[6]) | 214 p[0] = ('METHOD', p[2], p[4], p[6]) |
| 213 | 215 |
| 214 def p_parameters(self, p): | 216 def p_parameters(self, p): |
| 215 """parameters : parameter | 217 """parameters : parameter |
| 216 | parameter COMMA parameters | 218 | parameter COMMA parameters |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 296 def Main(): | 298 def Main(): |
| 297 if len(sys.argv) < 2: | 299 if len(sys.argv) < 2: |
| 298 print("usage: %s filename" % (sys.argv[0])) | 300 print("usage: %s filename" % (sys.argv[0])) |
| 299 sys.exit(1) | 301 sys.exit(1) |
| 300 tree = Parse(filename=sys.argv[1]) | 302 tree = Parse(filename=sys.argv[1]) |
| 301 print(tree) | 303 print(tree) |
| 302 | 304 |
| 303 | 305 |
| 304 if __name__ == '__main__': | 306 if __name__ == '__main__': |
| 305 Main() | 307 Main() |
| OLD | NEW |