Ejemplo n.º 1
0
        private static FunctionCallNode ParseArguments(ReadParams p, Span funcNameSpan, string funcName, Definition funcDef)
        {
            var funcCallNode  = new FunctionCallNode(p.Statement, funcNameSpan, funcName, funcDef);
            var code          = p.Code;
            var resetPos      = code.Position;
            var commaExpected = false;
            var closed        = false;
            var argIndex      = 0;
            var args          = new List <GroupNode>();
            var argDefs       = funcDef.Arguments.ToArray();

            if (code.ReadExact(')'))
            {
                closed = true;
            }
            else
            {
                while (!code.EndOfFile)
                {
                    if (commaExpected)
                    {
                        if (code.ReadExact(')'))
                        {
                            closed = true;
                            break;
                        }
                        if (!code.ReadExact(','))
                        {
                            code.Position = resetPos;
                            return(null);
                        }
                        commaExpected = false;
                    }
                    else
                    {
                        var argDef = argDefs != null && argIndex < argDefs.Length ? argDefs[argIndex] : null;

                        var arg = ExpressionNode.Read(p, argDef != null ? argDef.DataType : null, ",", ")");
                        if (arg != null)
                        {
                            funcCallNode.AddArgument(arg);
                        }
                        commaExpected = true;
                        argIndex++;
                    }
                }
            }

            if (!closed)
            {
                code.Position = resetPos;
                return(null);
            }

            //if (argDefs.Length != funcCallNode.NumArguments)
            //{
            //	code.Position = resetPos;
            //	return null;
            //}

            return(funcCallNode);
        }