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 scoped_name_rest""" |
| 278 p[0] = ''.join(p[1:]) |
| 279 if self.parse_debug: DumpReduction('scoped_name', p) |
| 280 |
| 281 def p_scoped_name_rest(self, p): |
| 282 """scoped_name_rest : '.' scoped_name |
| 283 |""" |
| 284 p[0] = ''.join(p[1:]) |
| 285 if self.parse_debug: DumpReduction('scoped_name_rest', p) |
| 286 |
| 287 # |
| 288 # Type reference |
| 289 # |
| 290 # |
| 291 def p_typeref(self, p): |
| 292 """typeref : scoped_name""" |
| 293 p[0] = p[1] |
| 294 if self.parse_debug: DumpReduction('typeref', p) |
| 295 |
| 296 |
| 297 # |
271 # Comments | 298 # Comments |
272 # | 299 # |
273 # Comments are optional list of C style comment objects. Comments are returned | 300 # Comments are optional list of C style comment objects. Comments are returned |
274 # as a list or None. | 301 # as a list or None. |
275 # | 302 # |
276 def p_comments(self, p): | 303 def p_comments(self, p): |
277 """comments : COMMENT comments | 304 """comments : COMMENT comments |
278 | """ | 305 | """ |
279 if len(p) > 1: | 306 if len(p) > 1: |
280 child = self.BuildComment('Comment', p, 1) | 307 child = self.BuildComment('Comment', p, 1) |
281 p[0] = ListFromConcat(child, p[2]) | 308 p[0] = ListFromConcat(child, p[2]) |
282 if self.parse_debug: DumpReduction('comments', p) | 309 if self.parse_debug: DumpReduction('comments', p) |
283 else: | 310 else: |
284 if self.parse_debug: DumpReduction('no comments', p) | 311 if self.parse_debug: DumpReduction('no comments', p) |
285 | 312 |
286 | 313 |
287 # | 314 # |
288 # Namespace | 315 # Namespace |
289 # | 316 # |
290 # A namespace provides a named scope to an enclosed top_list. | 317 # A namespace provides a named scope to an enclosed top_list. |
291 # | 318 # |
292 def p_namespace(self, p): | 319 def p_namespace(self, p): |
293 """namespace : modifiers NAMESPACE namespace_name '{' top_list '}' ';'""" | 320 """namespace : modifiers NAMESPACE namespace_name '{' top_list '}' ';'""" |
294 children = ListFromConcat(p[1], p[5]) | 321 children = ListFromConcat(p[1], p[5]) |
295 p[0] = self.BuildNamed('Namespace', p, 3, children) | 322 p[0] = self.BuildNamed('Namespace', p, 3, children) |
296 | 323 |
297 # We allow namespace names of the form foo.bar.baz. | 324 # We allow namespace names of the form foo.bar.baz. |
298 def p_namespace_name(self, p): | 325 def p_namespace_name(self, p): |
299 """namespace_name : SYMBOL | 326 """namespace_name : scoped_name""" |
300 | SYMBOL '.' namespace_name""" | 327 p[0] = p[1] |
301 p[0] = "".join(p[1:]) | |
302 | 328 |
303 | 329 |
304 # | 330 # |
305 # Dictionary | 331 # Dictionary |
306 # | 332 # |
307 # A dictionary is a named list of optional and required members. | 333 # A dictionary is a named list of optional and required members. |
308 # | 334 # |
309 def p_dictionary_block(self, p): | 335 def p_dictionary_block(self, p): |
310 """dictionary_block : modifiers DICTIONARY SYMBOL '{' struct_list '}' ';'""" | 336 """dictionary_block : modifiers DICTIONARY SYMBOL '{' struct_list '}' ';'""" |
311 p[0] = self.BuildNamed('Dictionary', p, 3, ListFromConcat(p[1], p[5])) | 337 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 ')' | 640 """param_list : '(' param_item param_cont ')' |
615 | '(' ')' """ | 641 | '(' ')' """ |
616 if len(p) > 3: | 642 if len(p) > 3: |
617 args = ListFromConcat(p[2], p[3]) | 643 args = ListFromConcat(p[2], p[3]) |
618 else: | 644 else: |
619 args = [] | 645 args = [] |
620 p[0] = self.BuildProduction('Callspec', p, 1, args) | 646 p[0] = self.BuildProduction('Callspec', p, 1, args) |
621 if self.parse_debug: DumpReduction('param_list', p) | 647 if self.parse_debug: DumpReduction('param_list', p) |
622 | 648 |
623 def p_param_item(self, p): | 649 def p_param_item(self, p): |
624 """param_item : modifiers optional SYMBOL arrays identifier""" | 650 """param_item : modifiers optional typeref arrays identifier""" |
625 typeref = self.BuildAttribute('TYPEREF', p[3]) | 651 typeref = self.BuildAttribute('TYPEREF', p[3]) |
626 children = ListFromConcat(p[1], p[2], typeref, p[4]) | 652 children = ListFromConcat(p[1], p[2], typeref, p[4]) |
627 p[0] = self.BuildNamed('Param', p, 5, children) | 653 p[0] = self.BuildNamed('Param', p, 5, children) |
628 if self.parse_debug: DumpReduction('param_item', p) | 654 if self.parse_debug: DumpReduction('param_item', p) |
629 | 655 |
630 def p_param_item_union(self, p): | 656 def p_param_item_union(self, p): |
631 """param_item : modifiers optional '(' union_list ')' identifier""" | 657 """param_item : modifiers optional '(' union_list ')' identifier""" |
632 union = self.BuildAttribute('Union', True) | 658 union = self.BuildAttribute('Union', True) |
633 children = ListFromConcat(p[1], p[2], p[4], union) | 659 children = ListFromConcat(p[1], p[2], p[4], union) |
634 p[0] = self.BuildNamed('Param', p, 6, children) | 660 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] | 779 p[0] = p[2] |
754 if self.parse_debug: DumpReduction('label_error', p) | 780 if self.parse_debug: DumpReduction('label_error', p) |
755 | 781 |
756 | 782 |
757 # | 783 # |
758 # Members | 784 # Members |
759 # | 785 # |
760 # A member attribute or function of a struct or interface. | 786 # A member attribute or function of a struct or interface. |
761 # | 787 # |
762 def p_member_attribute(self, p): | 788 def p_member_attribute(self, p): |
763 """member_attribute : modifiers SYMBOL arrays questionmark identifier""" | 789 """member_attribute : modifiers typeref arrays questionmark identifier""" |
764 typeref = self.BuildAttribute('TYPEREF', p[2]) | 790 typeref = self.BuildAttribute('TYPEREF', p[2]) |
765 children = ListFromConcat(p[1], typeref, p[3], p[4]) | 791 children = ListFromConcat(p[1], typeref, p[3], p[4]) |
766 p[0] = self.BuildNamed('Member', p, 5, children) | 792 p[0] = self.BuildNamed('Member', p, 5, children) |
767 if self.parse_debug: DumpReduction('attribute', p) | 793 if self.parse_debug: DumpReduction('attribute', p) |
768 | 794 |
769 def p_member_attribute_union(self, p): | 795 def p_member_attribute_union(self, p): |
770 """member_attribute : modifiers '(' union_list ')' questionmark identifier""
" | 796 """member_attribute : modifiers '(' union_list ')' questionmark identifier""
" |
771 union = self.BuildAttribute('Union', True) | 797 union = self.BuildAttribute('Union', True) |
772 children = ListFromConcat(p[1], p[3], p[5], union) | 798 children = ListFromConcat(p[1], p[3], p[5], union) |
773 p[0] = self.BuildNamed('Member', p, 6, children) | 799 p[0] = self.BuildNamed('Member', p, 6, children) |
774 if self.parse_debug: DumpReduction('attribute', p) | 800 if self.parse_debug: DumpReduction('attribute', p) |
775 | 801 |
776 def p_member_function(self, p): | 802 def p_member_function(self, p): |
777 """member_function : modifiers static SYMBOL arrays SYMBOL param_list""" | 803 """member_function : modifiers static typeref arrays SYMBOL param_list""" |
778 typeref = self.BuildAttribute('TYPEREF', p[3]) | 804 typeref = self.BuildAttribute('TYPEREF', p[3]) |
779 children = ListFromConcat(p[1], p[2], typeref, p[4], p[6]) | 805 children = ListFromConcat(p[1], p[2], typeref, p[4], p[6]) |
780 p[0] = self.BuildNamed('Member', p, 5, children) | 806 p[0] = self.BuildNamed('Member', p, 5, children) |
781 if self.parse_debug: DumpReduction('function', p) | 807 if self.parse_debug: DumpReduction('function', p) |
782 | 808 |
783 def p_static(self, p): | 809 def p_static(self, p): |
784 """static : STATIC | 810 """static : STATIC |
785 | """ | 811 | """ |
786 if len(p) == 2: | 812 if len(p) == 2: |
787 p[0] = self.BuildAttribute('STATIC', True) | 813 p[0] = self.BuildAttribute('STATIC', True) |
(...skipping 474 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1262 errs = ast.GetProperty('ERRORS') | 1288 errs = ast.GetProperty('ERRORS') |
1263 if errs: | 1289 if errs: |
1264 ErrOut.Log('Found %d error(s).' % errs); | 1290 ErrOut.Log('Found %d error(s).' % errs); |
1265 InfoOut.Log("%d files processed." % len(filenames)) | 1291 InfoOut.Log("%d files processed." % len(filenames)) |
1266 return errs | 1292 return errs |
1267 | 1293 |
1268 | 1294 |
1269 if __name__ == '__main__': | 1295 if __name__ == '__main__': |
1270 sys.exit(Main(sys.argv[1:])) | 1296 sys.exit(Main(sys.argv[1:])) |
1271 | 1297 |
OLD | NEW |