Beispiel #1
0
 internal override InternalResult <SourcePos> Parse(IParseState <TToken> state)
 => InternalResult.Success(state.SourcePos, false);
Beispiel #2
0
 internal sealed override InternalResult <T> Parse(IParseState <TToken> state)
 => InternalResult.Success <T>(_value, false);
Beispiel #3
0
            // see comment about expecteds in ParseState.Error.cs
            internal override InternalResult <IEnumerable <T> > Parse(ref ParseState <TToken> state)
            {
                var ts = _keepResults ? new List <T>() : null;

                var firstItemResult = _parser.Parse(ref state);

                if (!firstItemResult.Success)
                {
                    // state.Error set by _parser
                    return(InternalResult.Failure <IEnumerable <T> >(firstItemResult.ConsumedInput));
                }
                if (!firstItemResult.ConsumedInput)
                {
                    throw new InvalidOperationException("Until() used with a parser which consumed no input");
                }
                ts?.Add(firstItemResult.Value);

                while (true)
                {
                    state.BeginExpectedTran();
                    var terminatorResult = _terminator.Parse(ref state);
                    if (terminatorResult.Success)
                    {
                        state.EndExpectedTran(false);
                        return(InternalResult.Success <IEnumerable <T> >(ts, true));
                    }
                    if (terminatorResult.ConsumedInput)
                    {
                        // state.Error set by _terminator
                        state.EndExpectedTran(true);
                        return(InternalResult.Failure <IEnumerable <T> >(true));
                    }

                    state.BeginExpectedTran();
                    var itemResult = _parser.Parse(ref state);
                    if (!itemResult.Success)
                    {
                        if (!itemResult.ConsumedInput)
                        {
                            // get the expected from both _terminator and _parser
                            state.EndExpectedTran(true);
                            state.EndExpectedTran(true);
                        }
                        else
                        {
                            // throw out the _terminator expecteds and keep only _parser
                            var itemExpected = state.ExpectedTranState();
                            state.EndExpectedTran(false);
                            state.EndExpectedTran(false);
                            state.AddExpected(itemExpected.AsSpan());
                            itemExpected.Dispose();
                        }
                        return(InternalResult.Failure <IEnumerable <T> >(true));
                    }
                    // throw out both sets of expecteds
                    state.EndExpectedTran(false);
                    state.EndExpectedTran(false);
                    if (!itemResult.ConsumedInput)
                    {
                        throw new InvalidOperationException("Until() used with a parser which consumed no input");
                    }
                    ts?.Add(itemResult.Value);
                }
            }
            internal sealed override InternalResult <R> Parse(ref ParseState <TToken> state)
            {
                var consumedInput = false;


                var result1 = _p1.Parse(ref state);

                consumedInput = consumedInput || result1.ConsumedInput;
                if (!result1.Success)
                {
                    return(InternalResult.Failure <R>(consumedInput));
                }

                var result2 = _p2.Parse(ref state);

                consumedInput = consumedInput || result2.ConsumedInput;
                if (!result2.Success)
                {
                    return(InternalResult.Failure <R>(consumedInput));
                }

                var result3 = _p3.Parse(ref state);

                consumedInput = consumedInput || result3.ConsumedInput;
                if (!result3.Success)
                {
                    return(InternalResult.Failure <R>(consumedInput));
                }

                var result4 = _p4.Parse(ref state);

                consumedInput = consumedInput || result4.ConsumedInput;
                if (!result4.Success)
                {
                    return(InternalResult.Failure <R>(consumedInput));
                }

                var result5 = _p5.Parse(ref state);

                consumedInput = consumedInput || result5.ConsumedInput;
                if (!result5.Success)
                {
                    return(InternalResult.Failure <R>(consumedInput));
                }

                var result6 = _p6.Parse(ref state);

                consumedInput = consumedInput || result6.ConsumedInput;
                if (!result6.Success)
                {
                    return(InternalResult.Failure <R>(consumedInput));
                }

                var result7 = _p7.Parse(ref state);

                consumedInput = consumedInput || result7.ConsumedInput;
                if (!result7.Success)
                {
                    return(InternalResult.Failure <R>(consumedInput));
                }

                return(InternalResult.Success <R>(_func(
                                                      result1.Value,
                                                      result2.Value,
                                                      result3.Value,
                                                      result4.Value,
                                                      result5.Value,
                                                      result6.Value,
                                                      result7.Value
                                                      ), consumedInput));
            }
 internal override InternalResult <SourcePos> Parse(ref ParseState <TToken> state)
 => InternalResult.Success(state.ComputeSourcePos(), false);
            internal sealed override InternalResult <R> Parse(IParseState <TToken> state)
            {
                var consumedInput = false;


                var result1 = _p1.Parse(state);

                consumedInput = consumedInput || result1.ConsumedInput;
                if (!result1.Success)
                {
                    state.Error = state.Error.WithExpected(Expected);
                    return(InternalResult.Failure <R>(
                               consumedInput
                               ));
                }

                var result2 = _p2.Parse(state);

                consumedInput = consumedInput || result2.ConsumedInput;
                if (!result2.Success)
                {
                    state.Error = state.Error.WithExpected(Expected);
                    return(InternalResult.Failure <R>(
                               consumedInput
                               ));
                }

                var result3 = _p3.Parse(state);

                consumedInput = consumedInput || result3.ConsumedInput;
                if (!result3.Success)
                {
                    state.Error = state.Error.WithExpected(Expected);
                    return(InternalResult.Failure <R>(
                               consumedInput
                               ));
                }

                var result4 = _p4.Parse(state);

                consumedInput = consumedInput || result4.ConsumedInput;
                if (!result4.Success)
                {
                    state.Error = state.Error.WithExpected(Expected);
                    return(InternalResult.Failure <R>(
                               consumedInput
                               ));
                }

                var result5 = _p5.Parse(state);

                consumedInput = consumedInput || result5.ConsumedInput;
                if (!result5.Success)
                {
                    state.Error = state.Error.WithExpected(Expected);
                    return(InternalResult.Failure <R>(
                               consumedInput
                               ));
                }

                return(InternalResult.Success <R>(_func(
                                                      result1.Value,
                                                      result2.Value,
                                                      result3.Value,
                                                      result4.Value,
                                                      result5.Value
                                                      ), consumedInput));
            }