j-mie6 / parsley

A fast and modern parser combinator library for Scala
https://j-mie6.github.io/parsley/
BSD 3-Clause "New" or "Revised" License
173 stars 15 forks source link

Add support for custom error messages when dealing with overflow Binary/Hex/Octal integer parsing #231

Closed MarkWheelhouse closed 5 months ago

MarkWheelhouse commented 5 months ago

At the moment, if you try to parse a Binary, Hex or Octal integer literal (with the correct flags set) that is too large to be represented as a 32-bit Int, you get a rather unhelpful "unrecognised {x,b,o}" error message, rather than something more informative.

It would be good if this could be handled either internally by parsley, or if there was some way to hook a custom error message of of such an invalid input catch.

j-mie6 commented 5 months ago

Seems like the internal representation in number32 works fine for this, but octal32 | hexadecimal32 | binary32 | decimal32 does not. This makes sense as these are all atomic, so a failure to parse an in bounds is going to defer to a later number and be syntactically invalid that way. I don't think there is a nice way, necessarily, of allowing that to work, except by using number32.