Browse files

text and lazy text.

  • Loading branch information...
1 parent 8f4b177 commit 58c268c37e54a470c841c3ef5ecb7722f625552e @kazu-yamamoto committed Feb 8, 2011
Showing with 77 additions and 1 deletion.
  1. +37 −0 Text/Parsec/Text.hs
  2. +37 −0 Text/Parsec/Text/Lazy.hs
  3. +3 −1 parsec3.cabal
View
37 Text/Parsec/Text.hs
@@ -0,0 +1,37 @@
+-----------------------------------------------------------------------------
+-- |
+-- Module : Text.Parsec.Text
+-- Copyright : (c) Kazu Yamamoto 2010
+-- License : BSD-style (see the LICENSE file)
+--
+-- Maintainer : derek.a.elkins@gmail.com
+-- Stability : provisional
+-- Portability : portable
+--
+-- Make strict Texts an instance of 'Stream' with 'Char' token type.
+--
+-----------------------------------------------------------------------------
+
+{-# LANGUAGE FlexibleInstances, MultiParamTypeClasses #-}
+{-# OPTIONS_GHC -fno-warn-orphans #-}
+
+module Text.Parsec.Text (
+ Parser, GenParser, parseFromFile
+ ) where
+
+import Text.Parsec.Error
+import Text.Parsec.Prim
+
+import qualified Data.Text as T
+import qualified Data.Text.IO as T
+
+instance (Monad m) => Stream T.Text m Char where
+ uncons = return . T.uncons
+
+type Parser = Parsec T.Text ()
+type GenParser t st = Parsec T.Text st
+
+parseFromFile :: Parser a -> String -> IO (Either ParseError a)
+parseFromFile p fname = do
+ input <- T.readFile fname
+ return (runP p () fname input)
View
37 Text/Parsec/Text/Lazy.hs
@@ -0,0 +1,37 @@
+-----------------------------------------------------------------------------
+-- |
+-- Module : Text.Parsec.Text.Lazy
+-- Copyright : (c) Kazu Yamamoto 2010
+-- License : BSD-style (see the LICENSE file)
+--
+-- Maintainer : derek.a.elkins@gmail.com
+-- Stability : provisional
+-- Portability : portable
+--
+-- Make strict Texts an instance of 'Stream' with 'Char' token type.
+--
+-----------------------------------------------------------------------------
+
+{-# LANGUAGE FlexibleInstances, MultiParamTypeClasses #-}
+{-# OPTIONS_GHC -fno-warn-orphans #-}
+
+module Text.Parsec.Text.Lazy (
+ Parser, GenParser, parseFromFile
+ ) where
+
+import Text.Parsec.Error
+import Text.Parsec.Prim
+
+import qualified Data.Text.Lazy as T
+import qualified Data.Text.Lazy.IO as T
+
+instance (Monad m) => Stream T.Text m Char where
+ uncons = return . T.uncons
+
+type Parser = Parsec T.Text ()
+type GenParser t st = Parsec T.Text st
+
+parseFromFile :: Parser a -> String -> IO (Either ParseError a)
+parseFromFile p fname = do
+ input <- T.readFile fname
+ return (runP p () fname input)
View
4 parsec3.cabal
@@ -36,6 +36,8 @@ library
Text.Parsec.String,
Text.Parsec.ByteString,
Text.Parsec.ByteString.Lazy,
+ Text.Parsec.Text,
+ Text.Parsec.Text.Lazy,
Text.Parsec.Pos,
Text.Parsec.Error,
Text.Parsec.Prim,
@@ -45,6 +47,6 @@ library
Text.Parsec.Expr,
Text.Parsec.Language,
Text.Parsec.Perm
- build-depends: base >= 4 && < 5, mtl, bytestring
+ build-depends: base >= 4 && < 5, mtl, bytestring, text
extensions: DeriveDataTypeable, PolymorphicComponents, FlexibleInstances,
MultiParamTypeClasses, FlexibleContexts

0 comments on commit 58c268c

Please sign in to comment.