Skip to content

Commit

Permalink
add Stream Text instances
Browse files Browse the repository at this point in the history
  • Loading branch information
aslatter committed Oct 8, 2011
1 parent 43087fe commit b7fed21
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 1 deletion.
31 changes: 31 additions & 0 deletions Text/Parsec/Text.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
-----------------------------------------------------------------------------
-- |
-- 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
--
-- Make Text an instance of 'Stream' with 'Char' token type.
--
-----------------------------------------------------------------------------

{-# LANGUAGE FlexibleInstances #-}
{-# OPTIONS_GHC -fno-warn-orphans #-}

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

import qualified Data.Text as Text
import Text.Parsec.Error
import Text.Parsec.Prim

instance (Monad m) => Stream Text.Text m Char where
uncons = return . Text.uncons
{-# INLINE uncons #-}

type Parser = Parsec Text.Text ()
type GenParser st = Parsec Text.Text st
31 changes: 31 additions & 0 deletions Text/Parsec/Text/Lazy.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
-----------------------------------------------------------------------------
-- |
-- 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
--
-- Make Text an instance of 'Stream' with 'Char' token type.
--
-----------------------------------------------------------------------------

{-# LANGUAGE FlexibleInstances #-}
{-# OPTIONS_GHC -fno-warn-orphans #-}

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

import qualified Data.Text.Lazy as Text
import Text.Parsec.Error
import Text.Parsec.Prim

instance (Monad m) => Stream Text.Text m Char where
uncons = return . Text.uncons
{-# INLINE uncons #-}

type Parser = Parsec Text.Text ()
type GenParser st = Parsec Text.Text st
4 changes: 3 additions & 1 deletion parsec.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -60,6 +62,6 @@ library
else
build-depends: base >= 3.0.3 && < 4
cpp-options: -DBASE3
build-depends: mtl, bytestring
build-depends: mtl, bytestring, text >= 0.2 && < 0.12
extensions: ExistentialQuantification, PolymorphicComponents, MultiParamTypeClasses, FlexibleInstances, FlexibleContexts, DeriveDataTypeable, CPP
ghc-options: -O2

0 comments on commit b7fed21

Please sign in to comment.