Skip to content

Parse generic numbers (int, hex, real) #89

Answered by foonathan
facontidavide asked this question in Q&A
Discussion options

You must be logged in to vote

The only case that I am not handling correctly is the string 0x100.2 that should fail.

I mean, it does fail. It leaves a .2 on the input which will cause subsequent parse operations to fail or exit early. If you add a + dsl::eof to the root production, lexy will complain about the trailing input: https://godbolt.org/z/Y8dafdqzn

You can use dsl::peek_not to get a custom error if it happens: https://godbolt.org/z/cqzjdxbTx

You can even get a bit more fancy by recovering after the error: https://godbolt.org/z/nEbfd94oE

Replies: 3 comments 3 replies

Comment options

You must be logged in to vote
0 replies
Answer selected by foonathan
Comment options

You must be logged in to vote
2 replies
@foonathan
Comment options

@facontidavide
Comment options

Comment options

You must be logged in to vote
1 reply
@facontidavide
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants