parser icon indicating copy to clipboard operation
parser copied to clipboard

Parsing two ints fails when separated by an 'x'

Open Taneb opened this issue 7 years ago • 2 comments

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 avatar Nov 07 '17 12:11 Taneb

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"

jinjor avatar Nov 30 '17 07:11 jinjor

Possibly related to ints ability to parse hexadecimal?

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

SidneyNemzer avatar Jan 26 '18 07:01 SidneyNemzer