Example #1
0
 public static Parser <TToken, IDelayed <ISeq <T> > > SepBy0 <TToken, T>(
     Parser <TToken, T> parser,
     Parser <TToken, Unit> sep)
 {
     return(InternalCombinator.SepBy1(parser, sep)
            .Or(Parser.Return <TToken, IDelayed <ISeq <T> > >(Seq.Empty <T>())));
 }
 public static Parser <TToken, IEnumerable <T> > SepBy1_Optimized <TToken, T>(
     Parser <TToken, T> parser,
     Parser <TToken, Unit> sep)
 {
     return(parser.Pipe(InternalCombinator.Many0_Optimized(sep.Bindr(parser)),
                        (head, tail) => Enumerable.Concat(new[] { head }, tail)));
 }
 public static Parser <TToken, IEnumerable <T> > SepBy0_Optimized <TToken, T>(
     Parser <TToken, T> parser,
     Parser <TToken, Unit> sep)
 {
     return(InternalCombinator.SepBy1_Optimized(parser, sep)
            .Or(Parser.Return <TToken, IEnumerable <T> >(Enumerable.Empty <T>())));
 }
 public static Parser <TToken, IEnumerable <T> > SepEndBy1_Optimized <TToken, T>(
     Parser <TToken, T> parser,
     Parser <TToken, Unit> sep)
 {
     return(InternalCombinator.SepBy1_Optimized(parser, sep)
            .Bindl(sep.Optional()));
 }
Example #5
0
 public static Parser <TToken, IDelayed <ISeq <T> > > Append <TToken, T>(
     Parser <TToken, IDelayed <ISeq <T> > > parser0,
     Parser <TToken, T> parser1)
 {
     return(InternalCombinator.Append(
                parser0,
                parser1.Map(Seq.Singleton)));
 }
Example #6
0
 public static Parser <TToken, T> Chainr <TToken, T>(
     Parser <TToken, T> parser,
     Parser <TToken, Func <T, T, T> > op)
 {
     return(from lhs in parser
            from resultValue in InternalCombinator.ChainrRest <TToken, T>(parser, op, lhs)
            select resultValue);
 }
Example #7
0
 public static Parser <TToken, IDelayed <ISeq <T> > > ManyTill <TToken, T>(
     this Parser <TToken, T> parser,
     Parser <TToken, Unit> terminator)
 {
     return(terminator.Select(_ => Seq.Empty <T>())
            .Or(parser.SelectMany(head => InternalCombinator.ManyTill(parser, terminator)
                                  .Select(tail => Seq.Cons(head, tail)))));
 }
        public static Parser <TToken, T> Choice <TToken, T>(
            this IEnumerable <Parser <TToken, T> > parsers)
        {
            /*
             * return InternalCombinator.Choice(Seq.Of(parsers));
             */

            return(InternalCombinator.Choice_Optimized(parsers));
        }
Example #9
0
 public static Parser <TToken, IDelayed <ISeq <T> > > Many0 <TToken, T>(
     Parser <TToken, T> parser)
 {
     return(stream => parser(stream).Case(
                failure: (restStream, errorMessage) =>
                Reply.Success <TToken, IDelayed <ISeq <T> > >(stream, Seq.Empty <T>()),
                success: (restStream, head) =>
                InternalCombinator.Many0(parser).Select(tail => Seq.Cons(head, tail))(restStream)));
 }
Example #10
0
 public static Parser <TToken, T> Choice <TToken, T>(
     IDelayed <ISeq <Parser <TToken, T> > > parsers)
 {
     return(parsers.Force().Case(
                empty: () =>
                Parser.Fail <TToken, T>("Failure: Combinator.Choice"),
                headAndTail: pair =>
                pair.Item0.Or(InternalCombinator.Choice(pair.Item1))));
 }
Example #11
0
 public static Parser <TToken, IDelayed <ISeq <T> > > Sequence <TToken, T>(
     IDelayed <ISeq <Parser <TToken, T> > > parsers)
 {
     return(parsers.Force().Case(
                empty: () =>
                Parser.Return <TToken, IDelayed <ISeq <T> > >(Seq.Empty <T>()),
                headAndTail: pair =>
                pair.Item0.SelectMany(value0 => InternalCombinator.Sequence(pair.Item1).Select(value1 => Seq.Cons(value0, value1)))));
 }
        public static Parser <TToken, IEnumerable <T> > Sequence <TToken, T>(
            this IEnumerable <Parser <TToken, T> > parsers)
        {
            /*
             * InternalCombinator.Sequence(Seq.Of(parsers))
             *   .Select(delayedSeq => delayedSeq.AsEnumerable());
             */

            return(InternalCombinator.Sequence_Optimized(parsers));
        }
Example #13
0
 public static Parser <TToken, T> ChainrRest <TToken, T>(
     Parser <TToken, T> parser,
     Parser <TToken, Func <T, T, T> > op,
     T lhs)
 {
     return((from func in op
             from rhs in InternalCombinator.Chainr(parser, op)
             select func(lhs, rhs))
            .Or(Parser.Return <TToken, T>(lhs)));
 }
        public static Parser <TToken, IEnumerable <T> > Many1 <TToken, T>(
            this Parser <TToken, T> parser)
        {
            /*
             * return InternalCombinator.Many1(parser)
             *       .Select(delayedSeq => delayedSeq.AsEnumerable());
             */

            return(InternalCombinator.Many1_Optimized(parser));
        }
Example #15
0
 public static Parser <TToken, IDelayed <ISeq <T> > > Append <TToken, T>(
     Parser <TToken, IDelayed <ISeq <T> > > parser0,
     Parser <TToken, IOption <T> > parser1)
 {
     return(InternalCombinator.Append(
                parser0,
                parser1.Map(optionValue => optionValue.Case(
                                none: Seq.Empty <T>,
                                some: Seq.Singleton <T>))));
 }
Example #16
0
 public static Parser <TToken, T> ChainlRest <TToken, T>(
     Parser <TToken, T> parser,
     Parser <TToken, Func <T, T, T> > op,
     T lhs)
 {
     return((from func in op
             from rhs in parser
             from resultValue in InternalCombinator.ChainlRest(parser, op, func(lhs, rhs))
             select resultValue)
            .Or(Parser.Return <TToken, T>(lhs)));
 }
        public static Parser <TToken, IEnumerable <T> > Repeat <TToken, T>(
            this Parser <TToken, T> parser,
            int count)
        {
            /*
             * return InternalCombinator.Repeat(parser, count)
             *       .Select(delayedSeq => delayedSeq.AsEnumerable());
             */

            return(InternalCombinator.Repeat_Optimized(parser, count));
        }
        public static Parser <TToken, IEnumerable <T> > SepEndBy1 <TToken, T>(
            this Parser <TToken, T> parser,
            Parser <TToken, Unit> sep)
        {
            /*
             * return InternalCombinator.SepEndBy1(parser, sep)
             *     .Select(delayedSeq => delayedSeq.AsEnumerable());
             */

            return(InternalCombinator.SepEndBy1_Optimized(parser, sep));
        }
Example #19
0
 public static Parser <TToken, IDelayed <ISeq <T> > > Repeat <TToken, T>(
     Parser <TToken, T> parser,
     Int32 count)
 {
     return(InternalCombinator.Sequence(Seq.Of(Enumerable.Repeat(parser, count))));
 }
 public static Parser <TToken, IEnumerable <T> > Repeat_Optimized <TToken, T>(
     Parser <TToken, T> parser,
     Int32 count)
 {
     return(InternalCombinator.Sequence_Optimized(Enumerable.Repeat(parser, count)));
 }
 public static Parser <TToken, IEnumerable <T> > Many1_Optimized <TToken, T>(
     Parser <TToken, T> parser)
 {
     return(parser.Pipe(InternalCombinator.Many0_Optimized(parser),
                        (head, tail) => Enumerable.Concat(new[] { head }, tail)));
 }
Example #22
0
 public static Parser <TToken, IDelayed <ISeq <T> > > Many1 <TToken, T>(
     Parser <TToken, T> parser)
 {
     return(parser.SelectMany(head => InternalCombinator.Many0(parser).Select(tail => Seq.Cons(head, tail))));
 }
 public static Parser <TToken, IEnumerable <T> > EndBy1_Optimized <TToken, T>(
     Parser <TToken, T> parser,
     Parser <TToken, Unit> sep)
 {
     return(InternalCombinator.Many1_Optimized(parser.Bindl(sep)));
 }
Example #24
0
 public static Parser <TToken, IDelayed <ISeq <T> > > EndBy0 <TToken, T>(
     Parser <TToken, T> parser,
     Parser <TToken, Unit> sep)
 {
     return(InternalCombinator.Many0(parser.SelectMany(value => sep.Select(_ => value))));
 }
 public static Parser <TToken, T> Chainr <TToken, T>(
     this Parser <TToken, T> parser,
     Parser <TToken, Func <T, T, T> > op)
 {
     return(InternalCombinator.Chainr(parser, op));
 }
Example #26
0
 public static Parser <TToken, IDelayed <ISeq <T> > > SepBy1 <TToken, T>(
     Parser <TToken, T> parser,
     Parser <TToken, Unit> sep)
 {
     return(parser.SelectMany(head => InternalCombinator.Many0(sep.SelectMany(_ => parser)).Select(tail => Seq.Cons(head, tail))));
 }
Example #27
0
 public static Parser <TToken, IDelayed <ISeq <T> > > SepEndBy1 <TToken, T>(
     Parser <TToken, T> parser,
     Parser <TToken, Unit> sep)
 {
     return(InternalCombinator.SepBy1(parser, sep).SelectMany(value => sep.Optional().Select(_ => value)));
 }