public static Errorable <List <TextUnit> > Parse(string raw) { var res = parse(speechParser, raw); return(res.IsFaulted ? Errorable <List <TextUnit> > .Fail(res.Reply.Error.ToString()) : Errorable <List <TextUnit> > .OK(res.Reply.Result)); }
private static Errorable <LPU> ResolveUnit( Func <string, Errorable <LPU> > argResolve, Func <string, List <LPU>, Errorable <LPU> > macroReinvResolve, LPU x) { Errorable <List <LPU> > resolveAcc(IEnumerable <LPU> args) => Acc(args.Select(a => ResolveUnit(argResolve, macroReinvResolve, a))); Errorable <LPU> reloc(Errorable <ParseUnit> pu) { return(pu.isValid ? new LPU(pu.value, x.location) : Errorable <LPU> .Fail(pu.errors)); } return(x.unit.Match( macroVar: argResolve, macroReinv: macroReinvResolve, paren: ns => reloc(resolveAcc(ns).Map(ParseUnit.Paren)), words: ns => reloc(resolveAcc(ns).Map(ParseUnit.Words)), nswords: ns => reloc(resolveAcc(ns).Map(ParseUnit.NoSpaceWords)), postfix: ns => reloc(resolveAcc(ns).Map(ParseUnit.Postfix)), deflt: () => Errorable <LPU> .OK(x))); }