예제 #1
0
 public static IParser <S, Association <O, T> > Separated <S, O, T>(this IParser <S, T> parser, IParser <S, O> separator)
 {
     return(parser
            .Continue(first => separator.AndThen(parser).Repeat()
                      .Continue(rest => Parsers.Returns <S, Association <O, T> >(new Association <O, T>(
                                                                                     @operators: rest.Fmap(_ => _.Item1),
                                                                                     @operands: ArrayOperations.Concatenate(new T[] { first }, rest.Fmap(_ => _.Item2)))))));
 }
예제 #2
0
 private static IParser <LinkedList <T> > RepeatToLinkedList <T>(IParser <T> first)
 {
     return
         (first.AndThen(h =>
                        RepeatToLinkedList(first).Map(t => new LinkedList <T> {
         Head = h, Tail = t
     }))
          .Or(Pure <LinkedList <T> >(null)));
 }
예제 #3
0
 public static IParser <TU> Map <T, TU>(this IParser <T> init, Func <T, TU> transform)
 {
     return(init.AndThen(i => Pure(transform(i))));
 }
예제 #4
0
 public static IParser <TU> IgnoreAnd <T, TU>(this IParser <T> first, IParser <TU> second)
 {
     return(first.AndThen(_ => second));
 }
예제 #5
0
 public static IParser <T> AndIgnore <T, TU>(this IParser <T> first, IParser <TU> second)
 {
     return(first.AndThen(a => second.Map(_ => a)));
 }
예제 #6
0
 public static IParser <Tuple <T, TU> > And <T, TU>(this IParser <T> first, IParser <TU> second)
 {
     return(first.AndThen(a => second.Map(b => new Tuple <T, TU>(a, b))));
 }