packages feed

parsers 0.7 → 0.7.1

raw patch · 3 files changed

+70/−9 lines, 3 filesdep +textPVP: major bump suggested

API removals or changes: PVP suggests a major version bump

Dependencies added: text

API changes (from Hackage documentation)

+ Text.Parser.Char: text :: CharParsing m => Text -> m Text
+ Text.Parser.Token: identText :: (TokenParsing m, Monad m) => IdentifierStyle m -> m Text
+ Text.Parser.Token: reserveText :: (TokenParsing m, Monad m) => IdentifierStyle m -> Text -> m ()
+ Text.Parser.Token: textLiteral :: TokenParsing m => m Text
+ Text.Parser.Token: textLiteral' :: TokenParsing m => m Text
+ Text.Parser.Token: textSymbol :: TokenParsing m => Text -> m Text
- Text.Parser.Char: anyChar :: (CharParsing m, CharParsing m) => m Char
+ Text.Parser.Char: anyChar :: CharParsing m => m Char
- Text.Parser.Char: char :: (CharParsing m, CharParsing m) => Char -> m Char
+ Text.Parser.Char: char :: CharParsing m => Char -> m Char
- Text.Parser.Char: class Parsing m => CharParsing m where satisfy = lift . satisfy char c = satisfy (c ==) <?> show [c] notChar c = satisfy (c /=) anyChar = satisfy (const True) string s = s <$ try (traverse_ char s) <?> show s
+ Text.Parser.Char: class Parsing m => CharParsing m where satisfy = lift . satisfy char c = satisfy (c ==) <?> show [c] notChar c = satisfy (c /=) anyChar = satisfy (const True) string s = s <$ try (traverse_ char s) <?> show s text t = t <$ string (unpack t)
- Text.Parser.Char: notChar :: (CharParsing m, CharParsing m) => Char -> m Char
+ Text.Parser.Char: notChar :: CharParsing m => Char -> m Char
- Text.Parser.Char: string :: (CharParsing m, CharParsing m) => String -> m String
+ Text.Parser.Char: string :: CharParsing m => String -> m String

Files

parsers.cabal view
@@ -1,6 +1,6 @@ name:          parsers category:      Text, Parsing-version:       0.7+version:       0.7.1 license:       BSD3 cabal-version: >= 1.10 license-file:  LICENSE@@ -49,6 +49,7 @@     base                 >= 4       && < 5,     charset              >= 0.3,     containers           >= 0.4     && < 0.6,+    text                 >= 0.10    && < 0.12,     transformers         >= 0.2     && < 0.4,     unordered-containers >= 0.2     && < 0.3 
src/Text/Parser/Char.hs view
@@ -60,6 +60,7 @@ import Data.Foldable import qualified Data.IntSet as IntSet import Data.Monoid+import Data.Text import Text.Parser.Combinators  -- | @oneOf cs@ succeeds if the current character is in the supplied@@ -179,18 +180,18 @@   -- /e.g./   --   -- @semiColon = 'char' ';'@-  char :: CharParsing m => Char -> m Char+  char :: Char -> m Char   char c = satisfy (c ==) <?> show [c]   {-# INLINE char #-}    -- | @notChar c@ parses any single character other than @c@. Returns the parsed   -- character.-  notChar :: CharParsing m => Char -> m Char+  notChar :: Char -> m Char   notChar c = satisfy (c /=)   {-# INLINE notChar #-}    -- | This parser succeeds for any character. Returns the parsed character.-  anyChar :: CharParsing m => m Char+  anyChar :: m Char   anyChar = satisfy (const True)   {-# INLINE anyChar #-} @@ -199,10 +200,20 @@   --   -- >  divOrMod    =   string "div"   -- >              <|> string "mod"-  string :: CharParsing m => String -> m String+  string :: String -> m String   string s = s <$ try (traverse_ char s) <?> show s   {-# INLINE string #-} +  -- | @text t@ parses a sequence of characters determined by the text @t@ Returns+  -- the parsed text fragment (i.e. @t@).+  --+  -- Using @OverloadedStrings@:+  --+  -- >  divOrMod    =   text "div"+  -- >              <|> text "mod"+  text :: Text -> m Text+  text t = t <$ string (unpack t)+  {-# INLINE text #-}  instance (CharParsing m, MonadPlus m) => CharParsing (Lazy.StateT s m) where   satisfy = lift . satisfy@@ -215,6 +226,8 @@   {-# INLINE anyChar #-}   string  = lift . string   {-# INLINE string #-}+  text = lift . text+  {-# INLINE text #-}  instance (CharParsing m, MonadPlus m) => CharParsing (Strict.StateT s m) where   satisfy = lift . satisfy@@ -227,6 +240,8 @@   {-# INLINE anyChar #-}   string  = lift . string   {-# INLINE string #-}+  text = lift . text+  {-# INLINE text #-}  instance (CharParsing m, MonadPlus m) => CharParsing (ReaderT e m) where   satisfy = lift . satisfy@@ -239,6 +254,8 @@   {-# INLINE anyChar #-}   string  = lift . string   {-# INLINE string #-}+  text = lift . text+  {-# INLINE text #-}  instance (CharParsing m, MonadPlus m, Monoid w) => CharParsing (Strict.WriterT w m) where   satisfy = lift . satisfy@@ -251,6 +268,8 @@   {-# INLINE anyChar #-}   string  = lift . string   {-# INLINE string #-}+  text = lift . text+  {-# INLINE text #-}  instance (CharParsing m, MonadPlus m, Monoid w) => CharParsing (Lazy.WriterT w m) where   satisfy = lift . satisfy@@ -263,6 +282,8 @@   {-# INLINE anyChar #-}   string  = lift . string   {-# INLINE string #-}+  text = lift . text+  {-# INLINE text #-}  instance (CharParsing m, MonadPlus m, Monoid w) => CharParsing (Lazy.RWST r w s m) where   satisfy = lift . satisfy@@ -275,6 +296,8 @@   {-# INLINE anyChar #-}   string  = lift . string   {-# INLINE string #-}+  text = lift . text+  {-# INLINE text #-}  instance (CharParsing m, MonadPlus m, Monoid w) => CharParsing (Strict.RWST r w s m) where   satisfy = lift . satisfy@@ -287,6 +310,8 @@   {-# INLINE anyChar #-}   string  = lift . string   {-# INLINE string #-}+  text = lift . text+  {-# INLINE text #-}  instance (CharParsing m, MonadPlus m) => CharParsing (IdentityT m) where   satisfy = lift . satisfy@@ -299,3 +324,5 @@   {-# INLINE anyChar #-}   string  = lift . string   {-# INLINE string #-}+  text = lift . text+  {-# INLINE text #-}
src/Text/Parser/Token.hs view
@@ -25,12 +25,15 @@   , charLiteral     -- :: TokenParsing m => m Char   , stringLiteral   -- :: TokenParsing m => m String   , stringLiteral'  -- :: TokenParsing m => m String+  , textLiteral     -- :: TokenParsing m => m Text+  , textLiteral'    -- :: TokenParsing m => m Text   , natural         -- :: TokenParsing m => m Integer   , integer         -- :: TokenParsing m => m Integer   , double          -- :: TokenParsing m => m Double   , naturalOrDouble -- :: TokenParsing m => m (Either Integer Double)   , integerOrDouble -- :: TokenParsing m => m (Either Integer Double)   , symbol          -- :: TokenParsing m => String -> m String+  , textSymbol      -- :: TokenParsing m => Text -> m Text   , symbolic        -- :: TokenParsing m => Char -> m Char   , parens          -- :: TokenParsing m => m a -> m a   , braces          -- :: TokenParsing m => m a -> m a@@ -61,6 +64,8 @@                         --    IdentifierStyle m -> IdentifierStyle (t m)   , ident           -- :: TokenParsing m => IdentifierStyle m -> m String   , reserve         -- :: TokenParsing m => IdentifierStyle m -> String -> m ()+  , identText       -- :: TokenParsing m => IdentifierStyle m -> m Text+  , reserveText     -- :: TokenParsing m => IdentifierStyle m -> Text -> m ()   -- ** Lenses and Traversals   , styleName   , styleStart@@ -89,6 +94,7 @@ import Data.HashSet (HashSet) import Data.List (foldl') import Data.Monoid+import Data.Text hiding (empty,zip,foldl,foldl') import Text.Parser.Char import Text.Parser.Combinators import Text.Parser.Token.Highlight@@ -133,6 +139,11 @@   escapeGap = skipSome space *> (char '\\' <?> "end of string gap") {-# INLINE stringLiteral #-} +-- | A version of 'stringLiteral' that returns 'Text' instead.+textLiteral :: TokenParsing m => m Text+textLiteral = pack <$> stringLiteral+{-# INLINE textLiteral #-}+ -- | This token parser behaves as 'stringLiteral', but for single-quoted -- strings. stringLiteral' :: TokenParsing m => m String@@ -153,6 +164,11 @@   escapeGap = skipSome space *> (char '\\' <?> "end of string gap") {-# INLINE stringLiteral' #-} +-- | A version of 'stringLiteral'' that returns 'Text' instead.+textLiteral' :: TokenParsing m => m Text+textLiteral' = pack <$> stringLiteral'+{-# INLINE textLiteral' #-}+ -- | This token parser parses a natural number (a positive whole -- number). Returns the value of the number. The number can be -- specified in 'decimal', 'hexadecimal' or@@ -196,8 +212,8 @@ integerOrDouble :: TokenParsing m => m (Either Integer Double) integerOrDouble = token (highlight Number iod <?> "number")   where iod = mneg <$> optional (oneOf "+-") <*> natDouble-	mneg (Just '-') nd = either (Left . negate) (Right . negate) nd-	mneg _          nd = nd+        mneg (Just '-') nd = either (Left . negate) (Right . negate) nd+        mneg _          nd = nd {-# INLINE integerOrDouble #-}  -- | Token parser @symbol s@ parses 'string' @s@ and skips@@ -206,6 +222,12 @@ symbol name = token (highlight Symbol (string name)) {-# INLINE symbol #-} +-- | Token parser @textSymbol t@ parses 'text' @s@ and skips+-- trailing white space.+textSymbol :: TokenParsing m => Text -> m Text+textSymbol name = token (highlight Symbol (text name))+{-# INLINE textSymbol #-}+ -- | Token parser @symbolic s@ parses 'char' @s@ and skips -- trailing white space. symbolic :: TokenParsing m => Char -> m Char@@ -488,7 +510,14 @@    notFollowedBy (_styleLetter s) <?> "end of " ++ show name {-# INLINE reserve #-} --- | parse an non-reserved identifier or symbol+-- | parse a reserved operator or identifier using a given style given 'Text'.+reserveText :: (TokenParsing m, Monad m) => IdentifierStyle m -> Text -> m ()+reserveText s name = token $ try $ do+   _ <- highlight (_styleReservedHighlight s) $ text name+   notFollowedBy (_styleLetter s) <?> "end of " ++ show name+{-# INLINE reserveText #-}++-- | Parse a non-reserved identifier or symbol ident :: (TokenParsing m, Monad m) => IdentifierStyle m -> m String ident s = token $ try $ do   name <- highlight (_styleHighlight s)@@ -497,8 +526,12 @@   return name {-# INLINE ident #-} --- * Utilities+-- | Parse a non-reserved identifier or symbol (as 'Text').+identText :: (TokenParsing m, Monad m) => IdentifierStyle m -> m Text+identText s = pack <$> ident s+{-# INLINE identText #-} +-- * Utilities  -- | This parser parses a character literal without the surrounding quotation marks. --