/// <summary> /// Get the function or operator name of this function call /// </summary> public static string GetFunction(this ParseTreeNode input) { if (input.IsIntersection()) { return(GrammarNames.TokenIntersect); } if (input.IsUnion()) { return(GrammarNames.TokenUnionOperator); } if (input.IsBinaryOperation() || input.IsUnaryPostfixOperation()) { return(input.ChildNodes[1].Print()); } if (input.IsUnaryPrefixOperation()) { return(input.ChildNodes[0].Print()); } if (input.IsNamedFunction()) { return(RemoveFinalSymbol(input.ChildNodes[0].Print()).ToUpper()); } if (input.IsExternalUDFunction()) { return($"{input.ChildNodes[0].Print()}{GetFunction(input.ChildNodes[1])}"); } throw new ArgumentException("Not a function call", nameof(input)); }
/// <summary> /// Get all the arguments of a function or operation /// </summary> public static IEnumerable <ParseTreeNode> GetFunctionArguments(this ParseTreeNode input) { if (input.IsNamedFunction()) { return(input .ChildNodes[1] // "Arguments" non-terminal .ChildNodes // "Argument" non-terminals .Select(node => node.ChildNodes[0]) ); } if (input.IsBinaryOperation()) { return(new[] { input.ChildNodes[0], input.ChildNodes[2] }); } if (input.IsUnaryPrefixOperation()) { return(new[] { input.ChildNodes[1] }); } if (input.IsUnaryPostfixOperation()) { return(new[] { input.ChildNodes[0] }); } if (input.IsUnion()) { return(input.ChildNodes[0].ChildNodes); } if (input.IsExternalUDFunction()) { return(input // Reference .ChildNodes[1] // UDFunctionCall .ChildNodes[1] // Arguments .ChildNodes // Argument non-terminals .Select(node => node.ChildNodes[0]) ); } throw new ArgumentException("Not a function call", nameof(input)); }