internal Result(bool consumedInput, T value) { Success = true; ConsumedInput = consumedInput; _value = value; _error = default(ParseError <TToken>); }
internal Result(bool consumedInput, ParseError <TToken> error) { Success = false; ConsumedInput = consumedInput; _value = default(T); _error = error; }
internal sealed override InternalResult <T> Parse(ref ParseState <TToken> state) { var firstTime = true; var err = new ParseError <TToken>( Maybe.Nothing <TToken>(), false, Expected, state.SourcePos, "OneOf had no arguments" ); InternalResult <T> failureResult = InternalResult.Failure <T>(false); foreach (var p in _parsers) { var thisResult = p.Parse(ref state); // we'll usually return the error from the first parser that didn't backtrack, // even if other parsers had a longer match. // There is some room for improvement here. if (thisResult.Success || thisResult.ConsumedInput) { return(thisResult); } // choose the longest match, preferring the left-most error in a tie, // except the first time (avoid returning "OneOf had no arguments"). if (firstTime || state.Error.ErrorPos > err.ErrorPos) { failureResult = thisResult; err = state.Error; } firstTime = false; } state.Error = err.WithExpected(Expected); return(failureResult); }
public ParseState(Func <TToken, SourcePos, SourcePos> posCalculator, ITokenStream <TToken> stream) { _posCalculator = posCalculator; _bookmarks = new Stack <Bookmark>(); _stream = stream; _consumedCount = 0; _hasCurrent = false; SourcePos = new SourcePos(1, 1); Error = default; }
/// <inheritdoc/> public bool Equals(ParseError <TToken> other) => this.Unexpected.Equals(other.Unexpected) && this.EOF == other.EOF && (this.Expected == null && other.Expected == null || this.Expected.SequenceEqual(other.Expected)) && this.ErrorPos.Equals(other.ErrorPos) && object.Equals(this.Message, other.Message);
internal static Result <TToken, T> Failure <TToken, T>( ParseError <TToken> error, bool consumedInput ) => new Result <TToken, T>(error, consumedInput);
public bool Equals(ParseError <TToken> other) => this.Unexpected.Equals(other.Expected) && this.EOF == other.EOF && object.Equals(this.Expected, other.Expected) && this.ErrorPos.Equals(other.ErrorPos) && object.Equals(this.Message, other.Message);