bookhound 0.1.26.0 → 0.2.2
raw patch · 6 files changed
Files
- bookhound.cabal +1/−1
- src/Bookhound/Parser.hs +7/−5
- src/Bookhound/ParserCombinators.hs +2/−7
- src/Bookhound/Parsers/Text.hs +2/−2
- src/Bookhound/Utils/Text.hs +1/−1
- test/Bookhound/Parsers/CollectionsSpec.hs +2/−2
bookhound.cabal view
@@ -5,7 +5,7 @@ -- see: https://github.com/sol/hpack name: bookhound-version: 0.1.26.0+version: 0.2.2 synopsis: Simple Parser Combinators description: Please see the README on GitHub at <https://github.com/albertprz/bookhound#readme> category: Parser Combinators
src/Bookhound/Parser.hs view
@@ -5,6 +5,7 @@ import Control.Monad (MonadPlus) import Control.Monad.Error.Class (MonadError (..)) import Data.Either (fromRight)+import Data.Foldable (foldl') import Data.Set (Set) import qualified Data.Set as Set import Data.Text (Text, unpack)@@ -43,11 +44,12 @@ mempty = pure mempty instance Alternative Parser where- (<|>) (P p t e) (P p' t' e') =- applyTransformsErrors [ t, t' ] [ e, e' ] $+ (<|>) (P p t e) p2 =+ applyTransformError t e $ mkParser \x -> case p x of- Error _ -> p' x+ Error _ -> let (P _ t' e') = p2 in+ parse (applyTransformsErrors [t, t'] [e, e'] p2) x result -> result empty = mkParser \i -> if Text.null i then@@ -111,10 +113,10 @@ choice = anyOf anyOf :: Foldable f => f (Parser a) -> Parser a-anyOf = foldl (<|>) empty+anyOf = foldl' (<|>) empty allOf :: Foldable f => f (Parser a) -> Parser a-allOf = foldl both (pure undefined)+allOf = foldl' both (pure undefined) both :: Parser a -> Parser a -> Parser a both (P p t e) (P p' t' e') =
src/Bookhound/ParserCombinators.hs view
@@ -29,14 +29,9 @@ isNot = isMatch (/=) anyChar inverse = except anyChar -instance IsMatch String where- is = traverse is- isNot = traverse is- inverse = except (anyChar |*)- instance IsMatch Text where- is = fmap pack . is . unpack- isNot = fmap pack . is . unpack+ is = fmap pack . traverse is . unpack+ isNot = fmap pack . traverse is . unpack inverse = except (anyChar ||*)
src/Bookhound/Parsers/Text.hs view
@@ -16,8 +16,8 @@ import qualified Data.Text as Text -string :: Parser Text-string = (anyChar ||*)+anyString :: Parser Text+anyString = (anyChar ||*) word :: Parser Text word = (inverse whiteSpace ||+)
src/Bookhound/Utils/Text.hs view
@@ -27,7 +27,7 @@ instance ToText Double where toText = pack . show -instance ToText a => ToText [a] where+instance {-# OVERLAPPING #-} ToText a => ToText [a] where toText = Text.concat . fmap toText instance (ToText a, Foldable f, Functor f) => ToText (f a) where
test/Bookhound/Parsers/CollectionsSpec.hs view
@@ -11,7 +11,7 @@ import Data.Char (isAlpha, isAscii) import Data.List (intercalate) import qualified Data.Map as Map-import Data.Text ( pack)+import Data.Text (pack, unpack) import Test.QuickCheck ((==>)) import Test.QuickCheck.Property ((===)) @@ -46,7 +46,7 @@ prop "parses a map provided the key and value parsers" $ \(x :: [(Char, Char)]) ->- runParser (mapOf (is (":" :: String)) alpha alpha)+ runParser (mapOf (unpack <$> (is ":")) alpha alpha) (pack ("{" <> intercalate ", " (showMapEntry <$> filter areAlpha' x) <> "}"))