Example #1
0
 public static MonadicParser <TIn, TOut> SelectMany <TIn, TOut1, TOut, TOut2>(
     this MonadicParser <TIn, TOut1> parser1,
     Func <TOut1, MonadicParser <TIn, TOut2> > collectionSelector,
     Func <TOut1, TOut2, TOut> resultSelector)
 {
     return(scanner =>
     {
         var firsstResult = parser1(scanner);
         if (!firsstResult.Item2.Success)
         {
             return Tuple.Create(default(TOut), firsstResult.Item2);
         }
         else
         {
             var secParser = collectionSelector(firsstResult.Item1);
             var secResult = secParser(scanner);
             if (!secResult.Item2.Success)
             {
                 return Tuple.Create(default(TOut), secResult.Item2);
             }
             else
             {
                 return Tuple.Create(
                     resultSelector(firsstResult.Item1, secResult.Item1),
                     firsstResult.Item2 + secResult.Item2);
             }
         }
     });
 }
Example #2
0
 public static MonadicParser <TIn, TOut> Select <TIn, TOut, TOut1>(
     this MonadicParser <TIn, TOut1> parser,
     Func <TOut1, TOut> resultSelector)
 {
     return(scanner =>
     {
         var firsstResult = parser(scanner);
         return Tuple.Create(!firsstResult.Item2.Success ?
                             default(TOut) :
                             resultSelector(firsstResult.Item1), firsstResult.Item2);
     });
 }
Example #3
0
 public static IParser <TIn, TOut> GetParser <TIn, TOut>(this MonadicParser <TIn, TOut> parser)
 {
     return(new FunctionParser <TIn, TOut>(x => parser(x)));
 }