packages feed

parsers 0.9 → 0.10

raw patch · 6 files changed

+96/−40 lines, 6 filesdep +parsecdep ~charset

Dependencies added: parsec

Dependency ranges changed: charset

Files

parsers.cabal view
@@ -1,6 +1,6 @@ name:          parsers category:      Text, Parsing-version:       0.9+version:       0.10 license:       BSD3 cabal-version: >= 1.10 license-file:  LICENSE@@ -47,8 +47,9 @@    build-depends:     base                 >= 4       && < 5,-    charset              >= 0.3,+    charset              >= 0.3     && < 1,     containers           >= 0.4     && < 0.6,+    parsec               >= 3.1     && < 3.2,     text                 >= 0.10    && < 0.12,     transformers         >= 0.2     && < 0.4,     unordered-containers >= 0.2     && < 0.3
src/Text/Parser/Char.hs view
@@ -1,4 +1,5 @@ {-# LANGUAGE CPP #-}+{-# LANGUAGE FlexibleContexts #-} {-# OPTIONS_GHC -fspec-constr -fspec-constr-count=8 #-}  #if defined(__GLASGOW_HASKELL__) && __GLASGOW_HASKELL__ >= 704@@ -61,6 +62,8 @@ import qualified Data.IntSet as IntSet import Data.Monoid import Data.Text+import qualified Text.ParserCombinators.ReadP as ReadP+import qualified Text.Parsec as Parsec import Text.Parser.Combinators  -- | @oneOf cs@ succeeds if the current character is in the supplied@@ -326,3 +329,17 @@   {-# INLINE string #-}   text = lift . text   {-# INLINE text #-}++instance Parsec.Stream s m Char => CharParsing (Parsec.ParsecT s u m) where+  satisfy   = Parsec.satisfy+  char      = Parsec.char+  notChar c = Parsec.satisfy (/= c)+  anyChar   = Parsec.anyChar+  string    = Parsec.string++instance CharParsing ReadP.ReadP where+  satisfy   = ReadP.satisfy+  char      = ReadP.char+  notChar c = ReadP.satisfy (/= c)+  anyChar   = ReadP.get+  string    = ReadP.string
src/Text/Parser/Combinators.hs view
@@ -1,4 +1,5 @@ {-# LANGUAGE CPP #-}+{-# LANGUAGE UndecidableInstances #-}  #if defined(__GLASGOW_HASKELL__) && __GLASGOW_HASKELL__ >= 704 #define USE_DEFAULT_SIGNATURES@@ -8,6 +9,14 @@ {-# LANGUAGE DefaultSignatures, TypeFamilies #-} #endif +#if !MIN_VERSION_base(4,6,0)+#define ORPHAN_ALTERNATIVE_READP+#endif++#ifdef ORPHAN_ALTERNATIVE_READP+{-# OPTIONS_GHC -fno-warn-orphans #-}+#endif+ ----------------------------------------------------------------------------- -- | -- Module      :  Text.Parser.Combinators@@ -48,7 +57,7 @@   ) where  import Control.Applicative-import Control.Monad (MonadPlus(..))+import Control.Monad (MonadPlus(..), ap) import Control.Monad.Trans.Class import Control.Monad.Trans.State.Lazy as Lazy import Control.Monad.Trans.State.Strict as Strict@@ -61,6 +70,8 @@ import Data.Foldable (asum) import Data.Monoid import Data.Traversable (sequenceA)+import qualified Text.Parsec as Parsec+import qualified Text.ParserCombinators.ReadP as ReadP  -- | @choice ps@ tries to apply the parsers in the list @ps@ in order, -- until one of them succeeds. Returns the value of the succeeding@@ -346,3 +357,30 @@   {-# INLINE unexpected #-}   eof = lift eof   {-# INLINE eof #-}++instance (Parsec.Stream s m t, Show t) => Parsing (Parsec.ParsecT s u m) where+  try           = Parsec.try+  (<?>)         = (Parsec.<?>)+  skipMany      = Parsec.skipMany+  skipSome      = Parsec.skipMany1+  unexpected    = Parsec.unexpected+  eof           = Parsec.eof+  notFollowedBy = Parsec.notFollowedBy++instance Parsing ReadP.ReadP where+  try        = id+  (<?>)      = const+  skipMany   = ReadP.skipMany+  skipSome   = ReadP.skipMany1+  unexpected = const ReadP.pfail+  eof        = ReadP.eof++#ifdef ORPHAN_ALTERNATIVE_READP+instance Applicative ReadP.ReadP where+  pure = return+  (<*>) = ap++instance Alternative ReadP.ReadP where+  empty = mzero+  (<|>) = mplus+#endif
src/Text/Parser/Expression.hs view
@@ -1,4 +1,5 @@ {-# LANGUAGE DeriveDataTypeable #-}+{-# LANGUAGE ScopedTypeVariables #-} ----------------------------------------------------------------------------- -- | -- Module      :  Text.Parser.Expression@@ -90,7 +91,7 @@ -- >  prefix  name fun       = Prefix (fun <* reservedOp name) -- >  postfix name fun       = Postfix (fun <* reservedOp name) -buildExpressionParser :: (Parsing m, Monad m)+buildExpressionParser :: forall m a. (Parsing m, Applicative m)                       => OperatorTable m a                       -> m a                       -> m a@@ -99,62 +100,44 @@     where       makeParser term ops         = let (rassoc,lassoc,nassoc,prefix,postfix) = foldr splitOp ([],[],[],[],[]) ops-               rassocOp   = choice rassoc               lassocOp   = choice lassoc               nassocOp   = choice nassoc               prefixOp   = choice prefix  <?> ""               postfixOp  = choice postfix <?> "" -              ambiguous assoc op= try $ op *> fail ("ambiguous use of a " ++ assoc ++ " associative operator")+              ambiguous assoc op= op *> empty <?> ("ambiguous use of a " ++ assoc ++ "-associative operator")                ambiguousRight    = ambiguous "right" rassocOp               ambiguousLeft     = ambiguous "left" lassocOp               ambiguousNon      = ambiguous "non" nassocOp -              termP      = do { pre <- prefixP-                              ; x <- term-                              ; post <- postfixP-                              ; return (post (pre x))-                              }+              termP      = (prefixP <*> term) <**> postfixP -              postfixP   = postfixOp <|> return id+              postfixP   = postfixOp <|> pure id -              prefixP    = prefixOp <|> return id+              prefixP    = prefixOp <|> pure id -              rassocP x  = do{ f <- rassocOp-                             ; y <- termP >>= rassocP1-                             ; return (f x y)-                             }-                           <|> ambiguousLeft-                           <|> ambiguousNon-                           -- <|> return x+              rassocP, rassocP1, lassocP, lassocP1, nassocP :: m (a -> a) -              rassocP1 x = rassocP x <|> return x+              rassocP  = (flip <$> rassocOp <*> (termP <**> rassocP1)+                          <|> ambiguousLeft+                          <|> ambiguousNon) -              lassocP x  = do{ f <- lassocOp-                             ; y <- termP-                             ; lassocP1 (f x y)-                             }-                           <|> ambiguousRight-                           <|> ambiguousNon-                           -- <|> return x+              rassocP1 = rassocP <|> pure id -              lassocP1 x = lassocP x <|> return x+              lassocP  = ((flip <$> lassocOp <*> termP) <**> ((.) <$> lassocP1)+                          <|> ambiguousRight+                          <|> ambiguousNon) -              nassocP x  = do{ f <- nassocOp-                             ; y <- termP-                             ;    ambiguousRight+              lassocP1 = lassocP <|> pure id++              nassocP = (flip <$> nassocOp <*> termP)+                        <**> (ambiguousRight                               <|> ambiguousLeft                               <|> ambiguousNon-                              <|> return (f x y)-                             }-                           -- <|> return x--           in  do{ x <- termP-                 ; rassocP x <|> lassocP  x <|> nassocP x <|> return x-                   <?> "operator"-                 }+                              <|> pure id)+           in termP <**> (rassocP <|> lassocP <|> nassocP <|> pure id) <?> "operator"         splitOp (Infix op assoc) (rassoc,lassoc,nassoc,prefix,postfix)
src/Text/Parser/LookAhead.hs view
@@ -1,4 +1,5 @@ {-# LANGUAGE CPP #-}+{-# LANGUAGE UndecidableInstances #-}  #if defined(__GLASGOW_HASKELL__) && __GLASGOW_HASKELL__ >= 704 #define USE_DEFAULT_SIGNATURES@@ -36,6 +37,8 @@ import Control.Monad.Trans.Reader import Control.Monad.Trans.Identity import Data.Monoid+import qualified Text.ParserCombinators.ReadP as ReadP+import qualified Text.Parsec as Parsec import Text.Parser.Combinators  -- | Additional functionality needed to describe parsers independent of input type.@@ -74,3 +77,10 @@ instance (LookAheadParsing m, Monad m) => LookAheadParsing (IdentityT m) where   lookAhead = IdentityT . lookAhead . runIdentityT   {-# INLINE lookAhead #-}++instance (Parsec.Stream s m t, Show t) => LookAheadParsing (Parsec.ParsecT s u m) where+  lookAhead = Parsec.lookAhead++instance LookAheadParsing ReadP.ReadP where+  lookAhead p = ReadP.look >>= \s ->+                ReadP.choice $ map (return . fst) $ ReadP.readP_to_S p s
src/Text/Parser/Token.hs view
@@ -1,3 +1,4 @@+{-# LANGUAGE FlexibleContexts #-} {-# LANGUAGE GeneralizedNewtypeDeriving #-} {-# OPTIONS_GHC -fspec-constr -fspec-constr-count=8 #-} {-# LANGUAGE CPP #-}@@ -96,6 +97,8 @@ import Data.Monoid import Data.String import Data.Text hiding (empty,zip,foldl,foldl')+import qualified Text.ParserCombinators.ReadP as ReadP+import qualified Text.Parsec as Parsec import Text.Parser.Char import Text.Parser.Combinators import Text.Parser.Token.Highlight@@ -720,3 +723,7 @@   {-# INLINE semi #-}   highlight h (Unlined m) = Unlined (highlight h m)   {-# INLINE highlight #-}++instance Parsec.Stream s m Char => TokenParsing (Parsec.ParsecT s u m)++instance TokenParsing ReadP.ReadP