From 15f63061dd9308e223077d718db0fce85366538f Mon Sep 17 00:00:00 2001 From: defanor Date: Sun, 3 Dec 2017 10:39:34 +0300 Subject: Add List and Either instances No special handling for those yet, just for testing. --- Coalpit.hs | 11 +++++++++-- Example.hs | 4 ++-- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/Coalpit.hs b/Coalpit.hs index bc5436a..a252691 100644 --- a/Coalpit.hs +++ b/Coalpit.hs @@ -16,6 +16,7 @@ import Data.Maybe import Data.Char import Data.Proxy import Data.Semigroup +import Data.Either advance :: Pos -> SourcePos -> t -> SourcePos @@ -204,10 +205,10 @@ instance ArgParser Int where instance ToArgs Int where toArgs _ i = [show i] -instance ArgParser String where +instance {-#OVERLAPPING#-} ArgParser String where argParser _ = pS $ many anyChar -instance ToArgs String where +instance {-#OVERLAPPING#-} ToArgs String where toArgs _ i = [i] instance ArgParser Double where @@ -218,3 +219,9 @@ instance ToArgs Double where instance ArgParser a => ArgParser (Maybe a) instance ToArgs a => ToArgs (Maybe a) + +instance ArgParser a => ArgParser [a] +instance ToArgs a => ToArgs [a] + +instance (ArgParser a, ArgParser b) => ArgParser (Either a b) +instance (ToArgs a, ToArgs b) => ToArgs (Either a b) diff --git a/Example.hs b/Example.hs index fca8165..4df7ae9 100644 --- a/Example.hs +++ b/Example.hs @@ -16,7 +16,7 @@ instance ToArgs RecTest data Foo = Bar Int | Baz Int - | Qux (Maybe Int) (Maybe String) RecTest (Maybe Double) + | Qux [Int] (Maybe Int) (Either String Int) RecTest (Maybe Double) deriving (Generic, Show) instance ArgParser Foo @@ -30,7 +30,7 @@ instance ToArgs Wrap main :: IO () main = do - let val = Wrap (Just $ Qux Nothing (Just "foo bar") + let val = Wrap (Just $ Qux [1,2,3] Nothing (Left "foo bar") (RecTest Nothing (Just 2.3) Nothing) Nothing) (Just 1) a = toArgs defMod val print val -- cgit v1.2.3