Example #1
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);
        }
Example #2
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);
            }
            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));
            }
Example #4
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);
        }