summaryrefslogtreecommitdiff
path: root/Coalpit/DSV.hs
diff options
context:
space:
mode:
authordefanor <defanor@uberspace.net>2017-12-19 07:58:16 +0300
committerdefanor <defanor@uberspace.net>2017-12-19 07:58:16 +0300
commit62aa7bb8ba54c2a0f480e122c46d967f2102dac5 (patch)
treefeb437122a2f4148795571187912ef00ed787987 /Coalpit/DSV.hs
parent16a3509836691ff9a43a0a8920d615ba91f8a74f (diff)
Reorganize the modules
Diffstat (limited to 'Coalpit/DSV.hs')
-rw-r--r--Coalpit/DSV.hs17
1 files changed, 14 insertions, 3 deletions
diff --git a/Coalpit/DSV.hs b/Coalpit/DSV.hs
index f11f830..4940843 100644
--- a/Coalpit/DSV.hs
+++ b/Coalpit/DSV.hs
@@ -1,23 +1,25 @@
{- |
Module : Coalpit.DSV
-Description : Argument parsing facilities
+Description : DSV printing and parsing
Maintainer : defanor <defanor@uberspace.net>
Stability : unstable
Portability : non-portable (uses GHC extensions)
-This module provides functions useful for argument parsing.
+This module provides functions for DSV printing and parsing.
-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE FlexibleInstances #-}
-module Coalpit.DSV (composeDSV, parseDSV) where
+module Coalpit.DSV (showDSV, readDSV) where
import Data.List
import Text.Megaparsec
import Text.Megaparsec.Char
import Data.Void
+import Coalpit.Core
+
composeDSVLine :: Char -> [String] -> String
composeDSVLine fs = intercalate [fs] . map escapeVal
@@ -63,3 +65,12 @@ parseDSV fs = map parseLine . lines
parseLine l = case parse (pDSVLine fs) "line" l of
Left err -> Left $ parseErrorPretty err
Right x -> Right x
+
+
+-- | Shows values in DSV format.
+showDSV :: Coalpit a => Options -> [a] -> String
+showDSV opt = composeDSV (fieldSeparator opt) . map (toArgs opt)
+
+-- | Reads values from DSV format.
+readDSV :: Coalpit a => Options -> String -> [Either String a]
+readDSV opt = map (>>= fromArgs opt) . parseDSV (fieldSeparator opt)