3a_asm: ghc flags
[calu.git] / 3a_asm / Text / Parsec / ByteString / Lazy.hs
1 -----------------------------------------------------------------------------
2 -- |
3 -- Module      :  Text.Parsec.ByteString.Lazy
4 -- Copyright   :  (c) Paolo Martini 2007
5 -- License     :  BSD-style (see the LICENSE file)
6 -- 
7 -- Maintainer  :  derek.a.elkins@gmail.com
8 -- Stability   :  provisional
9 -- Portability :  portable
10 --
11 -- Make lazy ByteStrings an instance of 'Stream' with 'Char' token type.
12 --
13 -----------------------------------------------------------------------------
14
15 {-# LANGUAGE FlexibleInstances, MultiParamTypeClasses #-}
16 {-# OPTIONS_GHC -fno-warn-orphans #-}
17
18 module Text.Parsec.ByteString.Lazy
19     ( Parser, GenParser, parseFromFile
20     ) where
21
22 import Text.Parsec.Error
23 import Text.Parsec.Prim
24
25 import qualified Data.ByteString.Lazy.Char8 as C
26
27 instance (Monad m) => Stream C.ByteString m Char where
28     uncons = return . C.uncons
29
30 type Parser = Parsec C.ByteString ()
31 type GenParser t st = Parsec C.ByteString st
32
33 -- | @parseFromFile p filePath@ runs a lazy bytestring parser @p@ on the
34 -- input read from @filePath@ using 'ByteString.Lazy.Char8.readFile'. Returns either a 'ParseError'
35 -- ('Left') or a value of type @a@ ('Right').
36 --
37 -- >  main    = do{ result <- parseFromFile numbers "digits.txt"
38 -- >              ; case result of
39 -- >                  Left err  -> print err
40 -- >                  Right xs  -> print (sum xs)
41 -- >              }
42 parseFromFile :: Parser a -> String -> IO (Either ParseError a)
43 parseFromFile p fname
44     = do input <- C.readFile fname
45          return (runP p () fname input)