summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authordefanor <defanor@uberspace.net>2017-12-03 10:39:34 +0300
committerdefanor <defanor@uberspace.net>2017-12-03 10:39:34 +0300
commit15f63061dd9308e223077d718db0fce85366538f (patch)
tree5b202660f3eb4cb6e21c1163a2dcf03cfc3ad096
parent9fd02f49809bfdfef205fae5885636eef0a69b21 (diff)
downloadcoalpit-15f63061dd9308e223077d718db0fce85366538f.zip
coalpit-15f63061dd9308e223077d718db0fce85366538f.tar.gz
coalpit-15f63061dd9308e223077d718db0fce85366538f.tar.bz2
Add List and Either instances
No special handling for those yet, just for testing.
-rw-r--r--Coalpit.hs11
-rw-r--r--Example.hs4
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