private Expression ParseCallExpression(bool isNew) { Expression ret = ParseMemberExpression(); if (ret == null) return ret; var start = ret.StartIndex; while (MaybeEat(TokenKind.LeftParenthesis)) { List<Arg> arguments = new List<Arg>(); if (!MaybeEat(TokenKind.RightParenthesis)) { do { arguments.Add(ParseArg()); } while (MaybeEat(TokenKind.Comma)); Eat(TokenKind.RightParenthesis); } ret = new CallExpression(ret, arguments.ToArray()); ret.SetLoc(_globalParent, start, GetEnd()); } return ret; }
private Expression ParseCallOrMemberTail(Expression ret) { while (true) { if (MaybeEat(TokenKind.LeftParenthesis)) { List<Arg> arguments = new List<Arg>(); if (!MaybeEat(TokenKind.RightParenthesis)) { do { arguments.Add(ParseArg()); } while (MaybeEat(TokenKind.Comma)); Eat(TokenKind.RightParenthesis); } ret = new CallExpression(ret, arguments.ToArray()); ret.SetLoc(_globalParent, ret.StartIndex, GetEnd()); } else if (MaybeEat(TokenKind.Dot)) { ret = new MemberExpression(ret, ((NameToken)NextToken()).Name); ret.SetLoc(_globalParent, ret.StartIndex, GetEnd()); } else if (MaybeEat(TokenKind.LeftBracket)) { ret = new IndexExpression(ret, new[] { ParseExpression() }); // TODO: make possible with multiple indexes ret.SetLoc(_globalParent, ret.StartIndex, GetEnd()); Eat(TokenKind.RightBracket); } else return ret; } }
private CallExpression ParseSingleCall(Expression target) { Eat(TokenKind.LeftParenthesis); List<Arg> arguments = new List<Arg>(); if (!MaybeEat(TokenKind.RightParenthesis)) { do { arguments.Add(ParseArg()); } while (MaybeEat(TokenKind.Comma)); Eat(TokenKind.RightParenthesis); } var ret = new CallExpression(target, arguments.ToArray()); ret.SetLoc(_globalParent, target.StartIndex, GetEnd()); return ret; }