Skip to content

Bug in spanP #21

@SpectreVert

Description

@SpectreVert

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions