Cannot use lexy::new_ but I can use a lambda with the same parameters as the constructor #242
Replies: 2 comments 5 replies
|
An explicit constructor means you don't have automatic conversion, you must explicitly call the constructor to initialize a StringLiteralExpressionSyntax from a string, what callback is constructing the string? Cause if it doesn't pass specifically a std::string it will not convert and so fail to compile, however std::string itself can be constructed with implicit conversions. And if your other rules can produce an integer then no casting is needed. |
|
Can you post a full compilable example? I've tried to reproduce it to this, but that one compiles: struct ExpressionSyntax
{
virtual ~ExpressionSyntax() = default;
};
struct StringLiteralExpressionSyntax : public ExpressionSyntax
{
explicit StringLiteralExpressionSyntax(std::string value)
{
(void)value;
}
};
struct string_literal
{
static constexpr auto rule
= [] { return dsl::quoted.limit(dsl::ascii::newline)(-dsl::ascii::control); }();
static constexpr auto value = lexy::as_string<std::string, lexy::utf8_encoding>;
};
struct production
{
static constexpr auto whitespace = dsl::ascii::space;
static constexpr auto rule = dsl::p<string_literal>;
static constexpr auto value = lexy::callback<std::unique_ptr<ExpressionSyntax>>(
lexy::new_<StringLiteralExpressionSyntax, std::unique_ptr<ExpressionSyntax>>);
};My guess is that maybe there is some ambiguity in the overload set of the callback. Is there maybe anything else that produces something similar to |
Uh oh!
There was an error while loading. Please reload this page.
I have the following struct for a quoted string literal production:
In my expression production, I have the string literal production as an atom.
The expression value is as follows:
However, this gives me
missing value callback overload for productionwhen trying to build it.It I change the
lexy::new_<StringLiteralExpressionSyntax, ExpressionSyntaxPtr>by a lambda that explicitely constructs it, it works:Why is that? Isn't
lexy::new_supposed to take theconstructor? This should be exactly equivalent.Why does it work for integer literals (exact same structure except that it's
intinstead ofstd::string) but not for strings?Thanks for your help!
All reactions