Пример #1
0
        public IParseResult <T> TryParse(IInputReader inp)
        {
            if (inp.Eof())
            {
                return(Parse.Success <T>());
            }

            var ch = inp.Substr(20);

            return(Parse.Error <T>($"Expected EOS, but got '{ch}'", inp));
        }
Пример #2
0
        public IParseResult <TResult> TryParse(IInputReader inp)
        {
            TAccum acc = _seed();

            do
            {
                var pos    = inp.GetPosition();
                var parsed = _parser.TryParse(inp);
                if (!parsed.IsSuccess())
                {
                    inp.Seek(pos);
                    break;
                }
                acc = _accFunc(acc, parsed.Result);
            } while (!inp.Eof());

            return(Parse.Success(_resultSelector(acc)));
        }