X-Git-Url: https://git.martlubbers.net/?a=blobdiff_plain;f=gopt%2Fgopt.icl;h=09089ab2354dfdd5dde24f6a0239f98a111b4d8e;hb=a213c291ff305325434a46262c9ec97e04cb829e;hp=57cf229affdf015ec9381e4a136dc936fee14f81;hpb=3d178c7c12e836d3791180034d029cbd3897921a;p=clean-tests.git diff --git a/gopt/gopt.icl b/gopt/gopt.icl index 57cf229..09089ab 100644 --- a/gopt/gopt.icl +++ b/gopt/gopt.icl @@ -36,12 +36,13 @@ combine` sel app p s t = p s (sel t) >>= \(l, as)->pure ((app (const l) t), as) ar0 s f as = Ok o flip tuple as o f generic gopt a *! :: Opt a +//generic gopt a :: Opt a gopt{|Bool|} = BinaryFlag (const True) (const False) gopt{|Int|} = Positionals [("INT", \s _->if (and [isDigit c\\c<-:s]) (Ok $ toInt s) (Error ["Not an integer"]))] gopt{|Char|} = Positionals [("CHAR", \s _->if (size s == 1) (Ok s.[0]) (Error ["Not a single character"]))] gopt{|String|} = Positionals [("STRING", \s _->Ok s)] -gopt{|RECORD|} f = bifmap (\(RECORD a)->a) RECORD f -gopt{|OBJECT|} f = bifmap (\(OBJECT a)->a) OBJECT f +gopt{|RECORD|} f = bifmap (\(RECORD a)->a) (\x->RECORD x) f +gopt{|OBJECT|} f = bifmap (\(OBJECT a)->a) (\x->OBJECT x) f gopt{|FIELD of {gfd_name}|} f = case f of //Child is a boolean BinaryFlag set unset = mapF $ Flags [(gfd_name, ar0 gfd_name set), ("no-" +++ gfd_name, ar0 ("no-" +++ gfd_name) unset)] @@ -54,7 +55,7 @@ gopt{|FIELD of {gfd_name}|} f = case f of x = abort "Subparsers not supported" where mapF :: ((m a) -> m (FIELD a)) | bifmap m - mapF = bifmap (\(FIELD a)->a) FIELD + mapF = bifmap (\(FIELD a)->a) (\x->FIELD x) ptoarg [p] [] i = Error ["Not enough arguments for " +++ gfd_name] ptoarg [(_, p):ps] [a:as] i = p a i >>= ptoarg ps as