Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Initially feeding a parser with empty string results in non-obvious parse #75

Closed
bgamari opened this issue Aug 26, 2014 · 2 comments
Closed

Comments

@bgamari
Copy link
Collaborator

bgamari commented Aug 26, 2014

While writing a parser Fold for @Gabriel439's foldl package I stumbled upon this interesting inconsistency (full example here),

A.eitherResult
$ flip A.feed ""
$ flip A.feed "123"
$ A.parse A.double "1.3"
== 1.3123

A.eitherResult
$ flip A.feed ""
$ flip A.feed "123"
$ flip A.feed "1.3"
$ A.parse A.double ""
== 1.3

Given that empty strings are a bit special as they indicate the end of the stream it's not entirely clear that this is a bug but it is quite surprising. Why does the initial empty string affect the resulting parse? Is this considered buggy behavior?

@bos
Copy link
Collaborator

bos commented Aug 26, 2014

Smaller repro:

{-# LANGUAGE OverloadedStrings #-}

import Data.ByteString
import Control.Applicative
import qualified Data.Attoparsec.ByteString.Char8 as A

wat :: A.Parser ByteString
wat = do
  "a"
  "b" <|> ("empty" <$ "")

@bos bos closed this as completed in 3c47ecd Aug 27, 2014
bos added a commit that referenced this issue Aug 27, 2014
@bgamari
Copy link
Collaborator Author

bgamari commented Aug 27, 2014

Thanks!

mamash pushed a commit to TritonDataCenter/pkgsrc-wip that referenced this issue Sep 6, 2014
changelog:
0.12.1.2

* Fixed the incorrect tracking of capacity if the initial buffer was
  empty (haskell/attoparsec#75)

0.12.1.1

* Fixed a data corruption bug that occurred under some circumstances
  if a buffer grew after prompting for more input
  (haskell/attoparsec#74)

0.12.1.0

* Now compatible with GHC 7.9

* Reintroduced the Chunk class, used by the parsers package

0.12.0.0

* A new internal representation makes almost all real-world parsers
  faster, sometimes by big margins.  For example, parsing JSON data
  with aeson is now up to 70% faster.  These performance improvements
  also come with reduced memory consumption and some new capabilities.

* The new match combinator gives both the result of a parse and the
  input that it matched.

* The test suite has doubled in size.  This made it possible to switch
  to the new internal representation with a decent degree of
  confidence that everything was more or less working.

* The benchmark suite now contains a small family of benchmarks taken
  from real-world uses of attoparsec.

* A few types that ought to have been private now are.

* A few obsolete modules and functions have been marked as deprecated.
  They will be removed from the next major release.

0.11.3.0

* New function scientific is compatible with rational, but parses
  integers more efficiently (haskell/aeson#198)

0.11.2.0

* The new Chunk typeclass allows for some code sharing with Ed
  Kmett's parsers package: http://hackage.haskell.org/package/parsers

* New function runScanner generalises scan to return the final state
  of the scanner as well as the input consumed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants