private static Result <TToken, T> DoParse <TToken, T>(Parser <TToken, T> parser, ref ParseState <TToken> state) { var internalResult = parser.Parse(ref state); var result = internalResult.Success ? new Result <TToken, T>(internalResult.ConsumedInput, internalResult.Value) : new Result <TToken, T>(internalResult.ConsumedInput, state.BuildError()); state.Dispose(); // ensure we return the state's buffers to the buffer pool return(result); }
private static Result <TToken, T> DoParse <TToken, T>(Parser <TToken, T> parser, ITokenStream <TToken> stream, Func <TToken, SourcePos, SourcePos> calculatePos) { var state = new ParseState <TToken>(calculatePos, stream); state.Advance(); // pull the first element from the input var result = parser.Parse(ref state); state.Dispose(); // ensure we return the state's buffer to the buffer pool return(result.Success ? new Result <TToken, T>(result.ConsumedInput, result.Value) : new Result <TToken, T>(result.ConsumedInput, state.Error)); }
private static Result <TToken, T> DoParse <TToken, T>(Parser <TToken, T> parser, ITokenStream <TToken> stream, Func <TToken, SourcePos, SourcePos> calculatePos) { var state = new ParseState <TToken>(calculatePos, stream); var internalResult = parser.Parse(ref state); var result = internalResult.Success ? new Result <TToken, T>(internalResult.ConsumedInput, internalResult.Value) : new Result <TToken, T>(internalResult.ConsumedInput, state.BuildError()); state.Dispose(); // ensure we return the state's buffers to the buffer pool return(result); }
private static Result <TToken, T> DoParse <TToken, T>(Parser <TToken, T> parser, ref ParseState <TToken> state) { var startingLoc = state.Location; var expecteds = new ExpectedCollector <TToken>(); var success = parser.TryParse(ref state, ref expecteds, out var result); var result1 = success ? new Result <TToken, T>(state.Location > startingLoc, result) : new Result <TToken, T>(state.Location > startingLoc, state.BuildError(ref expecteds)); expecteds.Dispose(); state.Dispose(); // ensure we return the state's buffers to the buffer pool return(result1); }