parser
parser copied to clipboard
Parsing two ints fails when separated by an 'x'
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 )
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"
Possibly related to ints ability to parse hexadecimal?
http://package.elm-lang.org/packages/elm-tools/parser/2.0.1/Parser#int