comparison trunk/src/Parser.d @ 100:538e8b546669

- Added code for parsing IsExpressions. - Added class SpecializationType for IsExpressions. - Added missing default statement in parseDeclaratorSuffix(). - Added parameter identOptional to parseDeclarator().
author aziz
date Sat, 07 Jul 2007 13:55:01 +0000
parents 6b8c248f5911
children 6f3c5473c5e5
comparison
equal deleted inserted replaced
99:6b8c248f5911 100:538e8b546669
557 auto type = parseType(); 557 auto type = parseType();
558 require(T.RParen); 558 require(T.RParen);
559 e = new TypeidExpression(type); 559 e = new TypeidExpression(type);
560 break; 560 break;
561 case T.Is: 561 case T.Is:
562 // e = new IsExpression(); 562 requireNext(T.LParen);
563
564 Type type;
565 SpecializationType specType;
566 string ident; // optional Identifier
567
568 type = parseDeclarator(ident, true);
569
570 switch (token.type)
571 {
572 case T.Colon, T.Equal:
573 TOK specTok = token.type;
574 nT();
575 switch (token.type)
576 {
577 case T.Typedef,
578 T.Struct,
579 T.Union,
580 T.Class,
581 T.Interface,
582 T.Enum,
583 T.Function,
584 T.Delegate,
585 T.Super,
586 T.Return:
587 specType = new SpecializationType(specTok, token.type);
588 break;
589 default:
590 specType = new SpecializationType(specTok, parseType());
591 }
592 default:
593 }
594
595 e = new IsExpression(type, ident, specType);
563 break; 596 break;
564 case T.LParen: 597 case T.LParen:
565 nT(); 598 nT();
566 e = parseExpression(); 599 e = parseExpression();
567 require(T.RParen); 600 require(T.RParen);
734 continue; 767 continue;
735 case T.LParen: 768 case T.LParen:
736 auto params = parseParameters(); 769 auto params = parseParameters();
737 // new FunctionType(params); 770 // new FunctionType(params);
738 break; 771 break;
772 default:
773 break;
739 } 774 }
740 break; 775 break;
741 } 776 }
742 return t; 777 return t;
743 } 778 }
744 779
745 Type parseDeclarator(ref string ident) 780 Type parseDeclarator(ref string ident, bool identOptional = false)
746 { 781 {
747 auto t = parseBasicType2(parseBasicType()); 782 auto t = parseBasicType2(parseBasicType());
748 783
749 if (token.type == T.Identifier) 784 if (token.type == T.Identifier)
750 { 785 {
751 ident = token.srcText; 786 ident = token.srcText;
752 nT(); 787 nT();
753 } 788 }
754 else 789 else if (!identOptional)
755 errorIfNot(T.Identifier); 790 errorIfNot(T.Identifier);
756 791
757 t = parseDeclaratorSuffix(t); 792 t = parseDeclaratorSuffix(t);
758 return t; 793 return t;
759 } 794 }