Mercurial > projects > dang
diff 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 |
line wrap: on
line diff
--- a/parser/Parser.d Mon Jul 21 22:14:06 2008 +0200 +++ b/parser/Parser.d Tue Jul 22 00:33:58 2008 +0200 @@ -368,6 +368,7 @@ case Tok.This: auto id = Id(next); auto m_decl = parseFunc(iden, id, nes[$-1].a); + action.actOnClassMember(decl, m_decl); break; default: @@ -920,7 +921,7 @@ Token open = next(); Exp index = parseExpression(); Token close = require(Tok.CloseBracket); - return action.actOnIndexEpr(target, open, index, close); + return action.actOnIndexExpr(target, open, index, close); default: return target; } @@ -983,6 +984,50 @@ return action.actOnNumericConstant(n); else if (n.type == Tok.String) return action.actOnStringExp(n); + else if (n.type == Tok.New) + { + Exp[] allocator_args; + Exp[] constructor_args; + + if ( isa(Tok.OpenParentheses)) + { + next(); // Remove OpenParentheses + + if ( !isa(Tok.CloseParentheses ) ) + { + allocator_args ~= parseExpression; + + while ( isa(Tok.Comma) ) + { + next(); // Remove Comma + + allocator_args ~= parseExpression; + } + } + require(Tok.CloseParentheses); + } + + auto type = parseType; + + if ( isa(Tok.OpenParentheses)) + { + next(); // Remove OpenParentheses + + if ( !isa(Tok.CloseParentheses ) ) + { + constructor_args ~= parseExpression; + + while ( isa(Tok.Comma) ) + { + next(); // Remove Comma + + constructor_args ~= parseExpression; + } + } + require(Tok.CloseParentheses); + } + return action.actOnNewExpr(type, allocator_args, constructor_args); + } messages.report(ExpectedExp, n.location) .fatal(ExitLevel.Parser);