Exemplo n.º 1
0
        internal override string Generate(MatcherEngineGenerator generator)
        {
            string methodName = $"MatchCountBounds{_id}";
            string method     = $"{methodName}({{0}}, {{1}})";

            if (!generator.TryGetMethod(methodName, ref method))
            {
                generator.Add(methodName, method);
                string code = $@"private (bool success, int offset) {methodName}(string text, int startOffset)
        {{
			int offset = startOffset;
			bool subSuccess = true;
			int subOffset;
			int matches = 0;
			for (; matches < {_upperBounds} && subSuccess; matches++)
			{{
				(subSuccess, subOffset) = {string.Format(_subPattern.Generate(generator), "text", "offset")};
				offset += subOffset;
            }}
			bool success = subSuccess || matches >= {_lowerBounds};
            return success ? (true, offset - startOffset) : (false, 0);
        }}";
                method = generator.Add(method, methodName, code);
            }
            return(method);
        }
Exemplo n.º 2
0
        internal override string Generate(MatcherEngineGenerator generator)
        {
            string methodName = $"MatchOneOrMore{_id}";
            string method     = $"{methodName}({{0}}, {{1}})";

            if (!generator.TryGetMethod(methodName, ref method))
            {
                generator.Add(methodName, method);
                string code = $@"private (bool success, int offset) {methodName}(string text, int startOffset)
        {{
            int offset = startOffset;
            bool subSuccess = true;
            bool success = false;
            int subOffset;
            while (subSuccess)
            {{
                (subSuccess, subOffset) = {string.Format(_subPattern.Generate(generator), "text", "offset")};
                offset += subOffset;
                success |= subSuccess;
            }}
            return success ? (true, offset - startOffset) : (false, 0);
        }}";
                method = generator.Add(method, methodName, code);
            }
            return(method);
        }
Exemplo n.º 3
0
        internal override string Generate(MatcherEngineGenerator generator)
        {
            string methodName = $"MatchWholeWord{_id}";
            string method     = $"{methodName}({{0}}, {{1}})";

            if (!generator.TryGetMethod(methodName, ref method))
            {
                generator.Add(methodName, method);
                string code = $@"private (bool success, int offset) {methodName}(string text, int startOffset)
        {{
            if (startOffset - 1 >= 0 && char.IsLetterOrDigit(text[startOffset - 1]))
            {{
                return (false, 0);
            }}

            (bool success, int offset) = {string.Format(_subPattern.Generate(generator), "text", "startOffset")};

            int next = startOffset + offset;
            if (success && next < text.Length && char.IsLetterOrDigit(text[next]))
            {{
                return (false, 0);
            }}
            return (success, offset);
        }}";
                method = generator.Add(method, methodName, code);
            }
            return(method);
        }
Exemplo n.º 4
0
        internal override string Generate(MatcherEngineGenerator generator)
        {
            string methodName = $"MatchNot{_id}";
            string method     = $"{methodName}({{0}}, {{1}})";

            if (!generator.TryGetMethod(methodName, ref method))
            {
                generator.Add(methodName, method);
                string code = $@"private (bool success, int offset) {methodName}(string text, int startOffset)
        {{
            return text.Length > startOffset && !{string.Format(_subPattern.Generate(generator), "text", "startOffset")}.success ? (true, 0) : (false, 0);
        }}";
                method = generator.Add(method, methodName, code);
            }
            return(method);
        }
Exemplo n.º 5
0
 internal override string Generate(MatcherEngineGenerator generator) => _subPattern.Generate(generator);