trifecta-0.36.1: A modern parser combinator library with convenient diagnostics

Portabilitynon-portable (mptcs, fundeps)
Stabilityexperimental
Maintainerekmett@gmail.com

Text.Trifecta.Parser.ByteString

Description

Loading a file as a strict bytestring in one step.

Synopsis

Documentation

parseFromFile :: Show a => Parser String a -> String -> IO (Maybe a)Source

parseFromFile p filePath runs a parser p on the input read from filePath using ByteString.readFile. All diagnostic messages emitted over the course of the parse attempt are shown to the user on the console.

 main = do
   result <- parseFromFile numbers "digits.txt"
   case result of
     Nothing -> return ()
     Just a  -> print $ sum a

parseFromFileEx :: Show a => Parser String a -> String -> IO (Result TermDoc a)Source

parseFromFileEx p filePath runs a parser p on the input read from filePath using ByteString.readFile. Returns all diagnostic messages emitted over the course of the parse and the answer if the parse was successful.

 main = do
   result <- parseFromFileEx (many number) "digits.txt"
   case result of
     Failure xs -> unless (Seq.null xs) $ displayLn xs
     Success xs a  -> 
       unless (Seq.null xs) $ displayLn xs
       print $ sum a