{-# LANGUAGE TemplateHaskell, FlexibleContexts, NoMonomorphismRestriction, TupleSections #-} module OptionExample where import Data.Lenses import Data.Lenses.Template import Text.ParserCombinators.UU import Text.ParserCombinators.UU.Demo.Examples import Text.ParserCombinators.UU.BasicInstances import Text.ParserCombinators.UU.Utils import Text.ParserCombinators.UU.Idioms import Text.ParserCombinators.UU.MergeAndPermute import Options import Data.Monoid data Prefers = Clean | Haskell deriving Show data Address = Address {city_ :: String, room_ :: String} deriving Show data Name = Name { name_:: String, prefers_:: Prefers, ints_ :: [Int] , address_ :: Address} deriving Show $(deriveLenses ''Name) $(deriveLenses ''Address) defaults = Name "Doaitse" Haskell [] (Address "Utrecht" "BBL517") oName = name `option` ("name", pString) <> ints `options` ("int", pNatural) <> prefers `flags` [("clean", Clean) ,("haskell", Haskell)] <> address `field` ( city `option` ("city", pString) <> room `option` ("room", pString) ) main = run (($ defaults) <$> mkP oName) "--name=Rinus --int=7 --city=Nijmegen -i 5 --clean -i3" gLog = gmList gProcess gProcess = do n <- show <$> mkG pStart w <- pMany . mkG $ pWork n _ <- mkG $ pClose n return (n, w) pStart = pToken "s" *> pNatural pWork n = pToken ('w': n ++ " ") *> pMunch (/= '\n') -- read the rest of the line <* pToken "\n" pClose n = pToken ('c': n) <* pToken "\n" main2 = do inp <- readFile "ExampleLog" run (mkP gLog) inp