packages feed

uu-options 0.1.0.0 → 0.1.0.1

raw patch · 3 files changed

+86/−87 lines, 3 filesPVP: major bump suggested

API removals or changes: PVP suggests a major version bump

API changes (from Hackage documentation)

- Options.UU.OptionsDemo: Address :: String -> String -> Address
- Options.UU.OptionsDemo: Agda :: Prefers
- Options.UU.OptionsDemo: Haskell :: Prefers
- Options.UU.OptionsDemo: Name :: String -> Prefers -> [Int] -> Address -> Name
- Options.UU.OptionsDemo: address :: MonadState Name m => StateT Address m b -> m b
- Options.UU.OptionsDemo: address_ :: Name -> Address
- Options.UU.OptionsDemo: city :: MonadState Address m => StateT String m b -> m b
- Options.UU.OptionsDemo: city_ :: Address -> String
- Options.UU.OptionsDemo: data Address
- Options.UU.OptionsDemo: data Name
- Options.UU.OptionsDemo: data Prefers
- Options.UU.OptionsDemo: defaults :: Name
- Options.UU.OptionsDemo: demo :: [[Char]] -> IO ()
- Options.UU.OptionsDemo: instance Show Address
- Options.UU.OptionsDemo: instance Show Name
- Options.UU.OptionsDemo: instance Show Prefers
- Options.UU.OptionsDemo: instance ShowParserType Prefers
- Options.UU.OptionsDemo: ints :: MonadState Name m => StateT [Int] m b -> m b
- Options.UU.OptionsDemo: ints_ :: Name -> [Int]
- Options.UU.OptionsDemo: main :: IO ()
- Options.UU.OptionsDemo: name :: MonadState Name m => StateT String m b -> m b
- Options.UU.OptionsDemo: name_ :: Name -> String
- Options.UU.OptionsDemo: oName :: (Gram (P (Str Char String Int)) (Name -> Name), [Char])
- Options.UU.OptionsDemo: prefers :: MonadState Name m => StateT Prefers m b -> m b
- Options.UU.OptionsDemo: prefers_ :: Name -> Prefers
- Options.UU.OptionsDemo: street :: MonadState Address m => StateT String m b -> m b
- Options.UU.OptionsDemo: street_ :: Address -> String

Files

+ src/Options/UU/Main.hs view
@@ -0,0 +1,84 @@+{-# LANGUAGE TemplateHaskell, FlexibleContexts, NoMonomorphismRestriction, TypeSynonymInstances, FlexibleInstances #-}+module Main where+import Data.Lenses.Template+import Text.ParserCombinators.UU+import Text.ParserCombinators.UU.BasicInstances+import Text.ParserCombinators.UU.Utils+import Text.ParserCombinators.UU.Interleaved+import Options.UU.Interleaved+import Data.Monoid+import System.Environment++-- We assume that we store our options in a data type for which we generate lenses++data Prefers  =  Agda | Haskell deriving Show+data Address  =  Address  {  city_ :: String+                          ,  street_ :: String} +                 deriving Show+data Name     =  Name  {  name_:: String +                       ,  prefers_:: Prefers+                       ,  ints_ :: [Int]+                       ,  address_ :: Address} +                 deriving Show++$(deriveLenses ''Name)+$(deriveLenses ''Address)++instance ShowParserType Prefers where+   showType p = " <Agda | Haskell> "++-- The next thing to do is to specify a default record containing the default values:+defaults = Name  "Atze" Haskell [] +                 (Address  "Utrecht" +                           "Princetonplein")++-- Next we define the parser for the options, by specifying for each filed what may be specified:++oName =+                 name     `option`   ("name",       pString,      "Name")+            <>   ints     `options`  ("ints",       pNaturalRaw,  "A couple of numbers") +            <>   prefers  `choose`   [("agda",      Agda,         "In case you prefer Agda")+                                     ,("haskell",   Haskell,      "In case you prefer Haskell")+                                     ] +            <>   address  `field`+                           (   city     `option`  ("city",   pString, "Home city")  +                           <>  street   `option`  ("street" ,pString, "Home Street" )+                           )+{-+-- | The function `main` may serve as a template for your own option handling. You can also use this module to see what  the effectis  of the various ways of passing options+-- >>> ./OptionsDemo -i1 --ints 2 --street=Zandlust -a -nDoaitse -i3 --ints=4 --city=Tynaarlo+--     Name {name_ = "Doaitse", prefers_ = Agda, ints_ = [1,2,3,4], address_ = Address {city_ = "Tynaarlo", street_ = "Zandlust"}}+--+-- >>> ./OptionsDemo -i1 --ints 2 --street=Zandlust -nDoaitse -i3 --ints=4 --city=Tynaarlo+--     --name           [Char]         optional  Name+--     --ints           Int            recurring A couple of numbers+--     Choose at least one from(+--     --agda                          required  In case you prefer Agda+--     --haskell                       required  In case you prefer Haskell+--     )+--     --city           [Char]         optional  Home city+--     --street         [Char]         optional  Home Street+--     --+--     --  Correcting steps:+--     --    Inserted  "-a" at position 70 expecting one of ["--agda", "--agda=", "--haskell", "--haskell=", "--ints=", "--ints", "-i", "-h", "-a"]+--     --    Inserted  "\EOT" at position 70 expecting "\EOT"+-}+main  ::IO ()+main = do args  <- getArgs+          case run  defaults oName  (concat (map  (++ "\EOT") args)) of+            Left a        -> case a of+                                   Succes v -> print v+                                   Help   t -> putStrLn t+            Right errors  -> putStrLn errors++-- | The function `demo` can be used from within ghci:+{-+-- >>> demo ["-i2", "--street=Zandlust", "--ints=5", "-nAtze", "--city=Houten"]+--+-}+demo :: [[Char]] -> IO ()+demo args =  case run  defaults oName  (concat (map  (++ "\EOT") args)) of+                  Left a        -> case a of+                                   Succes v -> print v+                                   Help   t -> putStrLn t+                  Right errors  -> putStr errors
− src/Options/UU/OptionsDemo.hs
@@ -1,84 +0,0 @@-{-# LANGUAGE TemplateHaskell, FlexibleContexts, NoMonomorphismRestriction, TypeSynonymInstances, FlexibleInstances #-}-module Options.UU.OptionsDemo where-import Data.Lenses.Template-import Text.ParserCombinators.UU-import Text.ParserCombinators.UU.BasicInstances-import Text.ParserCombinators.UU.Utils-import Text.ParserCombinators.UU.Interleaved-import Options.UU.Interleaved-import Data.Monoid-import System.Environment---- We assume that we store our options in a data type for which we generate lenses--data Prefers  =  Agda | Haskell deriving Show-data Address  =  Address  {  city_ :: String-                          ,  street_ :: String} -                 deriving Show-data Name     =  Name  {  name_:: String -                       ,  prefers_:: Prefers-                       ,  ints_ :: [Int]-                       ,  address_ :: Address} -                 deriving Show--$(deriveLenses ''Name)-$(deriveLenses ''Address)--instance ShowParserType Prefers where-   showType p = " <Agda | Haskell> "---- The next thing to do is to specify a default record containing the default values:-defaults = Name  "Atze" Haskell [] -                 (Address  "Utrecht" -                           "Princetonplein")---- Next we define the parser for the options, by specifying for each filed what may be specified:--oName =-                 name     `option`   ("name",       pString,      "Name")-            <>   ints     `options`  ("ints",       pNaturalRaw,  "A couple of numbers") -            <>   prefers  `choose`   [("agda",      Agda,         "In case you prefer Agda")-                                     ,("haskell",   Haskell,      "In case you prefer Haskell")-                                     ] -            <>   address  `field`-                           (   city     `option`  ("city",   pString, "Home city")  -                           <>  street   `option`  ("street" ,pString, "Home Street" )-                           )-{---- | The function `main` may serve as a template for your own option handling. You can also use this module to see what  the effectis  of the various ways of passing options--- >>> ./OptionsDemo -i1 --ints 2 --street=Zandlust -a -nDoaitse -i3 --ints=4 --city=Tynaarlo---     Name {name_ = "Doaitse", prefers_ = Agda, ints_ = [1,2,3,4], address_ = Address {city_ = "Tynaarlo", street_ = "Zandlust"}}------ >>> ./OptionsDemo -i1 --ints 2 --street=Zandlust -nDoaitse -i3 --ints=4 --city=Tynaarlo---     --name           [Char]         optional  Name---     --ints           Int            recurring A couple of numbers---     Choose at least one from(---     --agda                          required  In case you prefer Agda---     --haskell                       required  In case you prefer Haskell---     )---     --city           [Char]         optional  Home city---     --street         [Char]         optional  Home Street---     -----     --  Correcting steps:---     --    Inserted  "-a" at position 70 expecting one of ["--agda", "--agda=", "--haskell", "--haskell=", "--ints=", "--ints", "-i", "-h", "-a"]---     --    Inserted  "\EOT" at position 70 expecting "\EOT"--}-main  ::IO ()-main = do args  <- getArgs-          case run  defaults oName  (concat (map  (++ "\EOT") args)) of-            Left a        -> case a of-                                   Succes v -> print v-                                   Help   t -> putStrLn t-            Right errors  -> putStrLn errors---- | The function `demo` can be used from within ghci:-{---- >>> demo ["-i2", "--street=Zandlust", "--ints=5", "-nAtze", "--city=Houten"]-----}-demo :: [[Char]] -> IO ()-demo args =  case run  defaults oName  (concat (map  (++ "\EOT") args)) of-                  Left a        -> case a of-                                   Succes v -> print v-                                   Help   t -> putStrLn t-                  Right errors  -> putStr errors
uu-options.cabal view
@@ -1,5 +1,5 @@ Name:                uu-options-Version:             0.1.0.0+Version:             0.1.0.1 Build-Type:          Simple License:             MIT Copyright:           S Doaitse Swierstra @@ -28,7 +28,7 @@      location: https://svn.science.uu.nl/repos/project.STEC.uu-parsinglib/uu-options  executable           demo-options-  Main-is:           Options/UU/OptionsDemo.hs+  Main-is:           Options/UU/Main.hs   hs-source-dirs:    src   Build-Depends:     base >= 4.2 && <5, uu-parsinglib >=2.8 && < 2.9, uu-interleaved >=0.1.0 && < 0.2, lenses >= 0.1.6 && < 0.1.7, transformers >= 0.3.0.0, mtl @@ -36,5 +36,4 @@   hs-source-dirs:    src   Build-Depends:     base >= 4.2 && <5, uu-parsinglib >=2.8 && < 2.9, uu-interleaved >=0.1.0 && < 0.2, lenses >= 0.1.6 && < 0.1.7, transformers >= 0.3.0.0, mtl   Exposed-modules:   Options.UU.Interleaved-                     Options.UU.OptionsDemo