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))))))); }
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))); }
public static IParser <TU> Map <T, TU>(this IParser <T> init, Func <T, TU> transform) { return(init.AndThen(i => Pure(transform(i)))); }
public static IParser <TU> IgnoreAnd <T, TU>(this IParser <T> first, IParser <TU> second) { return(first.AndThen(_ => second)); }
public static IParser <T> AndIgnore <T, TU>(this IParser <T> first, IParser <TU> second) { return(first.AndThen(a => second.Map(_ => a))); }
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)))); }