Skip to content

Commit

Permalink
Import hw-parser
Browse files Browse the repository at this point in the history
  • Loading branch information
newhoggy committed Feb 12, 2025
1 parent 620220e commit 579e7c1
Show file tree
Hide file tree
Showing 5 changed files with 115 additions and 2 deletions.
12 changes: 12 additions & 0 deletions components/succinct-parser--doctest/DoctestDriver.hs
Original file line number Diff line number Diff line change
@@ -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
3 changes: 3 additions & 0 deletions components/succinct-parser--doctest/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"sourceFolders": ["components/succinct-parser"]
}
1 change: 1 addition & 0 deletions components/succinct-parser--test/Spec.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{-# OPTIONS_GHC -F -pgmF hspec-discover #-}
62 changes: 62 additions & 0 deletions components/succinct-parser/HaskellWorks/Data/Parser.hs
Original file line number Diff line number Diff line change
@@ -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 #-}
39 changes: 37 additions & 2 deletions succinct.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down Expand Up @@ -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 }
Expand Down Expand Up @@ -286,14 +286,14 @@ library succinct-json
, dlist
, hw-bits
, hw-mquery
, hw-parser
, hw-prim
, mmap
, prettyprinter
, scientific
, succinct-balancedparens
, succinct-json-simple-cursor
, succinct-json-standard-cursor
, succinct-parser
, succinct-rankselect
, succinct-rankselect-base
, succinct-simd
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 579e7c1

Please # to comment.