polyparse 1.12.1 → 1.13.1
raw patch · 20 files changed
Files
- Changelog.md +14/−1
- README.md +12/−0
- polyparse.cabal +48/−47
- src/Text/Parse.hs +18/−18
- src/Text/Parse/ByteString.hs +16/−16
- src/Text/ParserCombinators/HuttonMeijer.hs +9/−7
- src/Text/ParserCombinators/HuttonMeijerWallace.hs +3/−0
- src/Text/ParserCombinators/Poly/Base.hs +20/−19
- src/Text/ParserCombinators/Poly/ByteString.hs +5/−2
- src/Text/ParserCombinators/Poly/ByteStringChar.hs +5/−2
- src/Text/ParserCombinators/Poly/Lazy.hs +10/−8
- src/Text/ParserCombinators/Poly/Lex.hs +6/−3
- src/Text/ParserCombinators/Poly/Parser.hs +12/−9
- src/Text/ParserCombinators/Poly/Plain.hs +9/−9
- src/Text/ParserCombinators/Poly/Result.hs +1/−1
- src/Text/ParserCombinators/Poly/State.hs +8/−8
- src/Text/ParserCombinators/Poly/StateLazy.hs +10/−8
- src/Text/ParserCombinators/Poly/StateParser.hs +12/−9
- src/Text/ParserCombinators/Poly/StateText.hs +5/−2
- src/Text/ParserCombinators/Poly/Text.hs +5/−2
Changelog.md view
@@ -1,4 +1,17 @@+## 1.13.1++_Andreas Abel, 2025-09-14_++- Remove support for GHC 7.+- Add support for MicroHs.+- Build tested with GHC 8.0 - 9.14 alpha1.++## 1.13++- GHC-8.8 compatibility+- PolyParse has MonadFail as a superclass.+ ## 1.12.1 - GHC-8.6 compatibility- - MonadFail instances+- MonadFail instances
+ README.md view
@@ -0,0 +1,12 @@+[](http://hackage.haskell.org/package/polyparse)+[](https://www.stackage.org/package/polyparse)+[](https://stackage.org/nightly/package/polyparse)+[](https://github.com/haskell-pkg-janitors/polyparse/actions)++# polyparse++A variety of alternative parser combinator libraries.++Description see: https://hackage.haskell.org/package/polyparse++Old homepage: https://archives.haskell.org/projects.haskell.org/polyparse/
polyparse.cabal view
@@ -1,79 +1,80 @@+cabal-version: 1.18 name: polyparse-version: 1.12.1+version: 1.13.1 license: LGPL-license-files: COPYRIGHT, LICENCE-LGPL, LICENCE-commercial+license-files: COPYRIGHT, LICENCE-LGPL, LICENCE-commercial copyright: (c) 2006-2016 Malcolm Wallace author: Malcolm Wallace <Malcolm.Wallace@me.com>-maintainer: author-homepage: http://code.haskell.org/~malcolm/polyparse/-bug-reports: https://github.com/haskell-infra/hackage-trustees/issues+maintainer: Andreas Abel+-- homepage:+bug-reports: https://github.com/haskell-pkg-janitors/polyparse/issues category: Text, Parsing synopsis: A variety of alternative parser combinator libraries. description:- This version, 1.12.1 is a Non-Maintainer Upload (NMU). Report issues to the Hackage Trustees issue tracker.- . A variety of alternative parser combinator libraries, including the original HuttonMeijer set. The Poly sets have features like good error reporting, arbitrary token type, running state, lazy parsing, and so on. Finally, Text.Parse is a proposed replacement for the standard Read class, for better deserialisation of Haskell values from Strings.+ .+ Old homepage: <https://archives.haskell.org/projects.haskell.org/polyparse/>+ build-type: Simple-cabal-version: >=1.8-extra-source-files: Changelog.md +extra-doc-files:+ Changelog.md+ README.md+ tested-with:- GHC ==8.6.1- || ==8.4.4- || ==8.2.2- || ==8.0.2- || ==7.10.3- || ==7.8.4- || ==7.6.3- || ==7.4.2- || ==7.2.2- || ==7.0.4+ GHC == 9.14.1+ GHC == 9.12.2+ GHC == 9.10.2+ GHC == 9.8.4+ GHC == 9.6.7+ GHC == 9.4.8+ GHC == 9.2.8+ GHC == 9.0.2+ GHC == 8.10.7+ GHC == 8.8.4+ GHC == 8.6.5+ GHC == 8.4.4+ GHC == 8.2.2+ GHC == 8.0.2 source-repository head- type: darcs- location: http://code.haskell.org/polyparse--source-repository this type: git- location: https://github.com/hackage-/malcolm-wallace-universe.git- tag: 1.12.1+ location: https://github.com/haskell-pkg-janitors/polyparse.git library hs-source-dirs: src- build-depends: base >= 4.3.1.0 && < 4.13 - if !impl(ghc >= 8.0)- build-depends: fail == 4.9.*- exposed-modules:- Text.ParserCombinators.HuttonMeijer,- Text.ParserCombinators.HuttonMeijerWallace,- Text.ParserCombinators.Poly,- Text.ParserCombinators.Poly.Base,- Text.ParserCombinators.Poly.Result,- Text.ParserCombinators.Poly.Parser,- Text.ParserCombinators.Poly.Plain,- Text.ParserCombinators.Poly.Lazy,- Text.ParserCombinators.Poly.StateParser,- Text.ParserCombinators.Poly.State,- Text.ParserCombinators.Poly.StateLazy,- Text.ParserCombinators.Poly.Lex,+ Text.ParserCombinators.HuttonMeijer+ Text.ParserCombinators.HuttonMeijerWallace+ Text.ParserCombinators.Poly+ Text.ParserCombinators.Poly.Base+ Text.ParserCombinators.Poly.Result+ Text.ParserCombinators.Poly.Parser+ Text.ParserCombinators.Poly.Plain+ Text.ParserCombinators.Poly.Lazy+ Text.ParserCombinators.Poly.StateParser+ Text.ParserCombinators.Poly.State+ Text.ParserCombinators.Poly.StateLazy+ Text.ParserCombinators.Poly.Lex Text.Parse++ build-depends: base >= 4.9 && < 5+ if impl(ghc)- build-depends: bytestring >= 0.9.1.0 && < 0.11- build-depends: text >= 1.2.3.0 && <1.3+ build-depends: bytestring >= 0.9.1.0 && < 0.13+ build-depends: text >= 1.2.3.0 && < 1.3 || >= 2.0 && < 3 exposed-modules: Text.ParserCombinators.Poly.ByteString Text.ParserCombinators.Poly.ByteStringChar Text.Parse.ByteString Text.ParserCombinators.Poly.Text Text.ParserCombinators.Poly.StateText--- Text.Parse.Text- cpp-options: -DVERSION="1.12"- nhc98-options: -K6M- extensions: CPP++ default-language: Haskell2010+ default-extensions: CPP
src/Text/Parse.hs view
@@ -1,19 +1,19 @@ module Text.Parse- ( -- * The Parse class is a replacement for the standard Read class. + ( -- * The Parse class is a replacement for the standard Read class. -- $parser- TextParser -- synonym for Parser Char, i.e. string input, no state- , Parse(..) -- instances: (), (a,b), (a,b,c), Maybe a, Either a, [a],- -- Int, Integer, Float, Double, Char, Bool- , parseByRead -- :: Read a => String -> TextParser a+ TextParser -- synonym for Parser Char, i.e. string input, no state+ , Parse(..) -- instances: (), (a,b), (a,b,c), Maybe a, Either a, [a],+ -- Int, Integer, Float, Double, Char, Bool+ , parseByRead -- :: Read a => String -> TextParser a , readByParse -- :: TextParser a -> ReadS a , readsPrecByParsePrec -- :: (Int->TextParser a) -> Int -> ReadS a -- ** Combinators specific to string input, lexed haskell-style- , word -- :: TextParser String- , isWord -- :: String -> TextParser ()- , literal -- :: String -> TextParser ()- , optionalParens -- :: TextParser a -> TextParser a- , parens -- :: Bool -> TextParser a -> TextParser a- , field -- :: Parse a => String -> TextParser a+ , word -- :: TextParser String+ , isWord -- :: String -> TextParser ()+ , literal -- :: String -> TextParser ()+ , optionalParens -- :: TextParser a -> TextParser a+ , parens -- :: Bool -> TextParser a -> TextParser a+ , field -- :: Parse a => String -> TextParser a , constructors-- :: [(String,TextParser a)] -> TextParser a , enumeration -- :: Show a => String -> [a] -> TextParser a -- ** Parsers for literal numerics and characters@@ -65,7 +65,7 @@ parsePrec _ = optionalParens parse -- | Parsing a list of items by default accepts the [] and comma syntax, -- except when the list is really a character string using \"\".- parseList :: TextParser [a] -- only to distinguish [] and ""+ parseList :: TextParser [a] -- only to distinguish [] and "" parseList = do { isWord "[]"; return [] } `onFail` do { isWord "["; isWord "]"; return [] }@@ -237,7 +237,7 @@ parseInt base radix isDigit digitToInt = do cs <- many1 (satisfy isDigit) return (foldl1 (\n d-> n*radix+d)- (map (fromIntegral.digitToInt) cs))+ (map (fromIntegral . digitToInt) cs)) `adjustErr` (++("\nexpected one or more "++base++" digits")) parseDec, parseOct, parseHex :: (Integral a) => TextParser a parseDec = parseInt "decimal" 10 Char.isDigit Char.digitToInt@@ -252,10 +252,10 @@ `onFail` return [] ) exp <- exponent `onFail` return 0 ( return . fromRational . (* (10^^(exp - length frac)))- . (%1) . (\ (Right x)->x) . fst+ . (% 1) . (\ (Right x) -> x) . fst . runParser parseDec ) (ds++frac) `onFail`- do w <- many (satisfy (not.isSpace))+ do w <- many (satisfy (not . isSpace)) case map toLower w of "nan" -> return (0/0) "infinity" -> return (1/0)@@ -377,7 +377,7 @@ -- Basic types instance Parse Int where- -- parse = parseByRead "Int" -- convert from Integer, deals with minInt+ -- parse = parseByRead "Int" -- convert from Integer, deals with minInt parse = fmap fromInteger $ do many (satisfy isSpace); parseSigned parseDec instance Parse Integer where@@ -396,7 +396,7 @@ -- else fail "expected a char" } -- parseList = bracket (isWord "\"") (satisfy (=='"')) -- (many (satisfy (/='"')))- -- not totally correct for strings...+ -- not totally correct for strings... parseList = do { w <- word; if head w == '"' then return (init (tail w)) else fail "not a string" } @@ -441,7 +441,7 @@ parens (p>9) (do { isWord "Just" ; fmap Just $ parsePrec 10 `adjustErrBad` ("but within Just, "++) })- `adjustErr` (("expected a Maybe (Just or Nothing)\n"++).indent 2)+ `adjustErr` (("expected a Maybe (Just or Nothing)\n"++) . indent 2) instance (Parse a, Parse b) => Parse (Either a b) where parsePrec p =
src/Text/Parse/ByteString.hs view
@@ -1,20 +1,20 @@ module Text.Parse.ByteString- ( -- * The Parse class is a replacement for the standard Read class. + ( -- * The Parse class is a replacement for the standard Read class. -- This particular instance reads from ByteString rather than String. -- $parser- TextParser -- synonym for Text.ParserCombinators.Poly.ByteString- , Parse(..) -- instances: (), (a,b), (a,b,c), Maybe a, Either a, [a],- -- Int, Integer, Float, Double, Char, Bool- , parseByRead -- :: Read a => String -> TextParser a+ TextParser -- synonym for Text.ParserCombinators.Poly.ByteString+ , Parse(..) -- instances: (), (a,b), (a,b,c), Maybe a, Either a, [a],+ -- Int, Integer, Float, Double, Char, Bool+ , parseByRead -- :: Read a => String -> TextParser a , readByParse -- :: TextParser a -> ReadS a , readsPrecByParsePrec -- :: (Int->TextParser a) -> Int -> ReadS a -- ** Combinators specific to bytestring input, lexed haskell-style- , word -- :: TextParser String- , isWord -- :: String -> TextParser ()- , literal -- :: String -> TextParser ()- , optionalParens -- :: TextParser a -> TextParser a- , parens -- :: Bool -> TextParser a -> TextParser a- , field -- :: Parse a => String -> TextParser a+ , word -- :: TextParser String+ , isWord -- :: String -> TextParser ()+ , literal -- :: String -> TextParser ()+ , optionalParens -- :: TextParser a -> TextParser a+ , parens -- :: Bool -> TextParser a -> TextParser a+ , field -- :: Parse a => String -> TextParser a , constructors-- :: [(String,TextParser a)] -> TextParser a , enumeration -- :: Show a => String -> [a] -> TextParser a -- ** Parsers for literal numerics and characters@@ -72,7 +72,7 @@ parsePrec _ = optionalParens parse -- | Parsing a list of items by default accepts the [] and comma syntax, -- except when the list is really a character string using \"\".- parseList :: TextParser [a] -- only to distinguish [] and ""+ parseList :: TextParser [a] -- only to distinguish [] and "" parseList = do { isWord "[]"; return [] } `onFail` do { isWord "["; isWord "]"; return [] }@@ -271,7 +271,7 @@ parseInt base radix isDigit digitToInt = do cs <- many1 (satisfy isDigit) return (foldl1 (\n d-> n*radix+d)- (map (fromIntegral.digitToInt) cs))+ (map (fromIntegral . digitToInt) cs)) `adjustErr` (++("\nexpected one or more "++base++" digits")) -- | Parse a decimal, octal, or hexadecimal (unsigned) Integral numeric literal.@@ -301,7 +301,7 @@ `onFail` return BS.empty ) exp <- exponent `onFail` return 0 ( return . fromRational . (* (10^^(exp - BS.length frac)))- . (%1) . (\ (Right x)->x) . fst+ . (% 1) . (\ (Right x) -> x) . fst . runParser parseDec ) (ds `BS.append` frac) `onFail` do w <- manySatisfy isAlpha@@ -426,7 +426,7 @@ -- Basic types instance Parse Int where- parse = fmap fromInteger $ -- convert from Integer, deals with minInt+ parse = fmap fromInteger $ -- convert from Integer, deals with minInt do manySatisfy isSpace; parseSigned parseUnsignedInteger instance Parse Integer where parse = do manySatisfy isSpace; parseSigned parseUnsignedInteger@@ -436,7 +436,7 @@ parse = do manySatisfy isSpace; parseSigned parseFloat instance Parse Char where parse = do manySatisfy isSpace; parseLitChar'- -- not totally correct for strings...+ -- not totally correct for strings... parseList = do { w <- word; if head w == '"' then return (init (tail w)) else fail "not a string" }
src/Text/ParserCombinators/HuttonMeijer.hs view
@@ -3,25 +3,25 @@ -- Module : Text.ParserCombinators.HuttonMeijer -- Copyright : Graham Hutton (University of Nottingham), Erik Meijer (University of Utrecht) -- Licence : BSD--- +-- -- Maintainer : Malcolm Wallace <Malcolm.Wallace@cs.york.ac.uk> -- Stability : Stable -- Portability : All -- -- A LIBRARY OF MONADIC PARSER COMBINATORS--- +-- -- 29th July 1996--- +-- -- Graham Hutton Erik Meijer -- University of Nottingham University of Utrecht--- +-- -- This Haskell script defines a library of parser combinators, and is -- taken from sections 1-6 of our article "Monadic Parser Combinators". -- Some changes to the library have been made in the move from Gofer -- to Haskell:--- +-- -- * Do notation is used in place of monad comprehension notation;--- +-- -- * The parser datatype is defined using "newtype", to avoid the overhead -- of tagging and untagging parsers with the P constructor. -----------------------------------------------------------------------------@@ -63,7 +63,9 @@ -- >>= :: Parser a -> (a -> Parser b) -> Parser b (P p) >>= f = P (\inp -> concat [papply (f v) out | (v,out) <- p inp]) +#if !MIN_VERSION_base(4,13,0) fail = Fail.fail+#endif instance Fail.MonadFail Parser where -- fail :: String -> Parser a@@ -193,7 +195,7 @@ comment :: Parser () --comment = do {string "--"; many (sat (\x -> x /= '\n')); return ()}---comment = do +--comment = do -- _ <- string "--" -- _ <- many (sat (\x -> x /= '\n')) -- return ()
src/Text/ParserCombinators/HuttonMeijerWallace.hs view
@@ -89,7 +89,10 @@ [ papply' (f v) s out | (v,s,out) <- res ] Left err -> Left err )++#if !MIN_VERSION_base(4,13,0) fail = Fail.fail+#endif instance Fail.MonadFail (Parser s t e) where -- fail :: String -> Parser s t e a
src/Text/ParserCombinators/Poly/Base.hs view
@@ -1,34 +1,35 @@ module Text.ParserCombinators.Poly.Base ( -- * The PolyParse classes- Commitment(..) -- class of all two-level-error values- , PolyParse -- class of all monadic two-level-error parsers+ Commitment(..) -- class of all two-level-error values+ , PolyParse -- class of all monadic two-level-error parsers -- * Combinators general to all parser types. -- ** Simple combinators- , apply -- :: PolyParse p => p (a->b) -> p a -> p b- , discard -- :: PolyParse p => p a -> p b -> p a+ , apply -- :: PolyParse p => p (a->b) -> p a -> p b+ , discard -- :: PolyParse p => p a -> p b -> p a -- ** Error-handling- , failBad -- :: PolyParse p => String -> p a+ , failBad -- :: PolyParse p => String -> p a , adjustErrBad-- :: PolyParse p => p a -> (String->String) -> p a- , indent -- :: Int -> String -> String+ , indent -- :: Int -> String -> String -- ** Choices- , oneOf -- :: PolyParse p => [p a] -> p a+ , oneOf -- :: PolyParse p => [p a] -> p a -- ** Sequences- , exactly -- :: PolyParse p => Int -> p a -> p [a]- , upto -- :: PolyParse p => Int -> p a -> p [a]- , many1 -- :: PolyParse p => p a -> p [a]- , sepBy -- :: PolyParse p => p a -> p sep -> p [a]- , sepBy1 -- :: PolyParse p => p a -> p sep -> p [a]- , bracketSep -- :: PolyParse p => p bra -> p sep -> p ket -> p a -> p [a]- , bracket -- :: PolyParse p => p bra -> p ket -> p a -> p a+ , exactly -- :: PolyParse p => Int -> p a -> p [a]+ , upto -- :: PolyParse p => Int -> p a -> p [a]+ , many1 -- :: PolyParse p => p a -> p [a]+ , sepBy -- :: PolyParse p => p a -> p sep -> p [a]+ , sepBy1 -- :: PolyParse p => p a -> p sep -> p [a]+ , bracketSep -- :: PolyParse p => p bra -> p sep -> p ket -> p a -> p [a]+ , bracket -- :: PolyParse p => p bra -> p ket -> p a -> p a , manyFinally -- :: PolyParse p => p a -> p z -> p [a] , manyFinally'-- :: PolyParse p => p a -> p z -> p [a] ) where import Control.Applicative+import qualified Control.Monad.Fail as Fail #ifdef __NHC__-default (Integer,Double,[]) -- hack to avoid bizarre type defaulting error+default (Integer,Double,[]) -- hack to avoid bizarre type defaulting error instance Commitment [] instance PolyParse [] #endif@@ -62,7 +63,7 @@ -- There are two additional basic combinators that we expect to be implemented -- afresh for every concrete type, but which (for technical reasons) -- cannot be class methods. They are @next@ and @satisfy@.-class (Functor p, Monad p, Applicative p, Alternative p, Commitment p) =>+class (Functor p, Monad p, Fail.MonadFail p, Applicative p, Alternative p, Commitment p) => PolyParse p infixl 3 `apply`@@ -99,7 +100,7 @@ -- An emphasised (severe) error cannot be overridden by choice -- operators. failBad :: PolyParse p => String -> p a-failBad e = commit (fail e)+failBad e = commit (Fail.fail e) -- | @adjustErrBad@ is just like @adjustErr@ except it also raises the -- severity of the error.@@ -108,7 +109,7 @@ -- | Parse the first alternative in the list that succeeds. oneOf :: PolyParse p => [p a] -> p a-oneOf [] = fail ("failed to parse any of the possible choices")+oneOf [] = Fail.fail ("failed to parse any of the possible choices") oneOf (p:ps) = p <|> oneOf ps --oneOf :: Show t => [Parser t a] -> Parser t a --oneOf [] = do { n <- next@@ -164,7 +165,7 @@ ; return (x:) `apply` many (do {sep; p}) } `adjustErr` ("When looking for a non-empty sequence with separators:\n\t"++)- + -- | Parse a list of items, discarding the start, end, and separator -- items. bracketSep :: PolyParse p => p bra -> p sep -> p ket -> p a -> p [a]
src/Text/ParserCombinators/Poly/ByteString.hs view
@@ -40,13 +40,16 @@ instance Monad Parser where return = pure- fail = Fail.fail (P f) >>= g = P (continue . f) where continue (Success ts x) = let (P g') = g x in g' ts continue (Committed r) = Committed (continue r) continue (Failure ts e) = Failure ts e +#if !MIN_VERSION_base(4,13,0)+ fail = Fail.fail+#endif+ instance Fail.MonadFail Parser where fail e = P (\ts-> Failure ts e) @@ -116,7 +119,7 @@ onFail :: Parser a -> Parser a -> Parser a (P p) `onFail` (P q) = P (\ts-> continue ts $ p ts) where continue ts (Failure _ _) = q ts- -- continue _ (Committed r) = r -- no, remain Committed+ -- continue _ (Committed r) = r -- no, remain Committed continue _ r = r ------------------------------------------------------------------------
src/Text/ParserCombinators/Poly/ByteStringChar.hs view
@@ -39,13 +39,16 @@ instance Monad Parser where return = pure- fail = Fail.fail (P f) >>= g = P (continue . f) where continue (Success ts x) = let (P g') = g x in g' ts continue (Committed r) = Committed (continue r) continue (Failure ts e) = Failure ts e +#if !MIN_VERSION_base(4,13,0)+ fail = Fail.fail+#endif+ instance Fail.MonadFail Parser where fail e = P (\ts-> Failure ts e) @@ -115,7 +118,7 @@ onFail :: Parser a -> Parser a -> Parser a (P p) `onFail` (P q) = P (\ts-> continue ts $ p ts) where continue ts (Failure _ _) = q ts- -- continue _ (Committed r) = r -- no, remain Committed+ -- continue _ (Committed r) = r -- no, remain Committed continue _ r = r ------------------------------------------------------------------------
src/Text/ParserCombinators/Poly/Lazy.hs view
@@ -1,18 +1,18 @@ {-# LANGUAGE CPP, GeneralizedNewtypeDeriving #-} module Text.ParserCombinators.Poly.Lazy ( -- * The Parser datatype- Parser(P) -- datatype, instance of: Functor, Monad, PolyParse- , Result(..) -- internal to the parser monad- , runParser -- :: Parser t a -> [t] -> (Either String a, [t])+ Parser(P) -- datatype, instance of: Functor, Monad, PolyParse+ , Result(..) -- internal to the parser monad+ , runParser -- :: Parser t a -> [t] -> (Either String a, [t]) -- ** Basic parsers- , next -- :: Parser t t- , eof -- :: Parser t ()- , satisfy -- :: (t->Bool) -> Parser t t- , satisfyMsg -- :: (t->Bool) -> String -> Parser t t+ , next -- :: Parser t t+ , eof -- :: Parser t ()+ , satisfy -- :: (t->Bool) -> Parser t t+ , satisfyMsg -- :: (t->Bool) -> String -> Parser t t , onFail -- :: Parser t a -> Parser t a -> Parser t a -- ** Re-parsing- , reparse -- :: [t] -> Parser t ()+ , reparse -- :: [t] -> Parser t () -- * Re-export all more general combinators , module Text.ParserCombinators.Poly.Base , module Control.Applicative@@ -45,7 +45,9 @@ fmap f (P p) = P (fmap f p) instance Monad (Parser t) where return x = P (return x)+#ifndef __MHS__ fail = Fail.fail+#endif (P f) >>= g = P (f >>= (\(P g')->g') . g) instance Fail.MonadFail (Parser t) where fail e = P (fail e)
src/Text/ParserCombinators/Poly/Lex.hs view
@@ -35,7 +35,7 @@ -- | In a strict language, where creating the entire input list of tokens -- in one shot may be infeasible, we can use a lazy "callback" kind of -- architecture instead. The lexer returns a single token at a time,--- together with a continuation. The @next@ parser is responsible for +-- together with a continuation. The @next@ parser is responsible for -- pulling on the token stream, applying the continuation where necessary. data LexReturn t = LexReturn t String (String->LexReturn t) | LexFinish@@ -56,13 +56,16 @@ instance Monad (Parser t) where return = pure- fail = Fail.fail (P f) >>= g = P (continue . f) where continue (Success ts x) = let (P g') = g x in g' ts continue (Committed r) = Committed (continue r) continue (Failure ts e) = Failure ts e +#if !MIN_VERSION_base(4,13,0)+ fail = Fail.fail+#endif+ instance Fail.MonadFail (Parser t) where fail e = P (\ts-> Failure ts e) @@ -90,7 +93,7 @@ r@(Committed _) -> r ) showErr (name,err) = name ++ "\n" ++ indent 2 err -infixl 6 `onFail` -- not sure about precedence 6?+infixl 6 `onFail` -- not sure about precedence 6? -- | @p `onFail` q@ means parse p, unless p fails, in which case -- parse q instead.
src/Text/ParserCombinators/Poly/Parser.hs view
@@ -4,17 +4,17 @@ -- via T.P.Poly.Plain or T.P.Poly.Lazy. module Text.ParserCombinators.Poly.Parser ( -- * The Parser datatype- Parser(P) -- datatype, instance of: Functor, Monad, PolyParse- , Result(..) -- internal to the Parser Monad.+ Parser(P) -- datatype, instance of: Functor, Monad, PolyParse+ , Result(..) -- internal to the Parser Monad. -- ** Basic parsers- , next -- :: Parser t t- , eof -- :: Parser t ()- , satisfy -- :: (t->Bool) -> Parser t t- , satisfyMsg -- :: Show t => (t->Bool) -> String -> Parser t t+ , next -- :: Parser t t+ , eof -- :: Parser t ()+ , satisfy -- :: (t->Bool) -> Parser t t+ , satisfyMsg -- :: Show t => (t->Bool) -> String -> Parser t t , onFail -- :: Parser t a -> Parser t a -> Parser t a -- ** Re-parsing- , reparse -- :: [t] -> Parser t ()+ , reparse -- :: [t] -> Parser t () ) where import Text.ParserCombinators.Poly.Base@@ -40,13 +40,16 @@ instance Monad (Parser t) where return = pure- fail = Fail.fail (P f) >>= g = P (continue . f) where continue (Success ts x) = let (P g') = g x in g' ts continue (Committed r) = Committed (continue r) continue (Failure ts e) = Failure ts e +#if !MIN_VERSION_base(4,13,0)+ fail = Fail.fail+#endif+ instance Fail.MonadFail (Parser t) where fail e = P (\ts-> Failure ts e) @@ -80,7 +83,7 @@ r@(Committed _) -> r ) showErr (name,err) = name++":\n"++indent 2 err -infixl 6 `onFail` -- not sure about precedence 6?+infixl 6 `onFail` -- not sure about precedence 6? -- | @p `onFail` q@ means parse p, unless p fails, in which case -- parse q instead.
src/Text/ParserCombinators/Poly/Plain.hs view
@@ -1,17 +1,17 @@ module Text.ParserCombinators.Poly.Plain ( -- * The Parser datatype- Parser(P) -- datatype, instance of: Functor, Monad, PolyParse- , Result(..) -- internal to the Parser Monad.- , runParser -- :: Parser t a -> [t] -> (Either String a, [t])+ Parser(P) -- datatype, instance of: Functor, Monad, PolyParse+ , Result(..) -- internal to the Parser Monad.+ , runParser -- :: Parser t a -> [t] -> (Either String a, [t]) -- ** Basic parsers- , next -- :: Parser t t- , eof -- :: Parser t ()- , satisfy -- :: (t->Bool) -> Parser t t- , satisfyMsg -- :: (t->Bool) -> String -> Parser t t- , onFail -- :: Parser t a -> Parser t a -> Parser t a+ , next -- :: Parser t t+ , eof -- :: Parser t ()+ , satisfy -- :: (t->Bool) -> Parser t t+ , satisfyMsg -- :: (t->Bool) -> String -> Parser t t+ , onFail -- :: Parser t a -> Parser t a -> Parser t a -- ** Re-parsing- , reparse -- :: [t] -> Parser t ()+ , reparse -- :: [t] -> Parser t () -- * Re-export all more general combinators , module Text.ParserCombinators.Poly.Base , module Control.Applicative
src/Text/ParserCombinators/Poly/Result.hs view
@@ -1,6 +1,6 @@ module Text.ParserCombinators.Poly.Result ( -- * The parsing result type- Result(..) -- A parsing result type, with Success, Failure, and Commitment.+ Result(..) -- A parsing result type, with Success, Failure, and Commitment. , resultToEither ) where
src/Text/ParserCombinators/Poly/State.hs view
@@ -1,19 +1,19 @@ module Text.ParserCombinators.Poly.State ( -- * The Parser datatype- Parser(P) -- datatype, instance of: Functor, Monad, PolyParse- , Result(..) -- internal to the parser monad- , runParser -- :: Parser s t a -> s -> [t] -> (Either String a, s, [t])+ Parser(P) -- datatype, instance of: Functor, Monad, PolyParse+ , Result(..) -- internal to the parser monad+ , runParser -- :: Parser s t a -> s -> [t] -> (Either String a, s, [t]) -- ** Basic parsers- , next -- :: Parser s t t- , eof -- :: Parser s t ()- , satisfy -- :: (t->Bool) -> Parser s t t- , onFail -- :: Parser s t a -> Parser s t a -> Parser s t a+ , next -- :: Parser s t t+ , eof -- :: Parser s t ()+ , satisfy -- :: (t->Bool) -> Parser s t t+ , onFail -- :: Parser s t a -> Parser s t a -> Parser s t a -- ** State-handling , stUpdate -- :: (s->s) -> Parser s t () , stQuery -- :: (s->a) -> Parser s t a , stGet -- :: Parser s t s -- ** Re-parsing- , reparse -- :: [t] -> Parser s t ()+ , reparse -- :: [t] -> Parser s t () -- * Re-export all more general combinators , module Text.ParserCombinators.Poly.Base , module Control.Applicative
src/Text/ParserCombinators/Poly/StateLazy.hs view
@@ -1,21 +1,21 @@ {-# LANGUAGE CPP, GeneralizedNewtypeDeriving #-} module Text.ParserCombinators.Poly.StateLazy ( -- * The Parser datatype- Parser(P) -- datatype, instance of: Functor, Monad, PolyParse- , Result(..) -- internal to the parser monad- , runParser -- :: Parser s t a -> s -> [t] -> (Either String a, s, [t])+ Parser(P) -- datatype, instance of: Functor, Monad, PolyParse+ , Result(..) -- internal to the parser monad+ , runParser -- :: Parser s t a -> s -> [t] -> (Either String a, s, [t]) -- ** Basic parsers- , next -- :: Parser s t t- , eof -- :: Parser s t ()- , satisfy -- :: (t->Bool) -> Parser s t t+ , next -- :: Parser s t t+ , eof -- :: Parser s t ()+ , satisfy -- :: (t->Bool) -> Parser s t t , onFail -- :: Parser s t a -> Parser s t a -> Parser s t a- , manyFinally -- :: Parser s t a -> Parser s t z -> Parser s t [a]+ , manyFinally -- :: Parser s t a -> Parser s t z -> Parser s t [a] -- ** State-handling , stUpdate -- :: (s->s) -> Parser s t () , stQuery -- :: (s->a) -> Parser s t a , stGet -- :: Parser s t s -- ** Re-parsing- , reparse -- :: [t] -> Parser s t ()+ , reparse -- :: [t] -> Parser s t () -- * Re-export all more general combinators , module Text.ParserCombinators.Poly.Base , module Control.Applicative@@ -49,7 +49,9 @@ fmap f (P p) = P (fmap f p) instance Monad (Parser s t) where return x = P (return x)+#ifndef __MHS__ fail = Fail.fail+#endif (P f) >>= g = P (f >>= (\(P g')->g') . g) instance Fail.MonadFail (Parser s t) where fail e = P (fail e)
src/Text/ParserCombinators/Poly/StateParser.hs view
@@ -4,19 +4,19 @@ -- via T.P.Poly.State or T.P.Poly.StateLazy. module Text.ParserCombinators.Poly.StateParser ( -- * The Parser datatype- Parser(P) -- datatype, instance of: Functor, Monad, PolyParse- , Result(..) -- internal to the parser monad+ Parser(P) -- datatype, instance of: Functor, Monad, PolyParse+ , Result(..) -- internal to the parser monad -- ** basic parsers- , next -- :: Parser s t t- , eof -- :: Parser s t ()- , satisfy -- :: (t->Bool) -> Parser s t t+ , next -- :: Parser s t t+ , eof -- :: Parser s t ()+ , satisfy -- :: (t->Bool) -> Parser s t t , onFail -- :: Parser s t a -> Parser s t a -> Parser s t a -- ** State-handling , stUpdate -- :: (s->s) -> Parser s t () , stQuery -- :: (s->a) -> Parser s t a , stGet -- :: Parser s t s -- ** re-parsing- , reparse -- :: [t] -> Parser s t ()+ , reparse -- :: [t] -> Parser s t () ) where @@ -43,13 +43,16 @@ instance Monad (Parser s t) where return = pure- fail = Fail.fail (P f) >>= g = P (\s-> continue . f s) where continue (Success (ts,s) x) = let (P g') = g x in g' s ts continue (Committed r) = Committed (continue r) continue (Failure tss e) = Failure tss e +#if !MIN_VERSION_base(4,13,0)+ fail = Fail.fail+#endif+ instance Fail.MonadFail (Parser s t) where fail e = P (\s ts-> Failure (ts,s) e) @@ -83,7 +86,7 @@ r@(Committed _) -> r ) showErr (name,err) = name++":\n"++indent 2 err -infixl 6 `onFail` -- not sure about precedence 6?+infixl 6 `onFail` -- not sure about precedence 6? -- | @p `onFail` q@ means parse p, unless p fails, in which case -- parse q instead.@@ -95,7 +98,7 @@ (P p) `onFail` (P q) = P (\s ts-> continue s ts $ p s ts) where continue s ts (Failure _ _) = q s ts- -- continue _ _ (Committed r) = r -- no, remain Committed+ -- continue _ _ (Committed r) = r -- no, remain Committed continue _ _ r = r ------------------------------------------------------------------------
src/Text/ParserCombinators/Poly/StateText.hs view
@@ -46,13 +46,16 @@ instance Monad (Parser s) where return = pure- fail = Fail.fail (P f) >>= g = P (\s-> continue . f s) where continue (Success (ts,s) x) = let (P g') = g x in g' s ts continue (Committed r) = Committed (continue r) continue (Failure ts e) = Failure ts e +#if !MIN_VERSION_base(4,13,0)+ fail = Fail.fail+#endif+ instance Fail.MonadFail (Parser s) where fail e = P (\s ts-> Failure (ts,s) e) @@ -122,7 +125,7 @@ onFail :: Parser s a -> Parser s a -> Parser s a (P p) `onFail` (P q) = P (\s ts-> continue s ts $ p s ts) where continue s ts (Failure _ _) = q s ts- -- continue _ _ (Committed r) = r -- no, remain Committed+ -- continue _ _ (Committed r) = r -- no, remain Committed continue _ _ r = r ------------------------------------------------------------------------
src/Text/ParserCombinators/Poly/Text.hs view
@@ -40,13 +40,16 @@ instance Monad Parser where return = pure- fail = Fail.fail (P f) >>= g = P (continue . f) where continue (Success ts x) = let (P g') = g x in g' ts continue (Committed r) = Committed (continue r) continue (Failure ts e) = Failure ts e +#if !MIN_VERSION_base(4,13,0)+ fail = Fail.fail+#endif+ instance Fail.MonadFail Parser where fail e = P (\ts-> Failure ts e) @@ -116,7 +119,7 @@ onFail :: Parser a -> Parser a -> Parser a (P p) `onFail` (P q) = P (\ts-> continue ts $ p ts) where continue ts (Failure _ _) = q ts- -- continue _ (Committed r) = r -- no, remain Committed+ -- continue _ (Committed r) = r -- no, remain Committed continue _ r = r ------------------------------------------------------------------------