diff --git a/components/succinct-parser--doctest/DoctestDriver.hs b/components/succinct-parser--doctest/DoctestDriver.hs new file mode 100644 index 0000000..bf68dd0 --- /dev/null +++ b/components/succinct-parser--doctest/DoctestDriver.hs @@ -0,0 +1,12 @@ +{-# LANGUAGE CPP #-} + +#if MIN_VERSION_GLASGOW_HASKELL(8,4,4,0) +{-# OPTIONS_GHC -F -pgmF doctest-discover -optF components/succinct-parser--doctest/config.json #-} +#else +module Main where + +import qualified System.IO as IO + +main :: IO () +main = IO.putStrLn "WARNING: doctest will not run on GHC versions earlier than 8.4.4" +#endif diff --git a/components/succinct-parser--doctest/config.json b/components/succinct-parser--doctest/config.json new file mode 100644 index 0000000..3657087 --- /dev/null +++ b/components/succinct-parser--doctest/config.json @@ -0,0 +1,3 @@ +{ + "sourceFolders": ["components/succinct-parser"] +} \ No newline at end of file diff --git a/components/succinct-parser--test/Spec.hs b/components/succinct-parser--test/Spec.hs new file mode 100644 index 0000000..a824f8c --- /dev/null +++ b/components/succinct-parser--test/Spec.hs @@ -0,0 +1 @@ +{-# OPTIONS_GHC -F -pgmF hspec-discover #-} diff --git a/components/succinct-parser/HaskellWorks/Data/Parser.hs b/components/succinct-parser/HaskellWorks/Data/Parser.hs new file mode 100644 index 0000000..f6b201e --- /dev/null +++ b/components/succinct-parser/HaskellWorks/Data/Parser.hs @@ -0,0 +1,62 @@ +{-# LANGUAGE FunctionalDependencies #-} +{-# LANGUAGE MultiParamTypeClasses #-} + +module HaskellWorks.Data.Parser + ( Parser(..) + ) where + +import Data.ByteString (ByteString) +import Data.Text (Text) +import Data.Word +import HaskellWorks.Data.Char.IsChar + +import qualified Data.Attoparsec.ByteString as ABS +import qualified Data.Attoparsec.ByteString.Char8 as BC +import qualified Data.Attoparsec.Text as AT +import qualified Data.Attoparsec.Types as T + +class Parser t e | t -> e where + satisfy :: (e -> Bool) -> T.Parser t e + satisfyWith :: (e -> a) -> (a -> Bool) -> T.Parser t a + satisfyChar :: (Char -> Bool) -> T.Parser t Char + string :: t -> T.Parser t t + try :: T.Parser t a -> T.Parser t a + char :: Char -> T.Parser t Char + () :: T.Parser t Char -> String -> T.Parser t Char + rational :: Fractional f => T.Parser t f + +instance Parser ByteString Word8 where + satisfy = ABS.satisfy + satisfyWith = ABS.satisfyWith + satisfyChar = ABS.satisfyWith toChar + string = ABS.string + try = ABS.try + char = BC.char + () = (BC.) + rational = BC.rational + {-# INLINE satisfy #-} + {-# INLINE satisfyWith #-} + {-# INLINE satisfyChar #-} + {-# INLINE string #-} + {-# INLINE try #-} + {-# INLINE char #-} + {-# INLINE () #-} + {-# INLINE rational #-} + +instance Parser Text Char where + satisfy = AT.satisfy + satisfyWith = AT.satisfyWith + satisfyChar = AT.satisfyWith toChar + string = AT.string + try = AT.try + char = AT.char + () = (AT.) + rational = AT.rational + {-# INLINE satisfy #-} + {-# INLINE satisfyWith #-} + {-# INLINE satisfyChar #-} + {-# INLINE string #-} + {-# INLINE try #-} + {-# INLINE char #-} + {-# INLINE () #-} + {-# INLINE rational #-} diff --git a/succinct.cabal b/succinct.cabal index a315ca9..1b562be 100644 --- a/succinct.cabal +++ b/succinct.cabal @@ -66,7 +66,6 @@ common hw-hedgehog { build-depends: hw-hedgehog common hw-hspec-hedgehog { build-depends: hw-hspec-hedgehog >= 0.1.0.4 && < 0.2 } common hw-int { build-depends: hw-int >= 0.0.2 && < 0.0.3 } common hw-mquery { build-depends: hw-mquery >= 0.2.0.0 && < 0.3 } -common hw-parser { build-depends: hw-parser >= 0.1 && < 0.2 } common hw-prim { build-depends: hw-prim >= 0.6.2.32 && < 0.7 } common lens { build-depends: lens >= 4 && < 6 } common mmap { build-depends: mmap >= 0.5 && < 0.6 } @@ -97,6 +96,7 @@ common succinct-json { build-depends: succinct:succinct-json common succinct-json-simd { build-depends: succinct:succinct-json-simd } common succinct-json-simple-cursor { build-depends: succinct:succinct-json-simple-cursor } common succinct-json-standard-cursor { build-depends: succinct:succinct-json-standard-cursor } +common succinct-parser { build-depends: succinct:succinct-parser } common succinct-rankselect { build-depends: succinct:succinct-rankselect } common succinct-rankselect-base { build-depends: succinct:succinct-rankselect-base } common succinct-simd { build-depends: succinct:succinct-simd } @@ -286,7 +286,6 @@ library succinct-json , dlist , hw-bits , hw-mquery - , hw-parser , hw-prim , mmap , prettyprinter @@ -294,6 +293,7 @@ library succinct-json , succinct-balancedparens , succinct-json-simple-cursor , succinct-json-standard-cursor + , succinct-parser , succinct-rankselect , succinct-rankselect-base , succinct-simd @@ -673,6 +673,41 @@ test-suite succinct-json-standard-cursor--doctest HS-Source-Dirs: components/succinct-json-standard-cursor--doctest build-tool-depends: doctest-discover:doctest-discover +library succinct-parser + import: base, config + , attoparsec + , bytestring + , hw-prim + , text + hs-source-dirs: components/succinct-parser + exposed-modules: HaskellWorks.Data.Parser + other-modules: Paths_succinct + autogen-modules: Paths_succinct + +test-suite succinct-parser--test + import: base, config + , hedgehog + , hspec + , hw-hspec-hedgehog + , succinct-parser + type: exitcode-stdio-1.0 + main-is: Spec.hs + hs-source-dirs: components/succinct-parser--test + ghc-options: -threaded -rtsopts -with-rtsopts=-N + build-tool-depends: hspec-discover:hspec-discover + +test-suite succinct-parser--doctest + import: base, config + , doctest + , doctest-discover + , succinct-parser + default-language: Haskell2010 + type: exitcode-stdio-1.0 + ghc-options: -threaded -rtsopts -with-rtsopts=-N + main-is: DoctestDriver.hs + HS-Source-Dirs: components/succinct-parser--doctest + build-tool-depends: doctest-discover:doctest-discover + library succinct-rankselect import: base, config , deepseq