| 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 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 88 p[0] = ('STRUCT', p[3], p[1], p[5]) | 88 p[0] = ('STRUCT', p[3], p[1], p[5]) |
| 89 | 89 |
| 90 def p_struct_body(self, p): | 90 def p_struct_body(self, p): |
| 91 """struct_body : field struct_body | 91 """struct_body : field struct_body |
| 92 | enum struct_body | 92 | enum struct_body |
| 93 |""" | 93 |""" |
| 94 if len(p) > 1: | 94 if len(p) > 1: |
| 95 p[0] = ListFromConcat(p[1], p[2]) | 95 p[0] = ListFromConcat(p[1], p[2]) |
| 96 | 96 |
| 97 def p_field(self, p): | 97 def p_field(self, p): |
| 98 """field : typename NAME ordinal SEMI""" | 98 """field : typename NAME default ordinal SEMI""" |
| 99 p[0] = ('FIELD', p[1], p[2], p[3]) | 99 p[0] = ('FIELD', p[1], p[2], p[4], p[3]) |
| 100 |
| 101 def p_default(self, p): |
| 102 """default : EQUALS expression |
| 103 | """ |
| 104 if len(p) > 2: |
| 105 p[0] = p[2] |
| 100 | 106 |
| 101 def p_interface(self, p): | 107 def p_interface(self, p): |
| 102 """interface : attribute_section INTERFACE NAME LBRACE interface_body RBRACE
SEMI""" | 108 """interface : attribute_section INTERFACE NAME LBRACE interface_body RBRACE
SEMI""" |
| 103 p[0] = ('INTERFACE', p[3], p[1], p[5]) | 109 p[0] = ('INTERFACE', p[3], p[1], p[5]) |
| 104 | 110 |
| 105 def p_interface_body(self, p): | 111 def p_interface_body(self, p): |
| 106 """interface_body : method interface_body | 112 """interface_body : method interface_body |
| 107 | enum interface_body | 113 | enum interface_body |
| 108 | """ | 114 | """ |
| 109 if len(p) > 1: | 115 if len(p) > 1: |
| (...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 270 def Main(): | 276 def Main(): |
| 271 if len(sys.argv) < 2: | 277 if len(sys.argv) < 2: |
| 272 print("usage: %s filename" % (sys.argv[0])) | 278 print("usage: %s filename" % (sys.argv[0])) |
| 273 sys.exit(1) | 279 sys.exit(1) |
| 274 tree = Parse(filename=sys.argv[1]) | 280 tree = Parse(filename=sys.argv[1]) |
| 275 print(tree) | 281 print(tree) |
| 276 | 282 |
| 277 | 283 |
| 278 if __name__ == '__main__': | 284 if __name__ == '__main__': |
| 279 Main() | 285 Main() |
| OLD | NEW |