Parse generic numbers (int, hex, real) #89
-
Follow up of #85
For the sake of completeness, this is the final solution I found to address negative integers and hexadecimals as well: https://godbolt.org/z/Td76TsrKK The only case that I am not handling correctly is the string |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 3 replies
-
I mean, it does fail. It leaves a You can use You can even get a bit more fancy by recovering after the error: https://godbolt.org/z/nEbfd94oE |
Beta Was this translation helpful? Give feedback.
-
thanks a lot! Something that confuse me a little is this static constexpr auto rule = [] {
auto hex_integer = LEXY_LIT("0x") >> dsl::integer<int, dsl::hex>;
auto regular_integer = dsl::peek(dsl::lit_c<'-'> / dsl::lit_c<'+'> / dsl::digit<>) >> dsl::p<integer>;
auto float_error = dsl::peek_not(dsl::period / dsl::lit_c<'e'> / dsl::lit_c<'E'>).error<invalid_float_suffix>;
return ( hex_integer | regular_integer ) >> float_error;
}(); I expected it to be return ( hex_integer | regular_integer ) + float_error; That doesn't compile ("choice requires a branch condition"). |
Beta Was this translation helpful? Give feedback.
-
BTW, as of 0370d94 the recovery behavior of |
Beta Was this translation helpful? Give feedback.
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/Y8dafdqznYou can use
dsl::peek_not
to get a custom error if it happens: https://godbolt.org/z/cqzjdxbTxYou can even get a bit more fancy by recovering after the error: https://godbolt.org/z/nEbfd94oE