コード例 #1
0
ファイル: Result.cs プロジェクト: dellis1972/Pidgin
 internal Result(bool consumedInput, T value)
 {
     Success       = true;
     ConsumedInput = consumedInput;
     _value        = value;
     _error        = default(ParseError <TToken>);
 }
コード例 #2
0
ファイル: Result.cs プロジェクト: dellis1972/Pidgin
 internal Result(bool consumedInput, ParseError <TToken> error)
 {
     Success       = false;
     ConsumedInput = consumedInput;
     _value        = default(T);
     _error        = error;
 }
コード例 #3
0
ファイル: Parser.OneOf.cs プロジェクト: 07101994/Pidgin
            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);
            }
コード例 #4
0
ファイル: ParseState.cs プロジェクト: raizam/Pidgin
 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;
 }
コード例 #5
0
ファイル: ParseError.cs プロジェクト: dellis1972/Pidgin
 /// <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);
コード例 #6
0
 internal static Result <TToken, T> Failure <TToken, T>(
     ParseError <TToken> error,
     bool consumedInput
     ) => new Result <TToken, T>(error, consumedInput);
コード例 #7
0
 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);