Exemple #1
0
    private static void TestRange(RegexContext context, SequenceBuffer <char> buffer)
    {
        var backtrackState = new BacktrackState(true, context.CurrentState);
        int j = 0;

        while (true)
        {
            if (buffer.IsPastEnd(context.Index))
            {
                backtrackState.AddZeroConsumed();
                context.Push(backtrackState);
                context.MoveToNextState();
                break;
            }

            var(matches, consumed) = MatchStateHere(context.CurrentState, buffer, context.Index);
            if (!matches || consumed == 0)
            {
                backtrackState.AddZeroConsumed();
                context.Push(backtrackState);
                context.MoveToNextState();
                break;
            }

            backtrackState.AddConsumption(consumed);
            context.AdvanceIndex(consumed);
            j++;
            if (j >= context.CurrentState.Maximum)
            {
                context.MoveToNextState();
                break;
            }
        }
    }
Exemple #2
0
    private static void TestZeroOrOne(RegexContext context, SequenceBuffer <char> buffer)
    {
        if (buffer.IsPastEnd(context.Index))
        {
            context.Push(new BacktrackState(false, context.CurrentState, 0));
            context.MoveToNextState();
            return;
        }

        var(matches, consumed) = MatchStateHere(context.CurrentState, buffer, context.Index);
        context.Push(new BacktrackState(matches && consumed > 0, context.CurrentState, consumed));
        context.AdvanceIndex(consumed);
        context.MoveToNextState();
    }
Exemple #3
0
    private static bool TestExactlyOne(RegexContext context, SequenceBuffer <char> buffer)
    {
        var(matches, consumed) = MatchStateHere(context.CurrentState, buffer, context.Index);
        if (matches)
        {
            context.Push(new BacktrackState(false, context.CurrentState, consumed));
            context.AdvanceIndex(consumed);
            context.MoveToNextState();
            return(true);
        }

        var couldBacktrack = context.Backtrack();

        if (couldBacktrack)
        {
            return(true);
        }
        return(false);
    }