Exemple #1
0
        private IdentifierSyntax ParseFunctionInvocation()
        {
            if (!PeekAndExpect(TokenType.FunctionInvocation, out string value))
            {
                return(null);
            }

            StartSpan();
            Expect(TokenType.LeftParen);

            _operators.Push(ExpressionSyntax.Sentinel);
            List <ArgumentExpressionSyntax> arguments = new List <ArgumentExpressionSyntax>();

            if (!Peek(TokenType.RightParen))
            {
                StartSpan();
                ArgumentExpressionSyntax ae = SyntaxFactory.ArgumentExpression(GetExpression());
                arguments.Add(ae.SetSpan <ArgumentExpressionSyntax>(EndSpan()));

                while (!Peek(TokenType.RightParen))
                {
                    if (!PeekAndExpect(TokenType.Comma))
                    {
                        Compiler.ReportError(CompilerErrorType.EndOfStatementExpected, PeekSpan());
                        while (!Peek(TokenType.Comma) &&
                               !Peek(TokenType.LeftParen) &&
                               !Peek(TokenType.Identifier) &&
                               !Peek(TokenType.FunctionInvocation) &&
                               !Peek(TokenType.Newline))
                        {
                            Ignore(Current.Type);
                        }
                        _stream.InsertToken(new Token(TokenType.Comma, 1));
                    }
                    else
                    {
                        StartSpan();
                        ae = SyntaxFactory.ArgumentExpression(GetExpression());
                        arguments.Add(ae.SetSpan <ArgumentExpressionSyntax>(EndSpan()));
                    }
                }
            }
            _operators.Pop();

            Expect(TokenType.RightParen);

            List <string> types = new List <string>();

            if (PeekAndExpect(TokenType.Colon))
            {
                ParseType(out string space, out string name, out IList <string> typeHints);
                types.Add(name);
            }

            var f = SyntaxFactory.FunctionInvocation(value, arguments).SetSpan <IdentifierSyntax>(EndSpan());

            f.SetTypeHints(types);
            return(f);
        }