Ejemplo n.º 1
0
            internal override InternalResult <string> Parse(ref ParseState <TToken> state)
            {
                var consumedInput = false;
                var builder       = new InplaceStringBuilder(_count);

                for (var _ = 0; _ < _count; _++)
                {
                    var result = _parser.Parse(ref state);
                    consumedInput = consumedInput || result.ConsumedInput;

                    if (!result.Success)
                    {
                        return(InternalResult.Failure <string>(consumedInput));
                    }

                    builder.Append(result.Value);
                }

                return(InternalResult.Success(builder.ToString(), consumedInput));
            }
Ejemplo n.º 2
0
        internal sealed override bool TryParse(ref ParseState <TToken> state, ref ExpectedCollector <TToken> expecteds, out string result)
        {
            var builder = new InplaceStringBuilder(_count);

            for (var _ = 0; _ < _count; _++)
            {
                var success = _parser.TryParse(ref state, ref expecteds, out var result1);

                if (!success)
                {
                    result = null;
                    return(false);
                }

                builder.Append(result1);
            }

            result = builder.ToString();
            return(true);
        }
Ejemplo n.º 3
0
            internal sealed override InternalResult <string> Parse(ref ParseState <char> state)
            {
                var consumedInput = false;

                var builder = new InplaceStringBuilder(_value.Length);

                foreach (var c in _value)
                {
                    if (!state.HasCurrent)
                    {
                        state.Error = new InternalError <char>(
                            Maybe.Nothing <char>(),
                            true,
                            state.SourcePos,
                            null
                            );
                        state.AddExpected(Expected);
                        return(InternalResult.Failure <string>(consumedInput));
                    }

                    var token = state.Current;
                    if (char.ToLowerInvariant(token) != char.ToLowerInvariant(c))
                    {
                        state.Error = new InternalError <char>(
                            Maybe.Just(token),
                            false,
                            state.SourcePos,
                            null
                            );
                        state.AddExpected(Expected);
                        return(InternalResult.Failure <string>(consumedInput));
                    }

                    consumedInput = true;
                    builder.Append(token);
                    state.Advance();
                }
                return(InternalResult.Success <string>(builder.ToString(), consumedInput));
            }