parsec-extra 0.1.0.5 → 0.2.0.0
raw patch · 3 files changed
+25/−15 lines, 3 filesdep −transformers
Dependencies removed: transformers
Files
- CHANGELOG.md +5/−0
- parsec-extra.cabal +3/−2
- src/Text/Parsec/Extra.hs +17/−13
+ CHANGELOG.md view
@@ -0,0 +1,5 @@+## 0.2.0.0++* Follow the transition from Error to Except: parseM now takes an additional+ argument specifying how to inject parse errors into the monad stack error+ type.
parsec-extra.cabal view
@@ -1,5 +1,5 @@ Name: parsec-extra-Version: 0.1.0.5+Version: 0.2.0.0 Cabal-Version: >= 1.6 License: BSD3 Author: Arie Peterson@@ -11,6 +11,8 @@ Also an alternative parse function, which throws a monadic error on parse failure. Build-Type: Simple +Extra-Source-Files: CHANGELOG.md+ Source-repository head Type: darcs Location: http://hub.darcs.net/AriePeterson/parsec-extra@@ -19,7 +21,6 @@ Build-Depends: base == 4.*, parsec == 3.*,- transformers >= 0.2 && < 0.5, monads-tf == 0.1.* Exposed-Modules: Text.Parsec.Extra
src/Text/Parsec/Extra.hs view
@@ -11,15 +11,16 @@ ) where -import Control.Applicative (Applicative,(<$>),(<*>),(<*),(*>),pure)-import Control.Monad.Error (Error,ErrorType,MonadError,throwError)-import Control.Monad.Trans.Error (noMsg,strMsg)-import Data.Char (toLower,toUpper)-import Data.List (foldl')-import Text.ParserCombinators.Parsec.Prim (GenParser,(<|>),(<?>),parse)-import Text.ParserCombinators.Parsec.Combinator (many1,option)-import qualified Text.ParserCombinators.Parsec.Char as Char-import Text.ParserCombinators.Parsec.Char (char)+import Control.Applicative ((<$>),(<*>),(<*),(*>),pure)+import Control.Monad.Error (ErrorType,MonadError,throwError)+import Data.Char (toLower,toUpper)+import Data.List (foldl')+import Text.Parsec.Prim ((<|>),(<?>),parse)+import Text.Parsec.Combinator (many1,option)+import qualified Text.Parsec.Char as Char+import Text.Parsec.Char (char)+import Text.Parsec.String (GenParser)+import Text.Parsec.Error (ParseError) -- | Parse \"end of line\": one of \"\\n\", \"\\r\\n\", or \"\\r\".@@ -32,11 +33,13 @@ -- | A natural (i.e. non-negative integer) number, in decimal notation. natural :: (Integral a) => GenParser Char state a-natural = (foldl' (\ a b -> a * 10 + b) 0 <$> many1 digit) <?> "nonnegative decimal integer"+natural = (foldl' (\ a b -> a * 10 + b) 0 <$> many1 digit)+ <?> "nonnegative decimal integer" -- | An integer number, in decimal notation (possibly prefixed with \"-\"). integer :: (Integral a) => GenParser Char state a-integer = (option id (char '-' *> pure negate) <*> natural) <?> "decimal integer"+integer = (option id (char '-' *> pure negate) <*> natural)+ <?> "decimal integer" -- | Parse the given character, or the same character in another case -- (upper or lower).@@ -53,5 +56,6 @@ -- | Parsing function. Uses the 'MonadError' class to throw a monadic error -- when parsing fails. (Useful in a stack of monad transformers from the -- transformers package <http://hackage.haskell.org/package/transformers>.)-parseM :: (MonadError m,Error (ErrorType m)) => GenParser t () a -> String -> [t] -> m a-parseM p s = either (throwError . strMsg . show) return . parse p s+parseM :: (MonadError m) =>+ (ParseError -> ErrorType m) -> GenParser t () a -> String -> [t] -> m a+parseM injectParseError p s = either (throwError . injectParseError) return . parse p s