Invalid cast lexy::lexeme<lexy::_br8> to int processing a float #166
-
I am trying to read an int then and optional int and recreate the float from that. But it requires a weird conversion from lexy::lexemelexy::_br8 that I am not sure how it happened. My production is: struct Decimal : lexy::token_production {
struct IntegerPart : lexy::transparent_production {
static constexpr auto rule =
dsl::minus_sign + dsl::integer<int>(dsl::digits<>.no_leading_zero());
static constexpr auto value = lexy::as_integer<int>;
};
struct DecimalPart : lexy::transparent_production {
static constexpr auto rule = dsl::lit_c<'.'> >> dsl::capture(dsl::digits<>);
static constexpr auto value = lexy::as_integer<int>;
};
static constexpr auto rule = dsl::peek(dsl::lit_c<'-'> / dsl::digit<>)
>> (dsl::p<IntegerPart> + dsl::opt(dsl::p<DecimalPart>));
static constexpr auto value = lexy::callback<ast::Decimal>(
[](int integer, lexy::nullopt) {
return integer;
},
[](auto integer, int decimal) {
const double numberOfDigits = decimal > 0 ? std::ceil(std::log10(decimal)) : 1;
return static_cast<double>(integer) + decimal * std::pow(10.0, -1 * numberOfDigits);
});
}; Any pointers? Full code https://godbolt.org/z/5fGjT4Msb |
Beta Was this translation helpful? Give feedback.
Answered by
EmmanuelMess
Jul 28, 2023
Replies: 1 comment
-
The problem here is that |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
EmmanuelMess
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The problem here is that
dsl::capture
returns a lexme, changing the capture todsl::capture(dsl::digits<>)
works.