| Portability | non-portable (mptcs, fundeps) |
|---|---|
| Stability | experimental |
| Maintainer | ekmett@gmail.com |
Text.Trifecta.Parser.ByteString
Description
Loading a file as a strict bytestring in one step.
Documentation
parseFromFile :: Show a => (forall r. Parser r 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 => (forall r. Parser r 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