Skip to content

Commit

Permalink
Merge pull request #53 from alpmestan/attoparsec-lookahead
Browse files Browse the repository at this point in the history
Add LookAheadParsing instance for attoparsec
  • Loading branch information
ekmett committed Jul 10, 2015
2 parents 1ef0799 + 17b63c2 commit 3bb0ead
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 9 deletions.
18 changes: 9 additions & 9 deletions parsers.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -47,15 +47,15 @@ library
ghc-options: -O2

build-depends:
base >= 4 && < 5,
charset >= 0.3 && < 1,
containers >= 0.4 && < 0.6,
parsec >= 3.1 && < 3.2,
attoparsec >= 0.12.1 && < 0.14,
text >= 0.10 && < 1.3,
transformers >= 0.2 && < 0.5,
scientific >= 0.3 && < 0.4,
unordered-containers >= 0.2 && < 0.3
base >= 4 && < 5,
charset >= 0.3 && < 1,
containers >= 0.4 && < 0.6,
parsec >= 3.1 && < 3.2,
attoparsec >= 0.12.1.4 && < 0.14,
text >= 0.10 && < 1.3,
transformers >= 0.2 && < 0.5,
scientific >= 0.3 && < 0.4,
unordered-containers >= 0.2 && < 0.3

-- Verify the results of the examples
test-suite doctests
Expand Down
5 changes: 5 additions & 0 deletions src/Text/Parser/LookAhead.hs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ import Control.Monad.Trans.RWS.Lazy as Lazy
import Control.Monad.Trans.RWS.Strict as Strict
import Control.Monad.Trans.Reader
import Control.Monad.Trans.Identity
import qualified Data.Attoparsec.Types as Att
import qualified Data.Attoparsec.Combinator as Att
import Data.Monoid
import qualified Text.ParserCombinators.ReadP as ReadP
import qualified Text.Parsec as Parsec
Expand Down Expand Up @@ -81,6 +83,9 @@ instance (LookAheadParsing m, Monad m) => LookAheadParsing (IdentityT m) where
instance (Parsec.Stream s m t, Show t) => LookAheadParsing (Parsec.ParsecT s u m) where
lookAhead = Parsec.lookAhead

instance Att.Chunk i => LookAheadParsing (Att.Parser i) where
lookAhead = Att.lookAhead

instance LookAheadParsing ReadP.ReadP where
lookAhead p = ReadP.look >>= \s ->
ReadP.choice $ map (return . fst) $ ReadP.readP_to_S p s

0 comments on commit 3bb0ead

Please sign in to comment.