Esempio n. 1
0
        public IParserResult <Tuple <R2, R1> > Parse(ParserInput input)
        {
            var firstResult = this.FirstParser.Parse(input);

            if (!firstResult.IsSuccessful)
            {
                return(new ParserFailed <Tuple <R2, R1> >());
            }
            var secondResult = this.SecondParser.Parse(firstResult.ToInput());

            if (!secondResult.IsSuccessful)
            {
                return(new ParserFailed <Tuple <R2, R1> >());
            }
            return(ParserSucceeded.Create(Tuple.Create(secondResult.Result, firstResult.Result), secondResult.Environment, secondResult.Source));
        }
Esempio n. 2
0
        public IParserResult <R> Parse(ParserInput input)
        {
            var firstResult = this.Parser.Parse(input);

            if (!firstResult.IsSuccessful)
            {
                return(new ParserFailed <R>());
            }
            var secondResult = this.Consumer.Consume(firstResult.ToInput());

            if (!secondResult.IsSuccessful)
            {
                return(new ParserFailed <R>());
            }
            return(ParserSucceeded.Create(firstResult.Result, secondResult.Environment, secondResult.Source));
        }
Esempio n. 3
0
        public IParserResult <R> Transform(S seed, ParserInput input)
        {
            var result1 = this.Transformer.Transform(seed, input);

            if (!result1.IsSuccessful)
            {
                return(result1);
            }
            var result2 = this.Consumer.Consume(result1.ToInput());

            if (!result2.IsSuccessful)
            {
                return(new ParserFailed <R>());
            }
            return(ParserSucceeded.Create(result1.Result, result2.Environment, result2.Source));
        }
Esempio n. 4
0
        public IParserResult <Tuple <R2, R1> > Transform(S seed, ParserInput input)
        {
            var result1 = this.Transformer.Transform(seed, input);

            if (!result1.IsSuccessful)
            {
                return(new ParserFailed <Tuple <R2, R1> >());
            }
            var result2 = this.Parser.Parse(result1.ToInput());

            if (!result2.IsSuccessful)
            {
                return(new ParserFailed <Tuple <R2, R1> >());
            }
            return(ParserSucceeded.Create(Tuple.Create(result2.Result, result1.Result), result2.Environment, result2.Source));
        }
Esempio n. 5
0
        public IParserResult <R> Transform(R seed, ParserInput input)
        {
            var curResult = this.Transformer.Transform(seed, input);

            if (!curResult.IsSuccessful)
            {
                return(new ParserFailed <R>());
            }

            IParserResult <R> lastSuccessfulResult;

            do
            {
                lastSuccessfulResult = curResult;
                curResult            = this.Transformer.Transform(lastSuccessfulResult.Result, lastSuccessfulResult.ToInput());
            } while (curResult.IsSuccessful);

            return(lastSuccessfulResult);
        }
Esempio n. 6
0
        public IParserResult <ImmutableList <R> > Parse(ParserInput input)
        {
            var list      = ImmutableList <R> .Empty;
            var curResult = this.Parser.Parse(input);

            if (!curResult.IsSuccessful)
            {
                return(new ParserFailed <ImmutableList <R> >());
            }

            IParserResult <R> lastSuccessfulResult;

            do
            {
                list = list.Add(curResult.Result);
                lastSuccessfulResult = curResult;
                curResult            = this.Parser.Parse(lastSuccessfulResult.ToInput());
            } while (curResult.IsSuccessful);

            return(ParserSucceeded.Create(list, lastSuccessfulResult.Environment, lastSuccessfulResult.Source));
        }
Esempio n. 7
0
 public IParserResult <R> Transform(R seed, ParserInput input) =>
 this.TransformFunc(ParserSucceeded.Create(seed, input.Environment, input.Source));
Esempio n. 8
0
 public IParserResult <R> Transform(S seed, ParserInput input) =>
 this.Transformer.Value.Transform(seed, input);
Esempio n. 9
0
 public IParserResult Consume(ParserInput input)
 {
     return(ParserSucceeded.Create(this.Transformer(input.Environment), input.Source));
 }
Esempio n. 10
0
 public IParserResult Consume(ParserInput input) =>
 this.Consumer.Value.Consume(input);
Esempio n. 11
0
 public IParserResult <R> Parse(ParserInput input) =>
 ParserSucceeded.Create(this.Result, input.Environment, input.Source);
Esempio n. 12
0
 public IParserResult <R> Parse(ParserInput input) =>
 this.Parser.Value.Parse(input);