OLD | NEW |
---|---|
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2012 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 """ Parser for PPAPI IDL """ | 6 """ Parser for PPAPI IDL """ |
7 | 7 |
8 # | 8 # |
9 # IDL Parser | 9 # IDL Parser |
10 # | 10 # |
(...skipping 250 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
261 # | 261 # |
262 # Modifier List | 262 # Modifier List |
263 # | 263 # |
264 # | 264 # |
265 def p_modifiers(self, p): | 265 def p_modifiers(self, p): |
266 """modifiers : comments ext_attr_block""" | 266 """modifiers : comments ext_attr_block""" |
267 p[0] = ListFromConcat(p[1], p[2]) | 267 p[0] = ListFromConcat(p[1], p[2]) |
268 if self.parse_debug: DumpReduction('modifiers', p) | 268 if self.parse_debug: DumpReduction('modifiers', p) |
269 | 269 |
270 # | 270 # |
271 # Scoped name is a name with an optional scope. | |
272 # | |
273 # Used for types and namespace names. eg. foo_bar.hello_world, or | |
274 # foo_bar.hello_world.SomeType. | |
275 # | |
276 def p_scoped_name(self, p): | |
277 """scoped_name : SYMBOL | |
Nils Barth (inactive)
2014/03/28 05:01:19
This should instead be:
scoped_name : SYMBOL scope
mtomasz
2014/03/28 05:19:38
Done.
Nils Barth (inactive)
2014/03/28 05:25:13
Thanks!
LGTM again!
| |
278 | scoped_name '.' SYMBOL""" | |
279 p[0] = ''.join(p[1:]) | |
280 if self.parse_debug: DumpReduction('scoped_name', p) | |
281 | |
282 # | |
283 # Type reference | |
284 # | |
285 # | |
286 def p_typeref(self, p): | |
287 """typeref : scoped_name""" | |
288 p[0] = p[1] | |
289 if self.parse_debug: DumpReduction('typeref', p) | |
290 | |
291 | |
292 # | |
271 # Comments | 293 # Comments |
272 # | 294 # |
273 # Comments are optional list of C style comment objects. Comments are returned | 295 # Comments are optional list of C style comment objects. Comments are returned |
274 # as a list or None. | 296 # as a list or None. |
275 # | 297 # |
276 def p_comments(self, p): | 298 def p_comments(self, p): |
277 """comments : COMMENT comments | 299 """comments : COMMENT comments |
278 | """ | 300 | """ |
279 if len(p) > 1: | 301 if len(p) > 1: |
280 child = self.BuildComment('Comment', p, 1) | 302 child = self.BuildComment('Comment', p, 1) |
281 p[0] = ListFromConcat(child, p[2]) | 303 p[0] = ListFromConcat(child, p[2]) |
282 if self.parse_debug: DumpReduction('comments', p) | 304 if self.parse_debug: DumpReduction('comments', p) |
283 else: | 305 else: |
284 if self.parse_debug: DumpReduction('no comments', p) | 306 if self.parse_debug: DumpReduction('no comments', p) |
285 | 307 |
286 | 308 |
287 # | 309 # |
288 # Namespace | 310 # Namespace |
289 # | 311 # |
290 # A namespace provides a named scope to an enclosed top_list. | 312 # A namespace provides a named scope to an enclosed top_list. |
291 # | 313 # |
292 def p_namespace(self, p): | 314 def p_namespace(self, p): |
293 """namespace : modifiers NAMESPACE namespace_name '{' top_list '}' ';'""" | 315 """namespace : modifiers NAMESPACE namespace_name '{' top_list '}' ';'""" |
294 children = ListFromConcat(p[1], p[5]) | 316 children = ListFromConcat(p[1], p[5]) |
295 p[0] = self.BuildNamed('Namespace', p, 3, children) | 317 p[0] = self.BuildNamed('Namespace', p, 3, children) |
296 | 318 |
297 # We allow namespace names of the form foo.bar.baz. | 319 # We allow namespace names of the form foo.bar.baz. |
298 def p_namespace_name(self, p): | 320 def p_namespace_name(self, p): |
299 """namespace_name : SYMBOL | 321 """namespace_name : scoped_name""" |
300 | SYMBOL '.' namespace_name""" | 322 p[0] = p[1] |
301 p[0] = "".join(p[1:]) | |
302 | 323 |
303 | 324 |
304 # | 325 # |
305 # Dictionary | 326 # Dictionary |
306 # | 327 # |
307 # A dictionary is a named list of optional and required members. | 328 # A dictionary is a named list of optional and required members. |
308 # | 329 # |
309 def p_dictionary_block(self, p): | 330 def p_dictionary_block(self, p): |
310 """dictionary_block : modifiers DICTIONARY SYMBOL '{' struct_list '}' ';'""" | 331 """dictionary_block : modifiers DICTIONARY SYMBOL '{' struct_list '}' ';'""" |
311 p[0] = self.BuildNamed('Dictionary', p, 3, ListFromConcat(p[1], p[5])) | 332 p[0] = self.BuildNamed('Dictionary', p, 3, ListFromConcat(p[1], p[5])) |
(...skipping 302 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
614 """param_list : '(' param_item param_cont ')' | 635 """param_list : '(' param_item param_cont ')' |
615 | '(' ')' """ | 636 | '(' ')' """ |
616 if len(p) > 3: | 637 if len(p) > 3: |
617 args = ListFromConcat(p[2], p[3]) | 638 args = ListFromConcat(p[2], p[3]) |
618 else: | 639 else: |
619 args = [] | 640 args = [] |
620 p[0] = self.BuildProduction('Callspec', p, 1, args) | 641 p[0] = self.BuildProduction('Callspec', p, 1, args) |
621 if self.parse_debug: DumpReduction('param_list', p) | 642 if self.parse_debug: DumpReduction('param_list', p) |
622 | 643 |
623 def p_param_item(self, p): | 644 def p_param_item(self, p): |
624 """param_item : modifiers optional SYMBOL arrays identifier""" | 645 """param_item : modifiers optional typeref arrays identifier""" |
625 typeref = self.BuildAttribute('TYPEREF', p[3]) | 646 typeref = self.BuildAttribute('TYPEREF', p[3]) |
626 children = ListFromConcat(p[1], p[2], typeref, p[4]) | 647 children = ListFromConcat(p[1], p[2], typeref, p[4]) |
627 p[0] = self.BuildNamed('Param', p, 5, children) | 648 p[0] = self.BuildNamed('Param', p, 5, children) |
628 if self.parse_debug: DumpReduction('param_item', p) | 649 if self.parse_debug: DumpReduction('param_item', p) |
629 | 650 |
630 def p_param_item_union(self, p): | 651 def p_param_item_union(self, p): |
631 """param_item : modifiers optional '(' union_list ')' identifier""" | 652 """param_item : modifiers optional '(' union_list ')' identifier""" |
632 union = self.BuildAttribute('Union', True) | 653 union = self.BuildAttribute('Union', True) |
633 children = ListFromConcat(p[1], p[2], p[4], union) | 654 children = ListFromConcat(p[1], p[2], p[4], union) |
634 p[0] = self.BuildNamed('Param', p, 6, children) | 655 p[0] = self.BuildNamed('Param', p, 6, children) |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
753 p[0] = p[2] | 774 p[0] = p[2] |
754 if self.parse_debug: DumpReduction('label_error', p) | 775 if self.parse_debug: DumpReduction('label_error', p) |
755 | 776 |
756 | 777 |
757 # | 778 # |
758 # Members | 779 # Members |
759 # | 780 # |
760 # A member attribute or function of a struct or interface. | 781 # A member attribute or function of a struct or interface. |
761 # | 782 # |
762 def p_member_attribute(self, p): | 783 def p_member_attribute(self, p): |
763 """member_attribute : modifiers SYMBOL arrays questionmark identifier""" | 784 """member_attribute : modifiers typeref arrays questionmark identifier""" |
764 typeref = self.BuildAttribute('TYPEREF', p[2]) | 785 typeref = self.BuildAttribute('TYPEREF', p[2]) |
765 children = ListFromConcat(p[1], typeref, p[3], p[4]) | 786 children = ListFromConcat(p[1], typeref, p[3], p[4]) |
766 p[0] = self.BuildNamed('Member', p, 5, children) | 787 p[0] = self.BuildNamed('Member', p, 5, children) |
767 if self.parse_debug: DumpReduction('attribute', p) | 788 if self.parse_debug: DumpReduction('attribute', p) |
768 | 789 |
769 def p_member_attribute_union(self, p): | 790 def p_member_attribute_union(self, p): |
770 """member_attribute : modifiers '(' union_list ')' questionmark identifier"" " | 791 """member_attribute : modifiers '(' union_list ')' questionmark identifier"" " |
771 union = self.BuildAttribute('Union', True) | 792 union = self.BuildAttribute('Union', True) |
772 children = ListFromConcat(p[1], p[3], p[5], union) | 793 children = ListFromConcat(p[1], p[3], p[5], union) |
773 p[0] = self.BuildNamed('Member', p, 6, children) | 794 p[0] = self.BuildNamed('Member', p, 6, children) |
774 if self.parse_debug: DumpReduction('attribute', p) | 795 if self.parse_debug: DumpReduction('attribute', p) |
775 | 796 |
776 def p_member_function(self, p): | 797 def p_member_function(self, p): |
777 """member_function : modifiers static SYMBOL arrays SYMBOL param_list""" | 798 """member_function : modifiers static typeref arrays SYMBOL param_list""" |
778 typeref = self.BuildAttribute('TYPEREF', p[3]) | 799 typeref = self.BuildAttribute('TYPEREF', p[3]) |
779 children = ListFromConcat(p[1], p[2], typeref, p[4], p[6]) | 800 children = ListFromConcat(p[1], p[2], typeref, p[4], p[6]) |
780 p[0] = self.BuildNamed('Member', p, 5, children) | 801 p[0] = self.BuildNamed('Member', p, 5, children) |
781 if self.parse_debug: DumpReduction('function', p) | 802 if self.parse_debug: DumpReduction('function', p) |
782 | 803 |
783 def p_static(self, p): | 804 def p_static(self, p): |
784 """static : STATIC | 805 """static : STATIC |
785 | """ | 806 | """ |
786 if len(p) == 2: | 807 if len(p) == 2: |
787 p[0] = self.BuildAttribute('STATIC', True) | 808 p[0] = self.BuildAttribute('STATIC', True) |
(...skipping 474 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1262 errs = ast.GetProperty('ERRORS') | 1283 errs = ast.GetProperty('ERRORS') |
1263 if errs: | 1284 if errs: |
1264 ErrOut.Log('Found %d error(s).' % errs); | 1285 ErrOut.Log('Found %d error(s).' % errs); |
1265 InfoOut.Log("%d files processed." % len(filenames)) | 1286 InfoOut.Log("%d files processed." % len(filenames)) |
1266 return errs | 1287 return errs |
1267 | 1288 |
1268 | 1289 |
1269 if __name__ == '__main__': | 1290 if __name__ == '__main__': |
1270 sys.exit(Main(sys.argv[1:])) | 1291 sys.exit(Main(sys.argv[1:])) |
1271 | 1292 |
OLD | NEW |