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); 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); }
// see comment about expecteds in ParseState.Error.cs internal sealed override bool TryParse(ref ParseState <TToken> state, ref ExpectedCollector <TToken> expecteds, out T result) { var childExpecteds = new ExpectedCollector <TToken>(); var success = _parser.TryParse(ref state, ref childExpecteds, out result); if (success) { childExpecteds.Dispose(); return(true); } var recoverParser = _errorHandler(state.BuildError(ref childExpecteds)); childExpecteds.Dispose(); return(recoverParser.TryParse(ref state, ref expecteds, out result)); }
// see comment about expecteds in ParseState.Error.cs internal override InternalResult <T> Parse(ref ParseState <TToken> state) { state.BeginExpectedTran(); var result = _parser.Parse(ref state); if (result.Success) { state.EndExpectedTran(false); return(result); } var parserExpecteds = state.ExpectedTranState(); state.EndExpectedTran(false); var recoverParser = _errorHandler(state.BuildError(parserExpecteds.AsEnumerable())); parserExpecteds.Dispose(clearArray: true); return(recoverParser.Parse(ref state)); }