{-# LANGUAGE Safe #-}

-----------------------------------------------------------------------------
-- |
-- Module      :  Text.Parsec.String
-- Copyright   :  (c) Antoine Latter 2011
-- License     :  BSD-style (see the file libraries/parsec/LICENSE)
--
-- Maintainer  :  aslatter@gmail.com
-- Stability   :  provisional
-- Portability :  portable
--
-- Convinience definitions for working with 'Text.Text'.
--
-----------------------------------------------------------------------------

module Text.Parsec.Text
    ( Parser, GenParser, parseFromFile
    ) where

import qualified Data.Text as Text
import qualified Data.Text.IO as T

import Text.Parsec.Prim
import Text.Parsec.Error

type Parser = Parsec Text.Text ()
type GenParser st = Parsec Text.Text st

-- | @parseFromFile p filePath@ runs a strict text parser @p@ on the
-- input read from @filePath@ using 'Data.Text.IO.readFile'. Returns either a 'ParseError'
-- ('Left') or a value of type @a@ ('Right').
--
-- >  main    = do{ result <- parseFromFile numbers "digits.txt"
-- >              ; case result of
-- >                  Left err  -> print err
-- >                  Right xs  -> print (sum xs)
-- >              }
--
-- @since 3.1.14.0

parseFromFile :: Parser a -> FilePath -> IO (Either ParseError a)
parseFromFile :: forall a. Parser a -> FilePath -> IO (Either ParseError a)
parseFromFile Parser a
p FilePath
fname
    = do Text
input <- FilePath -> IO Text
T.readFile FilePath
fname
         forall (m :: * -> *) a. Monad m => a -> m a
return (forall s t u a.
Stream s Identity t =>
Parsec s u a -> u -> FilePath -> s -> Either ParseError a
runP Parser a
p () FilePath
fname Text
input)