Mercurial > projects > dang
comparison parser/Parser.d @ 158:57b0b4464a0b
Parsing "new", putting it in AST and performs some tests on it. Eg. if the contructor exists and the params matches.
author | Anders Johnsen <skabet@gmail.com> |
---|---|
date | Tue, 22 Jul 2008 00:33:58 +0200 |
parents | 0ea5d2f3e96b |
children | 6cb2f4201e2a |
comparison
equal
deleted
inserted
replaced
157:bb01c1dc452a | 158:57b0b4464a0b |
---|---|
366 switch(peek.type) | 366 switch(peek.type) |
367 { | 367 { |
368 case Tok.This: | 368 case Tok.This: |
369 auto id = Id(next); | 369 auto id = Id(next); |
370 auto m_decl = parseFunc(iden, id, nes[$-1].a); | 370 auto m_decl = parseFunc(iden, id, nes[$-1].a); |
371 action.actOnClassMember(decl, m_decl); | |
371 break; | 372 break; |
372 | 373 |
373 default: | 374 default: |
374 auto m_decl = parseDecl(nes[$-1].a); | 375 auto m_decl = parseDecl(nes[$-1].a); |
375 action.actOnClassMember(decl, m_decl); | 376 action.actOnClassMember(decl, m_decl); |
918 } | 919 } |
919 case Tok.OpenBracket: | 920 case Tok.OpenBracket: |
920 Token open = next(); | 921 Token open = next(); |
921 Exp index = parseExpression(); | 922 Exp index = parseExpression(); |
922 Token close = require(Tok.CloseBracket); | 923 Token close = require(Tok.CloseBracket); |
923 return action.actOnIndexEpr(target, open, index, close); | 924 return action.actOnIndexExpr(target, open, index, close); |
924 default: | 925 default: |
925 return target; | 926 return target; |
926 } | 927 } |
927 } | 928 } |
928 | 929 |
981 return parseCast(n); | 982 return parseCast(n); |
982 else if (n.type == Tok.Integer) | 983 else if (n.type == Tok.Integer) |
983 return action.actOnNumericConstant(n); | 984 return action.actOnNumericConstant(n); |
984 else if (n.type == Tok.String) | 985 else if (n.type == Tok.String) |
985 return action.actOnStringExp(n); | 986 return action.actOnStringExp(n); |
987 else if (n.type == Tok.New) | |
988 { | |
989 Exp[] allocator_args; | |
990 Exp[] constructor_args; | |
991 | |
992 if ( isa(Tok.OpenParentheses)) | |
993 { | |
994 next(); // Remove OpenParentheses | |
995 | |
996 if ( !isa(Tok.CloseParentheses ) ) | |
997 { | |
998 allocator_args ~= parseExpression; | |
999 | |
1000 while ( isa(Tok.Comma) ) | |
1001 { | |
1002 next(); // Remove Comma | |
1003 | |
1004 allocator_args ~= parseExpression; | |
1005 } | |
1006 } | |
1007 require(Tok.CloseParentheses); | |
1008 } | |
1009 | |
1010 auto type = parseType; | |
1011 | |
1012 if ( isa(Tok.OpenParentheses)) | |
1013 { | |
1014 next(); // Remove OpenParentheses | |
1015 | |
1016 if ( !isa(Tok.CloseParentheses ) ) | |
1017 { | |
1018 constructor_args ~= parseExpression; | |
1019 | |
1020 while ( isa(Tok.Comma) ) | |
1021 { | |
1022 next(); // Remove Comma | |
1023 | |
1024 constructor_args ~= parseExpression; | |
1025 } | |
1026 } | |
1027 require(Tok.CloseParentheses); | |
1028 } | |
1029 return action.actOnNewExpr(type, allocator_args, constructor_args); | |
1030 } | |
986 | 1031 |
987 messages.report(ExpectedExp, n.location) | 1032 messages.report(ExpectedExp, n.location) |
988 .fatal(ExitLevel.Parser); | 1033 .fatal(ExitLevel.Parser); |
989 return null; | 1034 return null; |
990 } | 1035 } |