3a_asm: ghc flags
[calu.git] / 3a_asm / Text / Parsec / String.hs
1 -----------------------------------------------------------------------------
2 -- |
3 -- Module      :  Text.Parsec.String
4 -- Copyright   :  (c) Paolo Martini 2007
5 -- License     :  BSD-style (see the file libraries/parsec/LICENSE)
6 -- 
7 -- Maintainer  :  derek.a.elkins@gmail.com
8 -- Stability   :  provisional
9 -- Portability :  portable
10 -- 
11 -- Make Strings 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.String
19     ( Parser, GenParser, parseFromFile
20     ) where
21
22 import Text.Parsec.Error
23 import Text.Parsec.Prim
24
25 instance (Monad m) => Stream [tok] m tok where
26     uncons []     = return $ Nothing
27     uncons (t:ts) = return $ Just (t,ts)
28
29 type Parser = Parsec String ()
30 type GenParser tok st = Parsec [tok] st
31
32 -- | @parseFromFile p filePath@ runs a string parser @p@ on the
33 -- input read from @filePath@ using 'Prelude.readFile'. Returns either a 'ParseError'
34 -- ('Left') or a value of type @a@ ('Right').
35 --
36 -- >  main    = do{ result <- parseFromFile numbers "digits.txt"
37 -- >              ; case result of
38 -- >                  Left err  -> print err
39 -- >                  Right xs  -> print (sum xs)
40 -- >              }
41 parseFromFile :: Parser a -> String -> IO (Either ParseError a)
42 parseFromFile p fname
43     = do input <- readFile fname
44          return (runP p () fname input)