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

Float parser does not parse negative numbers #115

Closed
Swordlash opened this issue May 23, 2021 · 3 comments · Fixed by #142 or #225
Closed

Float parser does not parse negative numbers #115

Swordlash opened this issue May 23, 2021 · 3 comments · Fixed by #142 or #225
Labels
type: bug Something that should function correctly isn't.

Comments

@Swordlash
Copy link

Describe the bug
Token parser created by (makeTokenParser emptyDef).float does not parse negative numbers.

To Reproduce
In repl, import Text.Parsing.Parser, Text.Parsing.Parser.Language and Text.Parsing.Parser.Token.
Evaluate runParser "(-6.0)" (makeTokenParser emptyDef).float (parentheses don't matter).

Expected behavior
Right (-6.0)

Actual behavior
(Left (ParseError "Expected float" (Position { line: 1, column: 1 })))

Additional context
I think the parser should be able to parse negative numbers. integer parser already does. Perhaps add a sign-aware parser?

@Swordlash Swordlash added the type: bug Something that should function correctly isn't. label May 23, 2021
@jamesdbrock
Copy link
Member

Yeah that sounds like a bug. Thank you very much for reporting.

jamesdbrock added a commit that referenced this issue Jan 13, 2022
@jamesdbrock jamesdbrock linked a pull request Jan 13, 2022 that will close this issue
4 tasks
jamesdbrock added a commit that referenced this issue Jan 23, 2022
@jamesdbrock
Copy link
Member

Hi @Swordlash I hope #142 solves your problem. Please reopen this issue if it doesn't.

@mstream
Copy link
Contributor

mstream commented Apr 29, 2023

Hello @jamesdbrock,

This still seems to be an issue in the 10.2.0 version of the library.

That's probably because the float parser is implemented like this:

float :: ParserT String m Number
float = lexeme floating <?> "float"
 
floating :: ParserT String m Number
floating = decimal >>= fractExponent

And decimal does not parse negative numbers, which is also mentioned in the comment.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug Something that should function correctly isn't.
3 participants