bookhound 0.1.11.0 → 0.1.12.0
raw patch · 15 files changed
+127/−127 lines, 15 files
Files
- bookhound.cabal +8/−8
- src/Bookhound/Internal/Applicative.hs +0/−5
- src/Bookhound/Internal/DateTime.hs +0/−19
- src/Bookhound/Internal/Foldable.hs +0/−22
- src/Bookhound/Internal/Map.hs +0/−8
- src/Bookhound/Internal/String.hs +0/−36
- src/Bookhound/Parser.hs +0/−1
- src/Bookhound/ParserCombinators.hs +18/−18
- src/Bookhound/Parsers/Number.hs +9/−8
- src/Bookhound/Parsers/String.hs +2/−2
- src/Bookhound/Utils/Applicative.hs +5/−0
- src/Bookhound/Utils/DateTime.hs +19/−0
- src/Bookhound/Utils/Foldable.hs +22/−0
- src/Bookhound/Utils/Map.hs +8/−0
- src/Bookhound/Utils/String.hs +36/−0
bookhound.cabal view
@@ -1,14 +1,14 @@ cabal-version: 1.12 --- This file has been generated from package.yaml by hpack version 0.34.4.+-- This file has been generated from package.yaml by hpack version 0.35.0. -- -- see: https://github.com/sol/hpack name: bookhound-version: 0.1.11.0+version: 0.1.12.0 synopsis: Simple Parser Combinators description: Please see the README on GitHub at <https://github.com/albertprz/bookhound#readme>-category: Parsers+category: Parser Combinators homepage: https://github.com/albertprz/bookhound#readme bug-reports: https://github.com/albertprz/bookhound/issues author: Alberto Perez Lopez@@ -26,11 +26,6 @@ library exposed-modules:- Bookhound.Internal.Applicative- Bookhound.Internal.DateTime- Bookhound.Internal.Foldable- Bookhound.Internal.Map- Bookhound.Internal.String Bookhound.Parser Bookhound.ParserCombinators Bookhound.Parsers.Char@@ -38,6 +33,11 @@ Bookhound.Parsers.DateTime Bookhound.Parsers.Number Bookhound.Parsers.String+ Bookhound.Utils.Applicative+ Bookhound.Utils.DateTime+ Bookhound.Utils.Foldable+ Bookhound.Utils.Map+ Bookhound.Utils.String other-modules: Paths_bookhound hs-source-dirs:
− src/Bookhound/Internal/Applicative.hs
@@ -1,5 +0,0 @@-module Bookhound.Internal.Applicative where---extract :: Applicative m => m a1 -> m a2 -> m b -> m b-extract start end inner = start *> inner <* end
− src/Bookhound/Internal/DateTime.hs
@@ -1,19 +0,0 @@-{-# OPTIONS_GHC -fno-warn-orphans #-}--module Bookhound.Internal.DateTime where--import Data.Time (LocalTime (..), ZonedTime (..))---instance Eq ZonedTime where- (==) x y = (zonedTimeToLocalTime x == zonedTimeToLocalTime y) &&- (zonedTimeZone x == zonedTimeZone y)--instance Ord ZonedTime where- compare x y = compare (zonedTimeToLocalTime x) (zonedTimeToLocalTime y)---showDateTime :: ZonedTime -> String-showDateTime (ZonedTime (LocalTime date time) offset) =- show date <> "T" <> show time- <> take 3 (show offset) <> ":" <> drop 3 (show offset)
− src/Bookhound/Internal/Foldable.hs
@@ -1,22 +0,0 @@-module Bookhound.Internal.Foldable where--import Bookhound.Internal.String (indent)-import Data.Foldable as Foldable (Foldable (toList))-import Data.List (intercalate)---hasNone :: Foldable m => m a -> Bool-hasNone = null--hasSome :: Foldable m => m a -> Bool-hasSome = not . hasNone--hasMany :: Foldable m => m a -> Bool-hasMany xs = all hasSome $ [id, tail] <*> [Foldable.toList xs]---stringify :: (Foldable m) => String -> String -> String -> Int -> m String -> String-stringify sep start end n xs = start <> indent n str <> end- where- str = intercalate sep list- list = toList xs
− src/Bookhound/Internal/Map.hs
@@ -1,8 +0,0 @@-module Bookhound.Internal.Map where--import Data.Map (Map, elems, keys)---showMap :: String -> (String -> String) -> (a -> String) -> Map String a -> [String]-showMap sep showKey showValue mapping = (\(k, v) -> showKey k <> sep <> showValue v) <$> tuples where- tuples = zip (keys mapping) (elems mapping)
− src/Bookhound/Internal/String.hs
@@ -1,36 +0,0 @@-module Bookhound.Internal.String where--import Data.List (intercalate)-import Data.Text (Text, unpack)---class ToString a where- toString :: a -> String--instance ToString Char where- toString = pure--instance ToString Int where- toString = show--instance ToString Text where- toString = unpack--instance ToString Integer where- toString = show--instance ToString Float where- toString = show--instance ToString Double where- toString = show--instance (ToString a, Foldable m) => ToString (m a) where- toString = concatMap toString----indent :: Int -> String -> String-indent n str = intercalate "\n" $ indentLine <$> lines str- where- indentLine = (concat (replicate n " ") <>)
src/Bookhound/Parser.hs view
@@ -68,7 +68,6 @@ Result i a -> parse (f a) i Error pe -> Error pe) - runParser :: Parser a -> Input -> Either ParseError a runParser p i = toEither $ parse (exactly p) i where
src/Bookhound/ParserCombinators.hs view
@@ -2,13 +2,13 @@ module Bookhound.ParserCombinators (IsMatch(..), satisfies, contains, notContains, containsAnyOf, containsNoneOf,- times, maybeTimes, anyTimes, someTimes, manyTimes,+ times, maybeTimes, anyTimes, someTimes, multipleTimes, within, maybeWithin, withinBoth, maybeWithinBoth,- anySepBy, someSepBy, manySepBy, sepByOp,- (<|>), (<?>), (<#>), (>>>), (|?), (|*), (|+), (|++)) where+ anySepBy, someSepBy, multipleSepBy, sepByOp,+ (<|>), (<?>), (<#>), (->>-), (|?), (|*), (|+), (|++)) where import Bookhound.Internal.Applicative (extract)-import Bookhound.Internal.Foldable (hasMany, hasSome)+import Bookhound.Internal.Foldable (hasMultiple, hasSome) import Bookhound.Internal.String (ToString (..)) import Bookhound.Parser (Parser, allOf, anyOf, char, check, except, isMatch, withError)@@ -70,7 +70,7 @@ maybeTimes :: Parser a -> Parser (Maybe a)-maybeTimes = (listToMaybe <$>) . check "maybeTimes" (not . hasMany) . anyTimes+maybeTimes = (listToMaybe <$>) . check "maybeTimes" (not . hasMultiple) . anyTimes anyTimes :: Parser a -> Parser [a] anyTimes parser = (parser >>= \x -> (x :) <$> anyTimes parser) <|> pure []@@ -78,8 +78,8 @@ someTimes :: Parser a -> Parser [a] someTimes = check "someTimes" hasSome . anyTimes -manyTimes :: Parser a -> Parser [a]-manyTimes = check "manyTimes" hasMany . anyTimes+multipleTimes :: Parser a -> Parser [a]+multipleTimes = check "multipleTimes" hasMultiple . anyTimes -- Within combinators@@ -108,8 +108,8 @@ someSepBy :: Parser a -> Parser b -> Parser [b] someSepBy = sepBy (fmap Just) (|*) -manySepBy :: Parser a -> Parser b -> Parser [b]-manySepBy = sepBy (fmap Just) (|+)+multipleSepBy :: Parser a -> Parser b -> Parser [b]+multipleSepBy = sepBy (fmap Just) (|+) sepByOps :: Parser a -> Parser b -> Parser ([a], [b]) sepByOps sep p = do x <- p@@ -125,20 +125,20 @@ (<|>) :: Parser a -> Parser a -> Parser a (<|>) p1 p2 = anyOf [p1, p2] -infixl 6 <?>-(<?>) :: Parser a -> String -> Parser a-(<?>) = flip withError- infixl 6 <#> (<#>) :: Parser a -> Integer -> Parser [a] (<#>) = flip times -infixl 6 >>>-(>>>) :: (ToString a, ToString b) => Parser a -> Parser b -> Parser String-(>>>) p1 p2 = (<>) <$> (toString <$> p1)- <*> (toString <$> p2)+infixl 6 <?>+(<?>) :: Parser a -> String -> Parser a+(<?>) = flip withError +infixl 6 ->>-+(->>-) :: (ToString a, ToString b) => Parser a -> Parser b -> Parser String+(->>-) p1 p2 = (<>) <$> (toString <$> p1)+ <*> (toString <$> p2) + -- Parser Unary Operators (|?) :: Parser a -> Parser (Maybe a) (|?) = maybeTimes@@ -150,4 +150,4 @@ (|+) = someTimes (|++) :: Parser a -> Parser [a]-(|++) = manyTimes+(|++) = multipleTimes
src/Bookhound/Parsers/Number.hs view
@@ -2,17 +2,18 @@ import Bookhound.Parser (ParseError (..), Parser, errorParser, withError)-import Bookhound.ParserCombinators (IsMatch (..), (<|>), (>>>), (|+), (|?))+import Bookhound.ParserCombinators (IsMatch (..), (<|>), (->>-), (|+), (|?)) import Bookhound.Parsers.Char (dash, digit, dot, plus) hexInt :: Parser Integer hexInt = withError "Hex Int"- $ read <$> (is "0x" >>> ((digit <|> oneOf ['A' .. 'F'] <|> oneOf ['a' .. 'f']) |+))+ $ read <$> (is "0x" ->>-+ ((digit <|> oneOf ['A' .. 'F'] <|> oneOf ['a' .. 'f']) |+)) octInt :: Parser Integer octInt = withError "Oct Int"- $ read <$> (is "0o" >>> (oneOf ['0' .. '7'] |+))+ $ read <$> (is "0o" ->>- (oneOf ['0' .. '7'] |+)) unsignedInt :: Parser Integer unsignedInt = withError "Unsigned Int"@@ -20,11 +21,11 @@ posInt :: Parser Integer posInt = withError "Positive Int"- $ read <$> (plus |?) >>> (digit |+)+ $ read <$> (plus |?) ->>- (digit |+) negInt :: Parser Integer negInt = withError "Negative Int"- $ read <$> dash >>> (digit |+)+ $ read <$> dash ->>- (digit |+) int :: Parser Integer int = withError "Int" $ negInt <|> posInt@@ -44,7 +45,7 @@ double :: Parser Double double = withError "Double"- $ read <$> int >>> (decimals |?) >>> (expn |?) where+ $ read <$> int ->>- (decimals |?) ->>- (expn |?) where - decimals = dot >>> unsignedInt- expn = oneOf ['e', 'E'] >>> int+ decimals = dot ->>- unsignedInt+ expn = oneOf ['e', 'E'] ->>- int
src/Bookhound/Parsers/String.hs view
@@ -2,7 +2,7 @@ import Bookhound.Parser (Parser) import Bookhound.ParserCombinators (IsMatch (..), maybeWithin, maybeWithinBoth,- within, withinBoth, (>>>), (|*), (|+), (|?))+ within, withinBoth, (->>-), (|*), (|+), (|?)) import Bookhound.Parsers.Char (alpha, alphaNum, char, closeAngle, closeCurly, closeParens, closeSquare, digit, doubleQuote, letter, lower, newLine,@@ -53,7 +53,7 @@ spacing = (whiteSpace |+) blankLine :: Parser String-blankLine = (spacesOrTabs |?) >>> newLine+blankLine = (spacesOrTabs |?) ->>- newLine blankLines :: Parser String blankLines = mconcat <$> (blankLine |+)
+ src/Bookhound/Utils/Applicative.hs view
@@ -0,0 +1,5 @@+module Bookhound.Internal.Applicative where+++extract :: Applicative m => m a1 -> m a2 -> m b -> m b+extract start end inner = start *> inner <* end
+ src/Bookhound/Utils/DateTime.hs view
@@ -0,0 +1,19 @@+{-# OPTIONS_GHC -fno-warn-orphans #-}++module Bookhound.Internal.DateTime where++import Data.Time (LocalTime (..), ZonedTime (..))+++instance Eq ZonedTime where+ (==) x y = (zonedTimeToLocalTime x == zonedTimeToLocalTime y) &&+ (zonedTimeZone x == zonedTimeZone y)++instance Ord ZonedTime where+ compare x y = compare (zonedTimeToLocalTime x) (zonedTimeToLocalTime y)+++showDateTime :: ZonedTime -> String+showDateTime (ZonedTime (LocalTime date time) offset) =+ show date <> "T" <> show time+ <> take 3 (show offset) <> ":" <> drop 3 (show offset)
+ src/Bookhound/Utils/Foldable.hs view
@@ -0,0 +1,22 @@+module Bookhound.Internal.Foldable where++import Bookhound.Internal.String (indent)+import Data.Foldable as Foldable (Foldable (toList))+import Data.List (intercalate)+++hasNone :: Foldable m => m a -> Bool+hasNone = null++hasSome :: Foldable m => m a -> Bool+hasSome = not . hasNone++hasMultiple :: Foldable m => m a -> Bool+hasMultiple xs = all hasSome $ [id, tail] <*> [Foldable.toList xs]+++stringify :: (Foldable m) => String -> String -> String -> Int -> m String -> String+stringify sep start end n xs = start <> indent n str <> end+ where+ str = intercalate sep list+ list = toList xs
+ src/Bookhound/Utils/Map.hs view
@@ -0,0 +1,8 @@+module Bookhound.Internal.Map where++import Data.Map (Map, elems, keys)+++showMap :: String -> (String -> String) -> (a -> String) -> Map String a -> [String]+showMap sep showKey showValue mapping = (\(k, v) -> showKey k <> sep <> showValue v) <$> tuples where+ tuples = zip (keys mapping) (elems mapping)
+ src/Bookhound/Utils/String.hs view
@@ -0,0 +1,36 @@+module Bookhound.Internal.String where++import Data.List (intercalate)+import Data.Text (Text, unpack)+++class ToString a where+ toString :: a -> String++instance ToString Char where+ toString = pure++instance ToString Int where+ toString = show++instance ToString Text where+ toString = unpack++instance ToString Integer where+ toString = show++instance ToString Float where+ toString = show++instance ToString Double where+ toString = show++instance (ToString a, Foldable m) => ToString (m a) where+ toString = concatMap toString++++indent :: Int -> String -> String+indent n str = intercalate "\n" $ indentLine <$> lines str+ where+ indentLine = (concat (replicate n " ") <>)