snack: Strict ByteString Parser Combinator

[ library, parsing, text ] [ Propose Tags ] [ Report a vulnerability ]

Simple parser combinator for strict ByteString values.


[Skip to Readme]

Downloads

Maintainer's Corner

Package maintainers

For package maintainers and hackage trustees

Candidates

  • No Candidates
Versions [RSS] 0.1.0.0, 0.2.0.0, 0.3.0.0, 0.4.0.0
Change log Changelog.md
Dependencies base (>=4.13 && <5), bytestring (>=0.10.12), bytestring-lexing (>=0.5), text (>=2.0) [details]
Tested with ghc ==9.2.1
License CC0-1.0
Copyright Jan Hamal Dvořák
Author Jan Hamal Dvořák
Maintainer mordae@anilinux.org
Category Text, Parsing
Home page https://github.com/mordae/snack#readme
Bug tracker https://github.com/mordae/snack/issues
Source repo head: git clone https://github.com/mordae/snack.git
Uploaded by mordae at 2022-07-16T14:29:05Z
Distributions NixOS:0.4.0.0
Downloads 247 total (6 in the last 30 days)
Rating (no votes yet) [estimated by Bayesian average]
Your Rating
  • λ
  • λ
  • λ
Status Docs available [build log]
Last success reported on 2022-07-16 [all 1 reports]

Readme for snack-0.4.0.0

[back to package description]

snack

Strict ByteString Parser Combinator

  • Simple. Feel free to contribute.
  • Fast. Sometimes faster then Attoparsec.
  • ASCII. Good enough for IETF formats.
  • Also Text. But quite slower.

Example:

import Data.ByteString (ByteString)
import qualified Data.ByteString.Parser.Char8 as BSP

parseList :: BSP.Parser [ByteString]
parseList = (token `BSP.wrap` BSP.skipSpace) `BSP.sepBy` BSP.char ','
  where token = BSP.takeWhile isToken
        isToken c = inRange 'a' 'z' c ||
                    inRange 'A' 'Z' c ||
                    inRange '0' '9' c ||
                    c == '_' || c == '-'

main :: IO ()
main = do
  putStrLn $ show $ BSP.runParser parseList "monkey, wrench, bananas"
  putStrLn $ show $ BSP.runParser parseList "^quux"
  putStrLn $ show $ BSP.runParser (parseList <* BSP.endOfInput) "^quux"

-- Will output:
-- Success ["monkey","wrench","bananas"] ""
-- Success [""] "^quux"
-- Failure ["end of input"] "^quux"