packages feed

bookhound 0.1.8.0 → 0.1.9.0

raw patch · 23 files changed

+210/−162 lines, 23 filesPVP ok

version bump matches the API change (PVP)

API changes (from Hackage documentation)

+ ParserCombinators: containsAnyOf :: (Foldable t, Eq a) => t [a] -> Parser [a] -> Parser [a]
+ ParserCombinators: containsNoneOf :: (Foldable t, Eq a) => t [a] -> Parser [a] -> Parser [a]

Files

bookhound.cabal view
@@ -5,7 +5,7 @@ -- see: https://github.com/sol/hpack  name:           bookhound-version:        0.1.8.0+version:        0.1.9.0 synopsis:       Simple Parser Combinators & Parsers description:    Please see the README on GitHub at <https://github.com/albertprz/bookhound#readme> category:       Parsers
src/Operations/Finder.hs view
@@ -1,19 +1,20 @@ module Operations.Finder (Finder(..)) where  -import Parser (runParser)-import ParserCombinators (IsMatch(..), (|*), (<|>))-import Parsers.String (withinSquareBrackets)-import Parsers.Number (unsignedInt)-import Parsers.Char (dot)-import SyntaxTrees.Json(JsExpression(..))-import SyntaxTrees.Yaml (YamlExpression(..))-import SyntaxTrees.Toml (TomlExpression(..))+import Parser            (runParser)+import ParserCombinators (IsMatch (..), (<|>), (|*))+import Parsers.Char      (dot)+import Parsers.Number    (unsignedInt)+import Parsers.String    (withinSquareBrackets)+import SyntaxTrees.Json  (JsExpression (..))+import SyntaxTrees.Toml  (TomlExpression (..))+import SyntaxTrees.Yaml  (YamlExpression (..))  -import qualified Data.Map as Map-import Data.Maybe (listToMaybe) import Data.Either (fromRight)+import Data.Maybe  (listToMaybe)++import qualified Data.Map as Map   
src/Operations/ToJson.hs view
@@ -1,17 +1,17 @@ module Operations.ToJson (ToJson(..)) where -import SyntaxTrees.Json (JsExpression(..))-import SyntaxTrees.Xml  (XmlExpression(..))-import SyntaxTrees.Yaml (YamlExpression(..))-import SyntaxTrees.Toml  (TomlExpression(..))-import Parsers.Json (json)-import Parsers.String (spacing)-import Parser (runParser)-import ParserCombinators (IsMatch(..), (<|>), (|*), maybeWithin)+import Parser            (runParser)+import ParserCombinators (IsMatch (..), maybeWithin, (<|>), (|*))+import Parsers.Json      (json)+import Parsers.String    (spacing)+import SyntaxTrees.Json  (JsExpression (..))+import SyntaxTrees.Toml  (TomlExpression (..))+import SyntaxTrees.Xml   (XmlExpression (..))+import SyntaxTrees.Yaml  (YamlExpression (..)) -import qualified Data.Map as Map-import Data.Map (Map, elems)-import Data.Either (fromRight)+import           Data.Either (fromRight)+import           Data.Map    (Map, elems)+import qualified Data.Map    as Map   class ToJson a where
src/Operations/ToXml.hs view
@@ -2,12 +2,12 @@  module Operations.ToXml (ToXml(..)) where -import SyntaxTrees.Xml  (XmlExpression(..), literalExpression)-import SyntaxTrees.Json (JsExpression(..))-import Operations.ToJson (ToJson(..))+import Operations.ToJson (ToJson (..))+import SyntaxTrees.Json  (JsExpression (..))+import SyntaxTrees.Xml   (XmlExpression (..), literalExpression) -import qualified Data.Map as Map-import Data.Char (toLower)+import           Data.Char (toLower)+import qualified Data.Map  as Map   class ToXml a where
src/Operations/ToYaml.hs view
@@ -2,11 +2,11 @@  module Operations.ToYaml (ToYaml(..)) where -import SyntaxTrees.Yaml  (YamlExpression(..), CollectionType(..))-import SyntaxTrees.Json (JsExpression(..))-import Operations.ToJson (ToJson(..))-import Parsers.Number (intLike)-import Parser (runParser)+import Operations.ToJson (ToJson (..))+import Parser            (runParser)+import Parsers.Number    (intLike)+import SyntaxTrees.Json  (JsExpression (..))+import SyntaxTrees.Yaml  (CollectionType (..), YamlExpression (..))   class ToYaml a where
src/Parser.hs view
@@ -3,23 +3,30 @@                withTransform) where  import Control.Applicative (liftA2)-import Control.Monad (join)-import Data.Maybe (isJust)-import Data.Either (fromRight)-import Data.List (find)+import Control.Monad       (join)+import Data.Either         (fromRight)+import Data.List           (find)+import Data.Maybe          (isJust)  type Input = String -data Parser a = P { parse :: Input -> ParseResult a-                  , transform :: forall b. Maybe (Parser b -> Parser b)-                  }+data Parser a+  = P+      { parse     :: Input -> ParseResult a+      , transform :: forall b. Maybe (Parser b -> Parser b)+      } -data ParseResult a = Result Input a | Error ParseError-  deriving Eq+data ParseResult a+  = Result Input a+  | Error ParseError+  deriving (Eq) -data ParseError = UnexpectedEof       | ExpectedEof Input       |-                  UnexpectedChar Char | UnexpectedString String |-                  NoMatch String+data ParseError+  = UnexpectedEof+  | ExpectedEof Input+  | UnexpectedChar Char+  | UnexpectedString String+  | NoMatch String   deriving (Eq, Show)  @@ -48,7 +55,7 @@       combinedParser = mkParser (         \x -> case p x of         Result i a -> parse ((f a) <$> mb) i-        Error pe -> Error pe)+        Error pe   -> Error pe)  instance Monad Parser where   (>>=) (P p t) f = applyTransform t combinedParser@@ -56,14 +63,14 @@       combinedParser = mkParser (         \x -> case  p x of         Result i a -> parse (f a) i-        Error pe -> Error pe)+        Error pe   -> Error pe)   runParser :: Parser a -> Input -> Either ParseError a runParser p i = toEither $ parse (exactly p) i where    toEither = \case-    Error pe -> Left pe+    Error pe   -> Left pe     Result _ a -> Right a  errorParser :: ParseError -> Parser a@@ -72,7 +79,7 @@  char :: Parser Char char = mkParser parseIt  where-  parseIt [] = Error UnexpectedEof+  parseIt []          = Error UnexpectedEof   parseIt (ch : rest) = Result rest ch  @@ -98,7 +105,8 @@ anyOfHelper :: [Parser a] -> (forall b. Maybe (Parser b -> Parser b)) -> Parser a anyOfHelper [] _  = errorParser $ NoMatch "anyOf" anyOfHelper [p] _ = p-anyOfHelper ((P p t) : rest) t' = applyTransform (findJust t t') $ mkParser (+anyOfHelper ((P p t) : rest) t' = applyTransform (findJust t t') $+  mkParser (    \x -> case p x of     result@(Result _ _) -> result     Error _             -> parse (anyOfHelper rest t) x)@@ -108,9 +116,10 @@ allOfHelper :: [Parser a] -> (forall b. Maybe (Parser b -> Parser b)) -> Parser a allOfHelper [] _ = errorParser $ NoMatch "allOf" allOfHelper [p] _ = p-allOfHelper ((P p t) : rest) t' = applyTransform (findJust t t') $ mkParser (+allOfHelper ((P p t) : rest) t' = applyTransform (findJust t t') $+  mkParser (    \x -> case p x of-    Result i _    -> parse (allOfHelper rest t) i+    Result _ _    -> parse (allOfHelper rest t) x     err@(Error _) -> err)  @@ -134,7 +143,7 @@ except (P p t) (P p' _) = applyTransform t $ mkParser (   \x -> case p' x of     Result _ a -> Error $ UnexpectedString (show a)-    Error _     -> p x)+    Error _    -> p x)  withTransform :: (forall b. Parser b -> Parser b) -> Parser a -> Parser a withTransform f = applyTransform $ Just f
src/ParserCombinators.hs view
@@ -1,27 +1,29 @@ {-# LANGUAGE UndecidableInstances #-}  module ParserCombinators (IsMatch(..), satisfies, contains, notContains,+                          containsAnyOf, containsNoneOf,                           times, maybeTimes, anyTimes, someTimes, manyTimes,                           within, maybeWithin, withinBoth, maybeWithinBoth,                           anySepBy, someSepBy, manySepBy, sepByOp,                           (<|>), (<&>), (<#>), (>>>), (|?), (|*), (|+), (|++))  where -import Parser (Parser, char, isMatch, check, anyOf, allOf, except)-import Utils.Foldable (hasSome, hasMany)-import Utils.String (ToString(..))+import Parser            (Parser, allOf, anyOf, char, check, except, isMatch) import Utils.Applicative (extract)-import qualified Data.Foldable as Foldable+import Utils.Foldable    (hasMany, hasSome)+import Utils.String      (ToString (..)) +import Data.List  (isInfixOf) import Data.Maybe (listToMaybe)-import Data.List (isInfixOf) +import qualified Data.Foldable as Foldable + class IsMatch a where   is      :: a -> Parser a   isNot   :: a -> Parser a+  inverse :: Parser a -> Parser a   oneOf   :: [a] -> Parser a   noneOf  :: [a] -> Parser a-  inverse :: Parser a -> Parser a    oneOf xs  = anyOf $ is <$> xs   noneOf xs = allOf $ isNot <$> xs@@ -50,8 +52,14 @@ contains :: Eq a => [a] -> Parser [a] -> Parser [a] contains val p = check "contains" (isInfixOf val) p +containsAnyOf :: (Foldable t, Eq a) => t [a] -> Parser [a] -> Parser [a]+containsAnyOf x y = foldr contains y x+ notContains :: Eq a => [a] -> Parser [a] -> Parser [a] notContains val p = check "notContains" (isInfixOf val) p++containsNoneOf :: (Foldable t, Eq a) => t [a] -> Parser [a] -> Parser [a]+containsNoneOf x y = foldr notContains y x    -- Frequency combinators
src/Parsers/Char.hs view
@@ -1,8 +1,9 @@ module Parsers.Char where +import ParserCombinators (IsMatch (..), (<|>))++import           Parser (Parser) import qualified Parser-import Parser (Parser)-import ParserCombinators (IsMatch(..), (<|>))   char :: Parser Char
src/Parsers/Collections.hs view
@@ -1,13 +1,13 @@ module Parsers.Collections (collOf, listOf, tupleOf, mapOf) where -import Parser (Parser)-import ParserCombinators (maybeWithin, anySepBy, satisfies)-import Parsers.Char (comma, openSquare, closeSquare, openParens,-                     closeParens, openCurly, closeCurly)-import Parsers.String(spacing)+import Parser            (Parser)+import ParserCombinators (anySepBy, maybeWithin, satisfies)+import Parsers.Char      (closeCurly, closeParens, closeSquare, comma,+                          openCurly, openParens, openSquare)+import Parsers.String    (spacing) +import           Data.Map (Map) import qualified Data.Map as Map-import Data.Map(Map)   collOf :: Parser a -> Parser b -> Parser c -> Parser d -> Parser [d]
src/Parsers/DateTime.hs view
@@ -1,13 +1,13 @@ module Parsers.DateTime (date, time, timeZoneOffset, localDateTime, offsetDateTime,                          dateTime, year, day, month, hour, minute, second) where -import Parser(Parser, check)-import ParserCombinators (IsMatch(..), (<|>), (<#>), (|?), (|+), within)-import Parsers.Char (digit, dash, colon, plus)+import Parser            (Parser, check)+import ParserCombinators (IsMatch (..), within, (<#>), (<|>), (|+), (|?))+import Parsers.Char      (colon, dash, digit, plus) -import Data.Time (Day, LocalTime(..), TimeOfDay(..), TimeZone, ZonedTime(..),-                  fromGregorian, minutesToTimeZone) import Data.Maybe (fromMaybe)+import Data.Time  (Day, LocalTime (..), TimeOfDay (..), TimeZone,+                   ZonedTime (..), fromGregorian, minutesToTimeZone)   date :: Parser Day
src/Parsers/Json.hs view
@@ -1,12 +1,12 @@ module Parsers.Json (json, nil, number, bool, string, array, object) where -import Parser(Parser, exactly)-import ParserCombinators (IsMatch(..), (<|>), (|*), maybeWithin)-import Parsers.Number (double)+import Parser              (Parser)+import ParserCombinators   (IsMatch (..), maybeWithin, (<|>), (|*))+import Parsers.Char        (colon, doubleQuote) import Parsers.Collections (listOf, mapOf)-import Parsers.Char (doubleQuote, colon)-import Parsers.String (withinDoubleQuotes, spacing)-import SyntaxTrees.Json (JsExpression(..))+import Parsers.Number      (double)+import Parsers.String      (spacing, withinDoubleQuotes)+import SyntaxTrees.Json    (JsExpression (..))   json :: Parser JsExpression
src/Parsers/Number.hs view
@@ -1,8 +1,8 @@ module Parsers.Number (int, double, posInt, negInt, unsignedInt, hexInt, octInt, intLike) where -import Parser (Parser, errorParser, ParseError(..))-import ParserCombinators (IsMatch(..), (>>>), (<|>), (|+), (|?))-import Parsers.Char (digit, dot, dash, plus)+import Parser            (ParseError (..), Parser, errorParser)+import ParserCombinators (IsMatch (..), (<|>), (>>>), (|+), (|?))+import Parsers.Char      (dash, digit, dot, plus)   hexInt :: Parser Integer
src/Parsers/String.hs view
@@ -1,12 +1,13 @@ module Parsers.String where -import Parser (Parser)-import ParserCombinators (IsMatch(..), (|*), (|+), (|?), (>>>), within, withinBoth,-                         maybeWithin, maybeWithinBoth)-import Parsers.Char (char, digit, upper, lower, letter, alpha, alphaNum,-                     space, tab, spaceOrTab, whiteSpace, newLine, quote,-                     doubleQuote, openParens, closeParens, openSquare,-                     closeSquare, openCurly, closeCurly, openAngle, closeAngle)+import Parser            (Parser)+import ParserCombinators (IsMatch (..), maybeWithin, maybeWithinBoth, within,+                          withinBoth, (>>>), (|*), (|+), (|?))+import Parsers.Char      (alpha, alphaNum, char, closeAngle, closeCurly,+                          closeParens, closeSquare, digit, doubleQuote, letter,+                          lower, newLine, openAngle, openCurly, openParens,+                          openSquare, quote, space, spaceOrTab, tab, upper,+                          whiteSpace)   string :: Parser String
src/Parsers/Toml.hs view
@@ -1,20 +1,23 @@ module Parsers.Toml (toml, nil, integer, float, bool, string,                      array, inlineTable) where -import Parser(Parser)-import ParserCombinators (IsMatch(..), (<|>), (>>>), (<#>), (|?), (|*), (|+),-                          maybeWithin, within)-import Parsers.Number (double, hexInt, int, octInt)-import Parsers.String (blankLine, withinQuotes, withinDoubleQuotes,-                       spacesOrTabs, withinSquareBrackets, spacing, blankLines)-import Parsers.Char (quote, doubleQuote, whiteSpace, hashTag, newLine,-                     dot, digit, letter, underscore, dash, equal, spaceOrTab)-import SyntaxTrees.Toml (TomlExpression(..), TableType(..))-import Parsers.Collections (mapOf, listOf)+import Parser              (Parser)+import ParserCombinators   (IsMatch (..), maybeWithin, within, (<#>), (<|>),+                            (>>>), (|*), (|+), (|?))+import Parsers.Char        (dash, digit, dot, doubleQuote, equal, hashTag,+                            letter, newLine, quote, spaceOrTab, underscore,+                            whiteSpace)+import Parsers.Collections (listOf, mapOf)+import Parsers.Number      (double, hexInt, int, octInt)+import Parsers.String      (blankLine, blankLines, spacesOrTabs, spacing,+                            withinDoubleQuotes, withinQuotes,+                            withinSquareBrackets)+import SyntaxTrees.Toml    (TableType (..), TomlExpression (..))+ import qualified Parsers.DateTime as Dt -import qualified Data.Map as Map-import Data.Maybe (maybeToList)+import qualified Data.Map   as Map+import           Data.Maybe (maybeToList)   
src/Parsers/Xml.hs view
@@ -1,14 +1,13 @@ module Parsers.Xml (xml, branchExpr, leafExpr, literal) where -import Parser (Parser)-import ParserCombinators (IsMatch(..), (<|>), (|*), (|+), maybeWithin)-import Parsers.Char (doubleQuote)-import Parsers.String (withinDoubleQuotes, withinAngleBrackets, spacing)-import SyntaxTrees.Xml ( XmlExpression(..), literalExpression )+import Parser            (Parser)+import ParserCombinators (IsMatch (..), maybeWithin, (<|>), (|*), (|+))+import Parsers.Char      (doubleQuote)+import Parsers.String    (spacing, withinAngleBrackets, withinDoubleQuotes)+import SyntaxTrees.Xml   (XmlExpression (..), literalExpression) +import           Data.Map (Map) import qualified Data.Map as Map-import Data.Map(Map)-   xml :: Parser XmlExpression
src/Parsers/Yaml.hs view
@@ -2,19 +2,21 @@                      list, mapping) where  -import SyntaxTrees.Yaml (YamlExpression(..), CollectionType(..))-import Parser(Parser, check, andThen, exactly)-import ParserCombinators (IsMatch(..), (<|>), (<#>), (>>>), (|?), (|*), (|+), (|++), maybeWithin)-import Parsers.Number (double, hexInt, int, octInt)-import Parsers.String (spaces, spacesOrTabs, withinDoubleQuotes, withinQuotes,-                        blankLine, blankLines, tabs)-import Parsers.Char (colon, dash, space, whiteSpace, newLine, question, dot, hashTag,-                     quote, doubleQuote, char)-import Parsers.Collections (mapOf, listOf)+import Parser              (Parser, andThen, check, exactly)+import ParserCombinators   (IsMatch (..), maybeWithin, (<#>), (<|>), (>>>),+                            (|*), (|+), (|++), (|?))+import Parsers.Char        (char, colon, dash, dot, doubleQuote, hashTag,+                            newLine, question, quote, space, whiteSpace)+import Parsers.Collections (listOf, mapOf)+import Parsers.Number      (double, hexInt, int, octInt)+import Parsers.String      (blankLine, blankLines, spaces, spacesOrTabs, tabs,+                            withinDoubleQuotes, withinQuotes)+import SyntaxTrees.Yaml    (CollectionType (..), YamlExpression (..))+ import qualified Parsers.DateTime as Dt -import qualified Data.Map as Map-import Data.List (nub)+import           Data.List (nub)+import qualified Data.Map  as Map   
src/SyntaxTrees/Json.hs view
@@ -1,18 +1,21 @@ module SyntaxTrees.Json (JsExpression(..)) where  import Utils.Foldable (stringify)-import Utils.Map (showMap)+import Utils.Map      (showMap) -import Data.Map (Map) import Data.Char (toLower)+import Data.Map  (Map)   -data JsExpression = JsNumber Double | JsBool Bool |-                    JsString String |-                    JsArray [JsExpression] |-                    JsObject (Map String JsExpression) |-                    JsNull deriving (Eq, Ord)+data JsExpression+  = JsNumber Double+  | JsBool Bool+  | JsString String+  | JsArray [JsExpression]+  | JsObject (Map String JsExpression)+  | JsNull+  deriving (Eq, Ord)   instance Show JsExpression where
src/SyntaxTrees/Toml.hs view
@@ -2,25 +2,35 @@  import Utils.DateTime (showDateTime) import Utils.Foldable (stringify)-import Utils.Map (showMap)+import Utils.Map      (showMap) -import Data.Map (Map)-import qualified Data.Map as Map-import Data.Time (Day, TimeOfDay, ZonedTime(..)) import Data.Char (toLower)+import Data.Time (Day, TimeOfDay, ZonedTime (..)) +import           Data.Map (Map)+import qualified Data.Map as Map  -data TomlExpression = TomlInteger Integer | TomlFloat Double | TomlBool Bool |-                      TomlString String | TomlDate Day |-                      TomlTime TimeOfDay | TomlDateTime ZonedTime |-                      TomlArray [TomlExpression] |-                      TomlTable TableType (Map String TomlExpression) |-                      TomlNull-                    deriving (Eq, Ord) +data TomlExpression+  = TomlInteger Integer+  | TomlFloat Double+  | TomlBool Bool+  | TomlString String+  | TomlDate Day+  | TomlTime TimeOfDay+  | TomlDateTime ZonedTime+  | TomlArray [TomlExpression]+  | TomlTable TableType (Map String TomlExpression)+  | TomlNull+  deriving (Eq, Ord) -data TableType = TopLevel | Standard | Inline deriving (Eq, Ord)++data TableType+  = TopLevel+  | Standard+  | Inline+  deriving (Eq, Ord)   instance Show TomlExpression where
src/SyntaxTrees/Xml.hs view
@@ -2,18 +2,21 @@  import Utils.Foldable (stringify) -import Data.Map (Map, keys, elems)-import qualified Data.Map as Map import Data.Maybe (listToMaybe) +import           Data.Map (Map, elems, keys)+import qualified Data.Map as Map -data XmlExpression = XmlExpression {-    tagName     :: String-  , fields      :: Map String String-  , expressions :: [XmlExpression]-  } deriving (Eq, Ord) +data XmlExpression+  = XmlExpression+      { tagName     :: String+      , fields      :: Map String String+      , expressions :: [XmlExpression]+      }+  deriving (Eq, Ord) + instance Show XmlExpression where    show XmlExpression { tagName = tag, .. }@@ -24,7 +27,7 @@                         | otherwise        -> ">"  ++ ending          (sep, n) = if | ((tagName) . head) expressions == "literal" -> ("", 0)-                      | otherwise                                    -> ("\n", 2)+                      | otherwise                                   -> ("\n", 2)          ending = stringify sep sep sep n (show <$> expressions) ++ "</" ++ tag ++ ">" 
src/SyntaxTrees/Yaml.hs view
@@ -2,24 +2,32 @@  import Utils.DateTime () import Utils.Foldable (stringify)-import Utils.Map (showMap)+import Utils.Map      (showMap) -import Data.Map (Map)-import qualified Data.Map as Map-import Data.Char (toLower)-import Data.Time (Day, TimeOfDay, ZonedTime(..))+import           Data.Char (toLower)+import           Data.Map  (Map)+import qualified Data.Map  as Map+import           Data.Time (Day, TimeOfDay, ZonedTime (..))   -data YamlExpression = YamlInteger Integer | YamlFloat Double | YamlBool Bool |-                      YamlString String | YamlDate Day |-                      YamlTime TimeOfDay | YamlDateTime ZonedTime |-                      YamlList CollectionType [YamlExpression] |-                      YamlMap CollectionType (Map String YamlExpression) |-                      YamlNull-                    deriving (Eq, Ord)+data YamlExpression+  = YamlInteger Integer+  | YamlFloat Double+  | YamlBool Bool+  | YamlString String+  | YamlDate Day+  | YamlTime TimeOfDay+  | YamlDateTime ZonedTime+  | YamlList CollectionType [YamlExpression]+  | YamlMap CollectionType (Map String YamlExpression)+  | YamlNull+  deriving (Eq, Ord) -data CollectionType = Standard | Inline deriving (Eq, Ord)+data CollectionType+  = Standard+  | Inline+  deriving (Eq, Ord)   instance Show YamlExpression where
src/Utils/DateTime.hs view
@@ -2,7 +2,7 @@  module Utils.DateTime where -import Data.Time (ZonedTime(..), LocalTime(..))+import Data.Time (LocalTime (..), ZonedTime (..))   instance Eq ZonedTime where
src/Utils/Foldable.hs view
@@ -1,8 +1,8 @@ module Utils.Foldable where -import Utils.String (indent)-import Data.Foldable as Foldable (Foldable(toList))-import Data.List (intercalate)+import Data.Foldable as Foldable (Foldable (toList))+import Data.List     (intercalate)+import Utils.String  (indent)   hasNone :: Foldable m => m a -> Bool
src/Utils/Map.hs view
@@ -1,6 +1,6 @@ module Utils.Map where -import Data.Map (Map, keys, elems)+import Data.Map (Map, elems, keys)   showMap :: String -> (String -> String) -> (a -> String) -> Map String a -> [String]