Beispiel #1
0
 protected abstract bool ConsumeNestedQuery(string text, int startIndex, int endIndex, StringView sv, Match match, ICollection <QueryError> errors, TUserData userData);
Beispiel #2
0
        int MatchNestedQuery(string text, int startIndex, int endIndex, ICollection <QueryError> errors, out StringView sv, out Match match, out bool matched)
        {
            sv    = text.GetStringView();
            match = QueryRegexValues.k_NestedQueryRx.Match(text, startIndex, endIndex - startIndex);
            if (!match.Success)
            {
                matched = false;
                return(-1);
            }

            matched = true;
            return(match.Length);
        }
Beispiel #3
0
        int MatchGroup(string text, int groupStartIndex, int endIndex, ICollection <QueryError> errors, out StringView sv, out Match match, out bool matched)
        {
            sv    = text.GetStringView();
            match = null;
            if (groupStartIndex >= text.Length || text[groupStartIndex] != '(')
            {
                matched = false;
                return(-1);
            }

            matched = true;
            if (groupStartIndex < 0 || groupStartIndex >= text.Length)
            {
                errors.Add(new QueryError {
                    index = 0, reason = $"A group should have been found but index was {groupStartIndex}"
                });
                return(-1);
            }

            var charConsumed = 0;

            var parenthesisCounter = 1;
            var groupEndIndex      = groupStartIndex + 1;

            for (; groupEndIndex < text.Length && parenthesisCounter > 0; ++groupEndIndex)
            {
                if (text[groupEndIndex] == '(')
                {
                    ++parenthesisCounter;
                }
                else if (text[groupEndIndex] == ')')
                {
                    --parenthesisCounter;
                }
            }

            // Because of the final ++groupEndIndex, decrement the index
            --groupEndIndex;

            if (parenthesisCounter != 0)
            {
                errors.Add(new QueryError {
                    index = groupStartIndex, reason = $"Unbalanced parenthesis"
                });
                return(-1);
            }

            charConsumed = groupEndIndex - groupStartIndex + 1;
            sv           = text.GetStringView(groupStartIndex + 1, groupStartIndex + charConsumed - 1);
            return(charConsumed);
        }
Beispiel #4
0
        static int MatchCombiningToken(string text, int startIndex, int endIndex, ICollection <QueryError> errors, out StringView sv, out Match match, out bool matched)
        {
            match = null;
            sv    = text.GetStringView();
            var totalUsableLength = endIndex - startIndex;

            foreach (var combiningToken in k_CombiningToken)
            {
                var tokenLength = combiningToken.Length;
                if (tokenLength > totalUsableLength)
                {
                    continue;
                }

                sv = text.GetWordView(startIndex);
                if (sv == combiningToken)
                {
                    matched = true;
                    return(sv.Length);
                }
            }

            matched = false;
            return(-1);
        }
Beispiel #5
0
        static int MatchEmpty(string text, int startIndex, int endIndex, ICollection <QueryError> errors, out StringView sv, out Match match, out bool matched)
        {
            var currentIndex  = startIndex;
            var lengthMatched = 0;

            matched = false;
            while (currentIndex < endIndex && QueryEngineUtils.IsWhiteSpaceChar(text[currentIndex]))
            {
                ++currentIndex;
                ++lengthMatched;
                matched = true;
            }

            sv    = text.GetStringView(startIndex, startIndex + lengthMatched);
            match = null;
            return(lengthMatched);
        }
        int MatchWord(string text, int startIndex, int endIndex, ICollection <QueryError> errors, out StringView sv, out Match match, out bool matched)
        {
            sv    = text.GetStringView();
            match = k_PhraseRx.Match(text, startIndex, endIndex - startIndex);
            if (!match.Success)
            {
                match = k_WordRx.Match(text, startIndex, endIndex - startIndex);
            }
            if (!match.Success)
            {
                matched = false;
                return(-1);
            }

            matched = true;
            return(match.Length);
        }