Skip to content
This repository has been archived by the owner on Feb 4, 2021. It is now read-only.

Parsing two ints fails when separated by an 'x' #28

Open
Taneb opened this issue Nov 7, 2017 · 2 comments
Open

Parsing two ints fails when separated by an 'x' #28

Taneb opened this issue Nov 7, 2017 · 2 comments
Labels

Comments

@Taneb
Copy link

Taneb commented Nov 7, 2017

My code:

> parser = Parser.succeed (,) |= Parser.int |. Parser.symbol "x" |= Parser.int
> Parser.run parser "1x1"

Expected output:

( 1, 1 ) : ( Int, Int )

Actual ouput:

Err { row = 1, col = 2, source = "1x1", problem = BadInt, context = [] }
    : Result.Result Parser.Error ( Int, Int )
@Taneb Taneb changed the title Parsing two ints fails Parsing two ints fails when separated by an 'x' Nov 7, 2017
@jinjor
Copy link
Contributor

jinjor commented Nov 30, 2017

I ran into the same problem. It seems Parser.int reads non-digit characters right after digits.

This passes.

run int "2+" --> Ok 2

This fails. (BadInt)

run int "2m" --> Ok 2
    Ok 2
    ╷
    │ Expect.equal
    ╵
    Err { row = 1, col = 2, source = "2m", problem = BadInt, context = [] }

The parser that I actually wanted to work is:

meter : Parser Int
meter =
   succeed identity
     |= int
     |. keyword "m"

@SidneyNemzer
Copy link

Possibly related to ints ability to parse hexadecimal?

https://package.elm-lang.org/packages/elm-tools/parser/2.0.1/Parser#int

@evancz evancz added the problem label May 3, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

4 participants