-
Notifications
You must be signed in to change notification settings - Fork 60
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
Add bounded integer parsing #72
Comments
You're just needing a lower upper limit, right? If so, I'd be happy with Your proposed As such,I feel that checking whether e.g. a register is out of bounds isn't something that lexy should do, it's something that should be handled later, just like any other semantic errors. I'm already making an exception for overflow in general and lexy::code_point in particular, so checking for a maximal value is probably okay, but I don't like the min check. Does it make sense to you what I'm saying? :D |
You're quite right - I hadn't fully thought that part of it through, and as I hadn't done any test cases for the minimum bound checking, I hadn't discovered it that way yet!
Yeah, that makes sense - I think my preference for doing some semantic checking within the parser (and potentially getting better locality of where the error occurred within the input text) probably comes from ANTLR's semantic predicates, as ANTLR was the first parser generator I used. And, to be honest, most of the range checking I want to do in a parser tends to be of unsigned integers, so the I'll put together a PR with a |
Thanks, please also try and use it to implement the specialization for |
I'm trying out
lexy
with a re-implementation of a parser I've already got which, in part, parses register names of the formr<0..31>
andf<0..15>
- i.e. there are 32 general purpose registers (namedr0
,r1
, ...r31
) and 16 floating point registers.I'd like to verify that the register number is in range when parsed, so I'd like to have something like
lexy::code_point
, which has traits that check the parsed integer is in range. I've come up with the following generic bounded integer struct (kind of modelled onunbounded
).This can be used like this:
Is this something that would make a useful addition to
lexy
? If so, I'm happy enough to create a PR based on this...The text was updated successfully, but these errors were encountered: