Exemple #1
0
 public Filter(AstNode input, AstNode condition)
 {
     _input     = input;
     _condition = condition;
 }
Exemple #2
0
        private AstNode ParseMethod(AstNode qyInput)
        {
            List <AstNode> argList = new List <AstNode>();
            string         name    = _scanner.Name;
            string         prefix  = _scanner.Prefix;

            PassToken(XPathScanner.LexKind.Name);
            PassToken(XPathScanner.LexKind.LParens);
            if (_scanner.Kind != XPathScanner.LexKind.RParens)
            {
                do
                {
                    argList.Add(ParseExpression(qyInput));
                    if (_scanner.Kind == XPathScanner.LexKind.RParens)
                    {
                        break;
                    }
                    PassToken(XPathScanner.LexKind.Comma);
                } while (true);
            }
            PassToken(XPathScanner.LexKind.RParens);
            if (prefix.Length == 0)
            {
                ParamInfo pi;
                if (s_functionTable.TryGetValue(name, out pi))
                {
                    int argCount = argList.Count;
                    if (argCount < pi.Minargs)
                    {
                        throw XPathException.Create(SR.Xp_InvalidNumArgs, name, _scanner.SourceText);
                    }
                    if (pi.FType == Function.FunctionType.FuncConcat)
                    {
                        for (int i = 0; i < argCount; i++)
                        {
                            AstNode arg = (AstNode)argList[i];
                            if (arg.ReturnType != XPathResultType.String)
                            {
                                arg = new Function(Function.FunctionType.FuncString, arg);
                            }
                            argList[i] = arg;
                        }
                    }
                    else
                    {
                        if (pi.Maxargs < argCount)
                        {
                            throw XPathException.Create(SR.Xp_InvalidNumArgs, name, _scanner.SourceText);
                        }
                        if (pi.ArgTypes.Length < argCount)
                        {
                            argCount = pi.ArgTypes.Length;    // argument we have the type specified (can be < pi.Minargs)
                        }
                        for (int i = 0; i < argCount; i++)
                        {
                            AstNode arg = (AstNode)argList[i];
                            if (
                                pi.ArgTypes[i] != XPathResultType.Any &&
                                pi.ArgTypes[i] != arg.ReturnType
                                )
                            {
                                switch (pi.ArgTypes[i])
                                {
                                case XPathResultType.NodeSet:
                                    if (!(arg is Variable) && !(arg is Function && arg.ReturnType == XPathResultType.Any))
                                    {
                                        throw XPathException.Create(SR.Xp_InvalidArgumentType, name, _scanner.SourceText);
                                    }
                                    break;

                                case XPathResultType.String:
                                    arg = new Function(Function.FunctionType.FuncString, arg);
                                    break;

                                case XPathResultType.Number:
                                    arg = new Function(Function.FunctionType.FuncNumber, arg);
                                    break;

                                case XPathResultType.Boolean:
                                    arg = new Function(Function.FunctionType.FuncBoolean, arg);
                                    break;
                                }
                                argList[i] = arg;
                            }
                        }
                    }
                    return(new Function(pi.FType, argList));
                }
            }
            return(new Function(prefix, name, argList));
        }
Exemple #3
0
 public Function(FunctionType ftype, AstNode arg)
 {
     functionType = ftype;
     argumentList = new List <AstNode>();
     argumentList.Add(arg);
 }