/// <summary> /// Checks whether this node is a function call with name, and not just a unary or binary operation /// </summary> public static bool IsNamedFunction(this ParseTreeNode input) { return((input.Is(GrammarNames.FunctionCall) && input.ChildNodes.Exists(pt => pt.Term.Name == GrammarNames.Function)) || input.Is(GrammarNames.ReferenceFunction) // User defined function with prefix || (input.Is(GrammarNames.Reference) && input.ChildNodes.Count == 3 && input.ChildNodes[2].Is(GrammarNames.Arguments))); }
/// <summary> /// Get the function or operator name of this function call /// </summary> public static string GetFunction(this ParseTreeNode input) { if (IsIntersection(input)) { return(GrammarNames.TokenIntersect); } if (IsBinaryOperation(input) || IsUnaryPostfixOperation(input)) { return(input.ChildNodes[1].Print()); } if (IsUnaryPrefixOperation(input)) { return(input.ChildNodes[0].Print()); } if (input.Is(GrammarNames.ReferenceFunction) || input.Is(GrammarNames.FunctionCall)) { return(RemoveFinalSymbol(input.ChildNodes[0].Print()).ToUpper()); } if (input.Is(GrammarNames.Reference)) { if (input.ChildNodes.Count == 3 && input.ChildNodes[2].Is(GrammarNames.Arguments)) { return(RemoveFinalSymbol(input.ChildNodes[1].Print()).ToUpper()); } } throw new ArgumentException("Not a function call", "input"); }
/// <summary> /// Checks whether this node is a function /// </summary> public static Boolean IsFunction(this ParseTreeNode input) { return(input.Is(GrammarNames.FunctionCall) || input.Is(GrammarNames.ReferenceFunctionCall) || input.Is(GrammarNames.UDFunctionCall) // This gives potential problems/duplication on external UDFs, but they are so rare that I think this is acceptable || (input.Is(GrammarNames.Reference) && input.ChildNodes.Count == 2 && input.ChildNodes[1].IsFunction()) ); }
private static ParseTreeNode MoveTo(ParseTreeNode pt, Context old, Context _new) { if (pt.Is(GrammarNames.Reference)) { return(_new.QualifyMinimal(old.Qualify(pt))); } return(pt.ChildNodes.Count == 0 ? pt : CustomParseTreeNode.From(pt).SetChildNodes(pt.ChildNodes.Select(x => MoveTo(x, old, _new)))); }
/// <summary> /// Go to the first non-formula child node /// </summary> public static ParseTreeNode SkipFormula(this ParseTreeNode input) { while (input.Is(GrammarNames.Formula)) { input = input.ChildNodes.First(); } return(input); }
private static IEnumerable <ParseTreeNode> CellContainedInRanges(ParseTreeNode fqcellref, ContextNode formula) { if (!fqcellref.Is(GrammarNames.Reference) || !fqcellref.ChildNodes[1].Is(GrammarNames.Cell)) { throw new ArgumentException("Must be a reference to a single cell", nameof(fqcellref)); } return(CellContainedInRanges(fqcellref, formula.Node, formula.Ctx)); }
/// <summary>Tests whether this </summary> private static bool isArgumentArray(ParseTreeNode n) { if (!n.Is(GrammarNames.Arguments)) { return(false); } return(false); }
/// <summary> /// Whether or not this node represents an union /// </summary> public static bool IsUnion(this ParseTreeNode input) { try { return(input.Is(GrammarNames.ReferenceFunctionCall) && input.ChildNodes[0].Is(GrammarNames.Union)); } catch (Exception) { return(false); } }
/// <summary> /// Depth of nested formulas /// </summary> private static int Depth(ParseTreeNode node) { // Get the maximum depth of the childnodes int depth = node.ChildNodes.Count == 0 ? 0 : node.ChildNodes.Max(n => Depth(n)); // If this is a formula node, add one to the depth if (node.Is(GrammarNames.Formula)) { depth++; } return(depth); }
private static bool isPrefixableReference(ParseTreeNode reference) { // No qualifying to do if it's not a reference if (!reference.Is(GrammarNames.Reference)) { return(false); } // No qualifying to do if it's a Functioncall or dynamic data exchange var relevant = reference.SkipToRelevant(); var child = relevant.ChildNodes.Count > 0 ? relevant.ChildNodes[0] : null; if ((child?.IsFunction() ?? false) || (child?.Is(GrammarNames.DynamicDataExchange) ?? false)) { return(false); } return(true); }
/// <summary> /// Depth of nested formulas /// </summary> private static int Depth(ParseTreeNode node) { // Get the maximum depth of the childnodes int depth = node.ChildNodes.Count == 0 ? 0 : node.ChildNodes.Max(n => Depth(n)); // If this is a formula node, add one to the depth if (node.Is(GrammarNames.Formula)) { depth++; } return depth; }
public static bool IsExternalUDFunction(this ParseTreeNode input) { return(input.Is(GrammarNames.Reference) && input.ChildNodes.Count == 2 && input.ChildNodes[1].IsNamedFunction()); }
/// <summary> /// Checks whether this node is a function call with name, and not just a unary or binary operation /// </summary> public static bool IsNamedFunction(this ParseTreeNode input) { return((input.Is(GrammarNames.FunctionCall) && input.ChildNodes[0].Is(GrammarNames.FunctionName)) || (input.Is(GrammarNames.ReferenceFunctionCall) && input.ChildNodes[0].Is(GrammarNames.RefFunctionName)) || input.Is(GrammarNames.UDFunctionCall)); }
/// <summary> /// Whether or not this node represents an union /// </summary> public static bool IsUnion(this ParseTreeNode input) { return(input.Is(GrammarNames.ReferenceFunctionCall) && input.ChildNodes.Count == 1 && input.ChildNodes[0].Is(GrammarNames.Union)); }
public static bool IsBinaryReferenceOperation(this ParseTreeNode input) { return(input.IsBinaryOperation() && input.Is(GrammarNames.ReferenceFunctionCall)); }
public static bool IsBinaryOperation(this ParseTreeNode input) { return((input.Is(GrammarNames.FunctionCall) || input.Is(GrammarNames.Reference)) && input.ChildNodes.Count() == 3 && input.ChildNodes[1].Term.Flags.HasFlag(TermFlags.IsOperator)); }
public static bool IsUnaryPostfixOperation(this ParseTreeNode input) { return(input.Is(GrammarNames.FunctionCall) && input.ChildNodes.Count() == 2 && input.ChildNodes[1].Term.Flags.HasFlag(TermFlags.IsOperator)); }
/// <summary> /// Checks whether this node is a built-in excel function /// </summary> public static bool IsBuiltinFunction(this ParseTreeNode node) { return(node.IsFunction() && (node.Is(GrammarNames.ExcelFunction) || node.Is(GrammarNames.ReferenceFunction))); }