Пример #1
0
        internal sealed override InternalResult <Unit> Parse(ref ParseState <TToken> state)
        {
            var startingLocation = state.Location;
            var token            = state.HasCurrent ? Maybe.Just(state.Current) : Maybe.Nothing <TToken>();

            state.PushBookmark();  // make sure we don't throw out the buffer, we may need it to compute a SourcePos
            state.BeginExpectedTran();
            var result = _parser.Parse(ref state);

            state.EndExpectedTran(false);
            state.PopBookmark();
            if (result.Success)
            {
                state.Error = new InternalError <TToken>(
                    token,
                    false,
                    startingLocation,
                    null
                    );
                return(InternalResult.Failure <Unit>(result.ConsumedInput));
            }

            return(InternalResult.Success(
                       Unit.Value,
                       result.ConsumedInput
                       ));
        }
Пример #2
0
        internal sealed override bool TryParse(ref ParseState <TToken> state, ref ExpectedCollector <TToken> expecteds, out Unit result)
        {
            var startingLocation = state.Location;
            var token            = state.HasCurrent ? Maybe.Just(state.Current) : Maybe.Nothing <TToken>();

            state.PushBookmark();  // make sure we don't throw out the buffer, we may need it to compute a SourcePos
            var childExpecteds = new ExpectedCollector <TToken>(true);

            var success = _parser.TryParse(ref state, ref childExpecteds, out var result1);

            childExpecteds.Dispose();
            state.PopBookmark();

            if (success)
            {
                state.Error = new InternalError <TToken>(
                    token,
                    false,
                    startingLocation,
                    null
                    );
                result = default;
                return(false);
            }

            result = Unit.Value;
            return(true);
        }
Пример #3
0
            internal override InternalResult <U> Parse(ref ParseState <TToken> state)
            {
                var start = state.Location;

                state.PushBookmark();  // don't discard input buffer
                var result = _parser.Parse(ref state);


                if (!result.Success)
                {
                    state.PopBookmark();
                    return(InternalResult.Failure <U>(result.ConsumedInput));
                }


                var delta = state.Location - start;
                var val   = _selector(state.LookBehind(delta), result.Value);

                state.PopBookmark();

                return(InternalResult.Success <U>(val, result.ConsumedInput));
            }
Пример #4
0
            internal override InternalResult <T> Parse(ref ParseState <TToken> state)
            {
                state.PushBookmark();

                var result = _parser.Parse(ref state);

                if (result.Success)
                {
                    state.Rewind();
                    return(InternalResult.Success <T>(result.Value, false));
                }
                state.PopBookmark();
                return(result);
            }
Пример #5
0
        internal sealed override bool TryParse(ref ParseState <TToken> state, ref ExpectedCollector <TToken> expecteds, out U result)
        {
            var start = state.Location;

            state.PushBookmark();  // don't discard input buffer
            var success = _parser.TryParse(ref state, ref expecteds, out var result1);

            if (!success)
            {
                state.PopBookmark();
                result = default;
                return(false);
            }


            var delta = state.Location - start;

            result = _selector(state.LookBehind(delta), result1);

            state.PopBookmark();

            return(true);
        }
Пример #6
0
        internal sealed override bool TryParse(ref ParseState <TToken> state, ref ExpectedCollector <TToken> expecteds, out T result)
        {
            state.PushBookmark();

            var success = _parser.TryParse(ref state, ref expecteds, out result);

            if (success)
            {
                state.Rewind();
                return(true);
            }
            state.PopBookmark();
            return(success);
        }
Пример #7
0
            internal sealed override InternalResult <T> Parse(ref ParseState <TToken> state)
            {
                // start buffering the input
                state.PushBookmark();
                var result = _parser.Parse(ref state);

                if (!result.Success)
                {
                    // return to the start of the buffer and discard the bookmark
                    state.Rewind();
                    return(InternalResult.Failure <T>(false));
                }

                // discard the buffer
                state.PopBookmark();
                return(result);
            }
Пример #8
0
        internal sealed override bool TryParse(ref ParseState <TToken> state, ref ExpectedCollector <TToken> expecteds, out T result)
        {
            // start buffering the input
            state.PushBookmark();
            var success = _parser.TryParse(ref state, ref expecteds, out result);

            if (!success)
            {
                // return to the start of the buffer and discard the bookmark
                state.Rewind();
                return(false);
            }

            // discard the buffer
            state.PopBookmark();
            return(true);
        }