Esempio n. 1
0
        public static FunctionParametersNode Parameters(ParameterNode[] parameters)
        {
            // if (parameters)

            var result = new FunctionParametersNode(_nodeIndex++);

            foreach (var p in parameters)
            {
                result.AddChild(p);
            }

            return(result);
        }
Esempio n. 2
0
        public static FunctionParametersNode Parameters(AstNode parameters)
        {
            // if (parameters)
            var r = parameters as FunctionParametersNode;

            if (r != null)
            {
                return(r);
            }

            var result = new FunctionParametersNode(_nodeIndex++);
            var count  = parameters.Children.Count;

            for (int i = 0; i < count; i += 2)
            {
                var type    = parameters[i];
                var isArray = parameters[i + 1].Kind == SyntaxKind.ArrayIndexExpression;
                if (isArray)
                {
                    type.Value += "[]";
                    i++;
                }

                var name = parameters[i + 1];
                result.AddChild(AstNode.Parameter(name, type));

                if (count > 2 && i + 2 < count)
                {
                    var value = parameters[i + 2].Value;
                    if (value?.ToString() != ",")
                    {
                        throw new ExpressionException($"Unexpected character '{value}' found in function parameter declaration");
                    }
                    i++; // skip separator
                }
            }

            return(result);
        }