Chromium Code Reviews| 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 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 143 def p_attributes(self, p): | 143 def p_attributes(self, p): |
| 144 """attributes : attribute | 144 """attributes : attribute |
| 145 | attribute COMMA attributes | 145 | attribute COMMA attributes |
| 146 | """ | 146 | """ |
| 147 if len(p) == 2: | 147 if len(p) == 2: |
| 148 p[0] = ListFromConcat(p[1]) | 148 p[0] = ListFromConcat(p[1]) |
| 149 elif len(p) > 3: | 149 elif len(p) > 3: |
| 150 p[0] = ListFromConcat(p[1], p[3]) | 150 p[0] = ListFromConcat(p[1], p[3]) |
| 151 | 151 |
| 152 def p_attribute(self, p): | 152 def p_attribute(self, p): |
| 153 """attribute : NAME EQUALS NUMBER""" | 153 """attribute : NAME EQUALS NUMBER |
|
darin (slow to review)
2013/11/07 06:14:31
Previously, I had just supported [name=number] in
| |
| 154 | NAME EQUALS NAME""" | |
| 154 p[0] = ('ATTRIBUTE', p[1], p[3]) | 155 p[0] = ('ATTRIBUTE', p[1], p[3]) |
| 155 | 156 |
| 156 def p_struct(self, p): | 157 def p_struct(self, p): |
| 157 """struct : attribute_section STRUCT NAME LCURLY fields RCURLY SEMICOLON""" | 158 """struct : attribute_section STRUCT NAME LCURLY fields RCURLY SEMICOLON""" |
| 158 p[0] = ('STRUCT', p[3], p[1], p[5]) | 159 p[0] = ('STRUCT', p[3], p[1], p[5]) |
| 159 | 160 |
| 160 def p_fields(self, p): | 161 def p_fields(self, p): |
| 161 """fields : field fields | 162 """fields : field fields |
| 162 |""" | 163 |""" |
| 163 if len(p) > 1: | 164 if len(p) > 1: |
| 164 p[0] = ListFromConcat(p[1], p[2]) | 165 p[0] = ListFromConcat(p[1], p[2]) |
| 165 | 166 |
| 166 def p_field(self, p): | 167 def p_field(self, p): |
| 167 """field : typename NAME ordinal SEMICOLON""" | 168 """field : typename NAME ordinal SEMICOLON""" |
| 168 p[0] = ('FIELD', p[1], p[2], p[3]) | 169 p[0] = ('FIELD', p[1], p[2], p[3]) |
| 169 | 170 |
| 170 def p_interface(self, p): | 171 def p_interface(self, p): |
| 171 """interface : INTERFACE NAME LCURLY methods RCURLY SEMICOLON""" | 172 """interface : attribute_section INTERFACE NAME LCURLY methods RCURLY SEMICO LON""" |
| 172 p[0] = ('INTERFACE', p[2], p[4]) | 173 p[0] = ('INTERFACE', p[3], p[1], p[5]) |
| 173 | 174 |
| 174 def p_methods(self, p): | 175 def p_methods(self, p): |
| 175 """methods : method methods | 176 """methods : method methods |
| 176 | """ | 177 | """ |
| 177 if len(p) > 1: | 178 if len(p) > 1: |
| 178 p[0] = ListFromConcat(p[1], p[2]) | 179 p[0] = ListFromConcat(p[1], p[2]) |
| 179 | 180 |
| 180 def p_method(self, p): | 181 def p_method(self, p): |
| 181 """method : VOID NAME LPAREN parameters RPAREN ordinal SEMICOLON""" | 182 """method : VOID NAME LPAREN parameters RPAREN ordinal SEMICOLON""" |
| 182 p[0] = ('METHOD', p[2], p[4], p[6]) | 183 p[0] = ('METHOD', p[2], p[4], p[6]) |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 225 def Main(): | 226 def Main(): |
| 226 if len(sys.argv) < 2: | 227 if len(sys.argv) < 2: |
| 227 print("usage: %s filename" % (sys.argv[0])) | 228 print("usage: %s filename" % (sys.argv[0])) |
| 228 sys.exit(1) | 229 sys.exit(1) |
| 229 tree = Parse(filename=sys.argv[1]) | 230 tree = Parse(filename=sys.argv[1]) |
| 230 print(tree) | 231 print(tree) |
| 231 | 232 |
| 232 | 233 |
| 233 if __name__ == '__main__': | 234 if __name__ == '__main__': |
| 234 Main() | 235 Main() |
| OLD | NEW |