scanner-attoparsec 0.1 → 0.2
raw patch · 4 files changed
+34/−4 lines, 4 filesdep ~attoparsecdep ~scannerPVP ok
version bump matches the API change (PVP)
Dependency ranges changed: attoparsec, scanner
API changes (from Hackage documentation)
+ Scanner.Attoparsec: toAtto :: Scanner a -> Parser a
Files
- README.md +1/−1
- changelog.md +5/−0
- lib/Scanner/Attoparsec.hs +23/−0
- scanner-attoparsec.cabal +5/−3
README.md view
@@ -1,7 +1,7 @@ # scanner-attoparsec Inject attoparsec parser with backtracking into non-backtracking scanner -[](https://travis-ci.org/Yuras/scanner-attoparsec)+[](https://github.com/Yuras/scanner-attoparsec/actions/workflows/build.yml) Backtracking kills performance, so scanner package doesn't support it. But sometimes you just need it. E.g. you have a mostly non-backtracking
changelog.md view
@@ -1,4 +1,9 @@ +0.2++* add toAtto++ 0.1 * initial implementation
lib/Scanner/Attoparsec.hs view
@@ -1,15 +1,19 @@ module Scanner.Attoparsec ( atto+, toAtto ) where import qualified Scanner import Scanner.Internal (Scanner (Scanner)) +import Data.Maybe+import qualified Data.ByteString as ByteString import qualified Data.Attoparsec.ByteString as Atto {-# INLINE atto #-}+-- | Convert attoparsec parser into a scanner atto :: Atto.Parser a -> Scanner a atto p = Scanner $ \bs next -> case Atto.parse p bs of@@ -22,3 +26,22 @@ Atto.Done bs' r -> next bs' r Atto.Fail bs' _ err -> Scanner.Fail bs' err Atto.Partial cont' -> slowPath cont' next++-- | Convert scanner to attoparsec parser+--+-- @since 0.2+toAtto :: Scanner a -> Atto.Parser a+toAtto s = go (Scanner.scan s)+ where+ go run = do+ chunk <- fromMaybe ByteString.empty <$> Atto.getChunk+ case run chunk of+ Scanner.Done bs r -> do+ _ <- Atto.take (ByteString.length chunk - ByteString.length bs)+ return r+ Scanner.Fail bs msg -> do+ _ <- Atto.take (ByteString.length chunk - ByteString.length bs)+ fail msg+ Scanner.More next -> do+ _ <- Atto.take (ByteString.length chunk)+ go next
scanner-attoparsec.cabal view
@@ -1,5 +1,5 @@ name: scanner-attoparsec-version: 0.1+version: 0.2 synopsis: Inject attoparsec parser with backtracking into non-backtracking scanner homepage: https://github.com/Yuras/scanner-attoparsec license: BSD3@@ -28,8 +28,9 @@ other-modules: Data.Either ghc-options: -O2 build-depends: base <5- , attoparsec- , scanner+ , bytestring+ , attoparsec >= 0.14.1+ , scanner <0.4 hs-source-dirs: lib, compat default-language: Haskell2010 @@ -37,6 +38,7 @@ type: exitcode-stdio-1.0 hs-source-dirs: spec, compat main-is: spec.hs+ other-modules: Data.Either build-depends: base <5 , bytestring , scanner