internal static SearchExpression ExpressionSetParser(SearchExpressionParserArgs args) { var outerText = args.text; if (outerText.length < 2) { return(null); } var innerText = ParserUtils.SimplifyExpression(outerText, false); if (outerText.length == innerText.length) { return(null); } var text = outerText.Substring(innerText.startIndex - outerText.startIndex - 1, innerText.length + 2); if (text[0] != '{' || text[text.length - 1] != '}') { return(null); } var expressions = ParserUtils.GetExpressionsStartAndLength(innerText, out var rootHasParameters); if (!rootHasParameters) { return(null); } var parameters = ParserUtils.ExtractArguments(text) .Select(paramText => ParserManager.Parse(args.With(paramText).Without(SearchExpressionParserFlags.ImplicitLiterals))) .ToArray(); return(new SearchExpression(SearchExpressionType.Set, outerText, innerText.Trim(), SetEvaluator, parameters)); }
internal static SearchExpression QueryParser(SearchExpressionParserArgs args) { var text = ParserUtils.SimplifyExpression(args.text); var nestedExpressions = new List <SearchExpression>(); var expressionsStartAndLength = ParserUtils.GetExpressionsStartAndLength(text, out _); var lastExpressionEndIndex = 0; foreach (var expression in expressionsStartAndLength) { string exprName = string.Empty; if (expression[0] == '{') { var namedText = text.Substring(lastExpressionEndIndex, expression.startIndex - text.startIndex + 1 - lastExpressionEndIndex).ToString(); var match = ParserUtils.namedExpressionStartRegex.Match(namedText); if (match != null && match.Success && match.Groups["name"].Value != string.Empty) { exprName = match.Groups["name"].Value; } } var paramText = args.With(text.Substring(expression.startIndex - text.startIndex - exprName.Length, expression.length + exprName.Length)); var nestedExpression = ParserManager.Parse(paramText); nestedExpressions.Add(nestedExpression); lastExpressionEndIndex = expression.startIndex + expression.length; } return(new SearchExpression(SearchExpressionType.QueryString, args.text, text, QueryEvaluator, nestedExpressions.ToArray())); }
internal static SearchExpression NamedParser(SearchExpressionParserArgs args) { var text = ParserUtils.SimplifyExpression(args.text); if (text.IsNullOrEmpty()) { return(null); } var match = ParserUtils.namedExpressionStartRegex.Match(text.ToString()); if (!match.Success || match.Index != 0 || match.Groups["name"].Length == 0) { return(null); } var expressionsStartAndLength = ParserUtils.GetExpressionsStartAndLength(text, out _); if (expressionsStartAndLength.Length != 1) { return(null); } var expressionName = match.Groups["name"].Value; if ((expressionName.Length + expressionsStartAndLength[0].length) != text.length) { return(null); } var evaluator = EvaluatorManager.GetEvaluatorByNameDuringParsing(expressionName, text.Substring(0, expressionName.Length)); var parametersText = text.Substring(expressionName.Length, text.length - expressionName.Length); var parametersPositions = ParserUtils.ExtractArguments(parametersText, expressionName); var parameters = new List <SearchExpression>(); var argsWith = SearchExpressionParserFlags.None; var argsWithout = SearchExpressionParserFlags.ImplicitLiterals; ApplyEvaluatorHints(evaluator.hints, ref argsWith, ref argsWithout); foreach (var paramText in parametersPositions) { parameters.Add(ParserManager.Parse(args.With(paramText, argsWith).Without(argsWithout))); } if (!evaluator.hints.HasFlag(SearchExpressionEvaluationHints.DoNotValidateSignature) && args.HasOption(SearchExpressionParserFlags.ValidateSignature)) { var signatures = EvaluatorManager.GetSignaturesByName(expressionName); if (signatures != null) { SearchExpressionValidator.ValidateExpressionArguments(evaluator, parameters.ToArray(), signatures, text); } } var expressionText = ParserUtils.SimplifyExpression(expressionsStartAndLength[0].Substring(1, expressionsStartAndLength[0].length - 2)); return(new SearchExpression(SearchExpressionType.Function, args.text, expressionText, evaluator, parameters.ToArray())); }
internal static SearchExpression SelectorParser(StringView outerText) { var text = ParserUtils.SimplifyExpression(outerText); if (!s_SelectorPattern.IsMatch(text.ToString())) { return(null); } return(new SearchExpression(SearchExpressionType.Selector, outerText, text.Substring(1), s_SelectorEvaluator)); }
internal static SearchExpression BooleanParser(StringView text) { var trimmedText = ParserUtils.SimplifyExpression(text); if (!bool.TryParse(trimmedText.ToString(), out _)) { return(null); } return(new SearchExpression(SearchExpressionType.Boolean, text, trimmedText, ConstantEvaluator)); }
internal static SearchExpression NumberParser(StringView outerText) { var trimmedText = ParserUtils.SimplifyExpression(outerText); if (!Utils.TryParse(trimmedText.ToString(), out double _)) { return(null); } SearchExpressionType types = SearchExpressionType.Number; if (trimmedText == "0" || trimmedText == "1") { types |= SearchExpressionType.Boolean; } return(new SearchExpression(types, outerText, trimmedText, ConstantEvaluator)); }
internal static SearchExpression ExplicitStringParser(SearchExpressionParserArgs args) { var outerText = args.text; var text = ParserUtils.SimplifyExpression(outerText); if (text.length < 2 || !ParserUtils.HasQuotes(text)) { return(null); } // Check for any string, since enclosed strings are not allowed, if we find a string token that means there are multiple strings in the text for (int i = 1; i < text.length - 2; ++i) { if (ParserUtils.IsQuote(text[i])) { return(null); } } return(new SearchExpression(SearchExpressionType.Text, outerText, text.Substring(1, text.length - 2), ConstantEvaluator)); }
internal static SearchExpression FixedSetParser(SearchExpressionParserArgs args) { var outerText = args.text; var text = ParserUtils.SimplifyExpression(outerText); if (text.length < 2 || text[0] != '[' || text[text.length - 1] != ']') { return(null); } var expressions = ParserUtils.GetExpressionsStartAndLength(text, out _); if (expressions.Length != 1 || expressions[0].startIndex != text.startIndex || expressions[0].length != text.length) { return(null); } var parameters = ParserUtils.ExtractArguments(text) .Select(paramText => ParserManager.Parse(args.With(paramText).With(SearchExpressionParserFlags.ImplicitLiterals))) .ToArray(); var innerText = ParserUtils.SimplifyExpression(text.Substring(1, text.length - 2)); return(new SearchExpression(SearchExpressionType.Set, outerText, innerText, SetEvaluator, parameters)); }