From 62aa7bb8ba54c2a0f480e122c46d967f2102dac5 Mon Sep 17 00:00:00 2001 From: defanor Date: Tue, 19 Dec 2017 07:58:16 +0300 Subject: Reorganize the modules --- Coalpit/DSV.hs | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) (limited to 'Coalpit/DSV.hs') 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 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) -- cgit v1.2.3