Skip to content

Commit

Permalink
misc: add pretty print to error bundle of example
Browse files Browse the repository at this point in the history
  • Loading branch information
cptrodolfox committed Sep 4, 2024
1 parent 440f886 commit e04f15c
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
1 change: 1 addition & 0 deletions cassava-megaparsec.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ executable cassava-megaparsec-example
, cassava-megaparsec
, text
, vector
, megaparsec
default-language: Haskell2010

test-suite tests
Expand Down
12 changes: 7 additions & 5 deletions example/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,18 @@

module Main where

import Data.Csv hiding (decode, decodeByName, decodeByNameWith, decodeWith)
import Data.Csv.Parser.Megaparsec (decode, decodeByName, decodeByNameWith, decodeWith)
import Data.Vector (Vector)
import Data.Csv (FromRecord, HasHeader (NoHeader))
import Data.Csv.Parser.Megaparsec (decode)
import GHC.Generics (Generic)
import Text.Megaparsec.Error (errorBundlePretty)

data Test = Test {a :: Char, b :: Char, c :: Char} deriving (Eq, Show, Generic)

instance FromRecord Test

main :: IO ()
main = do
let res = decode @Test NoHeader "example" "a,ba,c\n"
print res
let res = decode @Test NoHeader "example.csv" "a,ba,c\n"
case res of
Left errorBundle -> putStrLn $ errorBundlePretty errorBundle
Right value -> print value

0 comments on commit e04f15c

Please sign in to comment.