OLD | NEW |
---|---|
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 # Copyright (c) 2013 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 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 """ Parser for PPAPI IDL """ | 6 """ Parser for PPAPI IDL """ |
7 | 7 |
8 # | 8 # |
9 # IDL Parser | 9 # IDL Parser |
10 # | 10 # |
(...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
252 p[0] = self.BuildNamed('Interface', p, 2, p[4]) | 252 p[0] = self.BuildNamed('Interface', p, 2, p[4]) |
253 | 253 |
254 # [9] | 254 # [9] |
255 def p_InterfaceMembers(self, p): | 255 def p_InterfaceMembers(self, p): |
256 """InterfaceMembers : ExtendedAttributeList InterfaceMember InterfaceMembers | 256 """InterfaceMembers : ExtendedAttributeList InterfaceMember InterfaceMembers |
257 |""" | 257 |""" |
258 if len(p) > 1: | 258 if len(p) > 1: |
259 p[2].AddChildren(p[1]) | 259 p[2].AddChildren(p[1]) |
260 p[0] = ListFromConcat(p[2], p[3]) | 260 p[0] = ListFromConcat(p[2], p[3]) |
261 | 261 |
262 # [10] | 262 # [10] Removed unsupported: Serializer |
263 def p_InterfaceMember(self, p): | 263 def p_InterfaceMember(self, p): |
264 """InterfaceMember : Const | 264 """InterfaceMember : Const |
265 | AttributeOrOperationOrIterator""" | 265 | Operation |
266 p[0] = p[1] | 266 | Stringifier |
267 | 267 | StaticMember |
268 # [10.1] Removed unsupported: Serializer | 268 | Iterable |
269 def p_AttributeOrOperationOrIterator(self, p): | 269 | ReadonlyMember |
270 """AttributeOrOperationOrIterator : Stringifier | 270 | ReadWriteAttribute |
271 | StaticMember | 271 | ReadWriteMaplike |
272 | ReadWriteAttribute | 272 | ReadWriteSetlike""" |
273 | OperationOrIterator""" | |
274 p[0] = p[1] | 273 p[0] = p[1] |
275 | 274 |
276 # [11] | 275 # [11] |
277 def p_Dictionary(self, p): | 276 def p_Dictionary(self, p): |
278 """Dictionary : DICTIONARY identifier Inheritance '{' DictionaryMembers '}' ';'""" | 277 """Dictionary : DICTIONARY identifier Inheritance '{' DictionaryMembers '}' ';'""" |
279 p[0] = self.BuildNamed('Dictionary', p, 2, ListFromConcat(p[3], p[5])) | 278 p[0] = self.BuildNamed('Dictionary', p, 2, ListFromConcat(p[3], p[5])) |
280 | 279 |
281 # [11.1] Error recovery for regular Dictionary | 280 # [11.1] Error recovery for regular Dictionary |
282 def p_DictionaryError(self, p): | 281 def p_DictionaryError(self, p): |
283 """Dictionary : DICTIONARY error ';'""" | 282 """Dictionary : DICTIONARY error ';'""" |
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
473 p[0] = p[1] | 472 p[0] = p[1] |
474 | 473 |
475 # [37] | 474 # [37] |
476 def p_StaticMember(self, p): | 475 def p_StaticMember(self, p): |
477 """StaticMember : STATIC StaticMemberRest""" | 476 """StaticMember : STATIC StaticMemberRest""" |
478 p[2].AddChildren(self.BuildTrue('STATIC')) | 477 p[2].AddChildren(self.BuildTrue('STATIC')) |
479 p[0] = p[2] | 478 p[0] = p[2] |
480 | 479 |
481 # [38] | 480 # [38] |
482 def p_StaticMemberRest(self, p): | 481 def p_StaticMemberRest(self, p): |
483 """StaticMemberRest : AttributeRest | 482 """StaticMemberRest : ReadOnly AttributeRest |
484 | ReturnType OperationRest""" | 483 | ReturnType OperationRest""" |
485 if len(p) == 2: | 484 if len(p) == 2: |
486 p[0] = p[1] | 485 p[0] = p[1] |
487 else: | 486 else: |
488 p[2].AddChildren(p[1]) | 487 p[2].AddChildren(p[1]) |
489 p[0] = p[2] | 488 p[0] = p[2] |
490 | 489 |
491 # [39] NOT IMPLEMENTED (ReadOnlyMember) | 490 # [39] |
492 # [40] NOT IMPLEMENTED (ReadOnlyMemberReset) | 491 def p_ReadonlyMember(self, p): |
492 """ReadonlyMember : READONLY ReadonlyMemberRest""" | |
493 p[2].AddChildren(self.BuildTrue('READONLY')) | |
494 p[0] = p[2] | |
495 | |
496 # [40] | |
497 def p_ReadonlyMemberRest(self, p): | |
498 """ReadonlyMemberRest : AttributeRest | |
499 | MaplikeRest | |
500 | SetlikeRest""" | |
501 p[0] = p[1] | |
493 | 502 |
494 # [41] | 503 # [41] |
495 def p_ReadWriteAttribute(self, p): | 504 def p_ReadWriteAttribute(self, p): |
496 """ReadWriteAttribute : Inherit AttributeRest""" | 505 """ReadWriteAttribute : INHERIT ReadOnly AttributeRest |
497 p[2].AddChildren(ListFromConcat(p[1])) | 506 | AttributeRest""" |
498 p[0] = p[2] | 507 if len(p) > 2: |
499 | 508 inherit = self.BuildTrue('INHERIT') |
500 # [41] Deprecated - Remove this entry after blink stops using it. | 509 p[3].AddChildren(ListFromConcat(inherit, p[2])) |
501 def p_Attribute(self, p): | 510 p[0] = p[3] |
502 """Attribute : ReadWriteAttribute""" | 511 else: |
503 p[0] = p[1] | 512 p[0] = p[1] |
504 | 513 |
505 # [42] | 514 # [42] |
506 def p_AttributeRest(self, p): | 515 def p_AttributeRest(self, p): |
507 """AttributeRest : ReadOnly ATTRIBUTE Type identifier ';'""" | 516 """AttributeRest : ATTRIBUTE Type AttributeName ';'""" |
508 p[0] = self.BuildNamed('Attribute', p, 4, | 517 p[0] = self.BuildNamed('Attribute', p, 3, p[2]) |
509 ListFromConcat(p[1], p[3])) | |
510 | 518 |
511 # [43] NOT IMPLEMENTED (AttributeName) | 519 # [43] |
512 # [44] NOT IMPLEMENTED (AttributeNameKeyword) | 520 def p_AttributeName(self, p): |
521 """AttributeName : AttributeNameKeyword | |
522 | identifier""" | |
523 p[0] = p[1] | |
513 | 524 |
514 # [45] | 525 # [44] |
515 def p_Inherit(self, p): | 526 def p_AttributeNameKeyword(self, p): |
516 """Inherit : INHERIT | 527 """AttributeNameKeyword : REQUIRED""" |
517 |""" | 528 p[0] = p[1] |
haraken
2014/12/15 15:11:13
p[0] = self.BuildTrue('REQUIRED') ?
Jens Widell
2014/12/15 15:30:32
No, this is simply a grammar workaround to allow a
| |
518 if len(p) > 1: | 529 |
519 p[0] = self.BuildTrue('INHERIT') | 530 # [45] Unreferenced in the specification |
Jens Widell
2014/12/15 11:35:15
This is:
[45] Inherit → "inherit"
| |
520 | 531 |
521 # [46] | 532 # [46] |
522 def p_ReadOnly(self, p): | 533 def p_ReadOnly(self, p): |
523 """ReadOnly : READONLY | 534 """ReadOnly : READONLY |
524 |""" | 535 |""" |
525 if len(p) > 1: | 536 if len(p) > 1: |
526 p[0] = self.BuildTrue('READONLY') | 537 p[0] = self.BuildTrue('READONLY') |
527 | 538 |
528 # [47] | 539 # [47] |
529 def p_OperationOrIterator(self, p): | 540 def p_Operation(self, p): |
530 """OperationOrIterator : ReturnType OperationOrIteratorRest | 541 """Operation : ReturnType OperationRest |
531 | SpecialOperation""" | 542 | SpecialOperation""" |
532 if len(p) == 3: | 543 if len(p) == 3: |
533 p[2].AddChildren(p[1]) | 544 p[2].AddChildren(p[1]) |
534 p[0] = p[2] | 545 p[0] = p[2] |
535 else: | 546 else: |
536 p[0] = p[1] | 547 p[0] = p[1] |
537 | 548 |
538 # [48] | 549 # [48] |
539 def p_SpecialOperation(self, p): | 550 def p_SpecialOperation(self, p): |
540 """SpecialOperation : Special Specials ReturnType OperationRest""" | 551 """SpecialOperation : Special Specials ReturnType OperationRest""" |
541 p[4].AddChildren(ListFromConcat(p[1], p[2], p[3])) | 552 p[4].AddChildren(ListFromConcat(p[1], p[2], p[3])) |
542 p[0] = p[4] | 553 p[0] = p[4] |
543 | 554 |
544 # [49] | 555 # [49] |
545 def p_Specials(self, p): | 556 def p_Specials(self, p): |
546 """Specials : Special Specials | 557 """Specials : Special Specials |
547 | """ | 558 | """ |
548 if len(p) > 1: | 559 if len(p) > 1: |
549 p[0] = ListFromConcat(p[1], p[2]) | 560 p[0] = ListFromConcat(p[1], p[2]) |
550 | 561 |
551 # [50] | 562 # [50] |
552 def p_Special(self, p): | 563 def p_Special(self, p): |
553 """Special : GETTER | 564 """Special : GETTER |
554 | SETTER | 565 | SETTER |
555 | CREATOR | 566 | CREATOR |
556 | DELETER | 567 | DELETER |
557 | LEGACYCALLER""" | 568 | LEGACYCALLER""" |
558 p[0] = self.BuildTrue(p[1].upper()) | 569 p[0] = self.BuildTrue(p[1].upper()) |
559 | 570 |
560 # [51] | 571 # [51] |
561 def p_OperationOrIteratorRest(self, p): | |
562 """OperationOrIteratorRest : OperationRest""" | |
563 p[0] = p[1] | |
564 | |
565 # [51] | |
566 def p_OperationRest(self, p): | 572 def p_OperationRest(self, p): |
567 """OperationRest : OptionalIdentifier '(' ArgumentList ')' ';'""" | 573 """OperationRest : OptionalIdentifier '(' ArgumentList ')' ';'""" |
568 arguments = self.BuildProduction('Arguments', p, 2, p[3]) | 574 arguments = self.BuildProduction('Arguments', p, 2, p[3]) |
569 p[0] = self.BuildNamed('Operation', p, 1, arguments) | 575 p[0] = self.BuildNamed('Operation', p, 1, arguments) |
570 | 576 |
571 # [52] | 577 # [52] |
572 def p_OptionalIdentifier(self, p): | 578 def p_OptionalIdentifier(self, p): |
573 """OptionalIdentifier : identifier | 579 """OptionalIdentifier : identifier |
574 |""" | 580 |""" |
575 if len(p) > 1: | 581 if len(p) > 1: |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
641 # [] Unspecified | 647 # [] Unspecified |
642 def p_ExceptionField(self, p): | 648 def p_ExceptionField(self, p): |
643 """ExceptionField : Type identifier ';'""" | 649 """ExceptionField : Type identifier ';'""" |
644 p[0] = self.BuildNamed('ExceptionField', p, 2, p[1]) | 650 p[0] = self.BuildNamed('ExceptionField', p, 2, p[1]) |
645 | 651 |
646 # [] Error recovery for ExceptionMembers - Unspecified | 652 # [] Error recovery for ExceptionMembers - Unspecified |
647 def p_ExceptionFieldError(self, p): | 653 def p_ExceptionFieldError(self, p): |
648 """ExceptionField : error""" | 654 """ExceptionField : error""" |
649 p[0] = self.BuildError(p, 'ExceptionField') | 655 p[0] = self.BuildError(p, 'ExceptionField') |
650 | 656 |
651 # [59] NOT IMPLEMENTED (Iterable) | 657 # [59] |
652 # [60] NOT IMPLEMENTED (OptionalType) | 658 def p_Iterable(self, p): |
653 # [61] NOT IMPLEMENTED (ReadWriteMaplike) | 659 """Iterable : ITERABLE '<' Type OptionalType '>' ';' |
654 # [62] NOT IMPLEMENTED (ReadWriteSetlike) | 660 | LEGACYITERABLE '<' Type '>' ';'""" |
655 # [63] NOT IMPLEMENTED (MaplikeRest) | 661 if len(p) > 6: |
656 # [64] NOT IMPLEMENTED (SetlikeRest) | 662 childlist = ListFromConcat(p[3], p[4]) |
663 p[0] = self.BuildProduction('Iterable', p, 2, childlist) | |
664 else: | |
665 p[0] = self.BuildProduction('LegacyIterable', p, 2, p[3]) | |
666 | |
667 # [60] | |
668 def p_OptionalType(self, p): | |
669 """OptionalType : ',' Type | |
670 |""" | |
671 if len(p) > 1: | |
haraken
2014/12/15 15:11:13
if len(p) > 2:
Jens Widell
2014/12/15 15:30:32
The pattern in cases like this is "len(p) > 1". Se
| |
672 p[0] = p[2] | |
673 | |
674 # [61] | |
675 def p_ReadWriteMaplike(self, p): | |
676 """ReadWriteMaplike : MaplikeRest""" | |
677 p[0] = p[1] | |
678 | |
679 # [62] | |
680 def p_ReadWriteSetlike(self, p): | |
681 """ReadWriteSetlike : SetlikeRest""" | |
682 p[0] = p[1] | |
683 | |
684 # [63] | |
685 def p_MaplikeRest(self, p): | |
686 """MaplikeRest : MAPLIKE '<' Type ',' Type '>' ';'""" | |
687 childlist = ListFromConcat(p[3], p[5]) | |
688 p[0] = self.BuildProduction('Maplike', p, 2, childlist) | |
689 | |
690 # [64] | |
691 def p_SetlikeRest(self, p): | |
692 """SetlikeRest : SETLIKE '<' Type '>' ';'""" | |
693 p[0] = self.BuildProduction('Setlike', p, 2, p[3]) | |
657 | 694 |
658 # [65] No comment version for mid statement attributes. | 695 # [65] No comment version for mid statement attributes. |
659 def p_ExtendedAttributeListNoComments(self, p): | 696 def p_ExtendedAttributeListNoComments(self, p): |
660 """ExtendedAttributeListNoComments : '[' ExtendedAttribute ExtendedAttribute s ']' | 697 """ExtendedAttributeListNoComments : '[' ExtendedAttribute ExtendedAttribute s ']' |
661 | """ | 698 | """ |
662 if len(p) > 2: | 699 if len(p) > 2: |
663 items = ListFromConcat(p[2], p[3]) | 700 items = ListFromConcat(p[2], p[3]) |
664 p[0] = self.BuildProduction('ExtAttributes', p, 1, items) | 701 p[0] = self.BuildProduction('ExtAttributes', p, 1, items) |
665 | 702 |
666 # [65.1] Add optional comment field for start of statements. | 703 # [65.1] Add optional comment field for start of statements. |
(...skipping 490 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1157 | 1194 |
1158 print '\n'.join(ast.Tree(accept_props=['PROD'])) | 1195 print '\n'.join(ast.Tree(accept_props=['PROD'])) |
1159 if errors: | 1196 if errors: |
1160 print '\nFound %d errors.\n' % errors | 1197 print '\nFound %d errors.\n' % errors |
1161 | 1198 |
1162 return errors | 1199 return errors |
1163 | 1200 |
1164 | 1201 |
1165 if __name__ == '__main__': | 1202 if __name__ == '__main__': |
1166 sys.exit(main(sys.argv[1:])) | 1203 sys.exit(main(sys.argv[1:])) |
OLD | NEW |