public EvaluationName GetName(NamePtg namePtg)
 {
     int ix = namePtg.Index;
     return new Name(_iBook.GetNameRecord(ix), ix);
 }
        /**
         * Generates the variable function ptg for the formula.
         * <p>
         * For IF Formulas, Additional PTGs are Added To the Tokens
         * @param name
         * @param numArgs
         * @return Ptg a null Is returned if we're in an IF formula, it needs extreme manipulation and Is handled in this function
         */
        private ParseNode GetFunction(String name, NamePtg namePtg, ParseNode[] args)
        {

            FunctionMetadata fm = FunctionMetadataRegistry.GetFunctionByName(name.ToUpper());
            int numArgs = args.Length;
            if (fm == null)
            {
                if (namePtg == null)
                {
                    throw new InvalidOperationException("NamePtg must be supplied for external functions");
                }
                // must be external function
                ParseNode[] allArgs = new ParseNode[numArgs + 1];
                allArgs[0] = new ParseNode(namePtg);
                Array.Copy(args, 0, allArgs, 1, numArgs);
                return new ParseNode(new FuncVarPtg(name, (byte)(numArgs + 1)), allArgs);
            }

            if (namePtg != null)
            {
                throw new InvalidOperationException("NamePtg no applicable To internal functions");
            }
            bool IsVarArgs = !fm.HasFixedArgsLength;
            int funcIx = fm.Index;
            ValidateNumArgs(args.Length, fm);

            AbstractFunctionPtg retval;
            if (IsVarArgs)
            {
                retval = new FuncVarPtg(name, (byte)numArgs);
            }
            else
            {
                retval = new FuncPtg(funcIx);
            }
            return new ParseNode(retval, args);
        }
 public String GetNameText(NamePtg namePtg)
 {
     return _iBook.GetNameRecord(namePtg.Index).NameText;
 }
        /**
         * Note - Excel function names are 'case aware but not case sensitive'.  This method may end
         * up creating a defined name record in the workbook if the specified name Is not an internal
         * Excel function, and has not been encountered before.
         *
         * @param name case preserved function name (as it was entered/appeared in the formula).
         */
        private ParseNode function(String name)
        {
            NamePtg nameToken = null;
            // Note regarding parameter -
            if (!AbstractFunctionPtg.IsInternalFunctionName(name))
            {
                // external functions Get a Name Token which points To a defined name record
                nameToken = new NamePtg(name, this.book);

                // in the Token tree, the name Is more or less the first argument
            }

            Match('(');
            ParseNode[] args = Arguments();
            Match(')');

            return GetFunction(name, nameToken, args);
        }