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

Bug in spanP #21

Open
SpectreVert opened this issue Mar 18, 2021 · 0 comments
Open

Bug in spanP #21

SpectreVert opened this issue Mar 18, 2021 · 0 comments

Comments

@SpectreVert
Copy link

SpectreVert commented Mar 18, 2021

spanP is defined as below:

spanP :: String           -- description
      -> (Char -> Bool)   -- predicate
      -> Parser String
spanP desc = many . parseIf desc

Using many here instead of some makes it so matching nothing or even getting an empty input is not an error.

How to reproduce

> ghci Main.hs
λ> runParser (spanP "integer" isDigit) $ Input 0 ""
Right (Input {inputLoc = 0, inputStr = ""},"")
λ> runParser (spanP "integer" isDigit) $ Input 0 "abcde"
Right (Input {inputLoc = 0, inputStr = "abcde"},"")

As of now spanP creates a parser which does not return an error on parse failure of string.

I'm not sure if that is the intended behavior but that might bring some trouble later on.

N.B: See many / some documentation here.

I'm aware that for removing optional whitespaces and such the many is required. Maybe there should be a spanP' that uses some instead for the other cases.

@SpectreVert SpectreVert changed the title Possible bug in spanP Bug in spanP Mar 18, 2021
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

1 participant