-
I'm having trouble getting Lexy to fully parse C++ expression statements (like All the other kinds of statements, like variable declarations and flow control statements, are significantly easier to deal with: as they all include some sort of prefix like Since expression statements are not prefixed by anything and my gigantic Code (with unnecessary parts omitted since it's already quite long): My questions are:
If you have any further questions about the attached snippet, feel free to ask them. Thanks in advance for answering, and thanks for making this library! |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 3 replies
-
UPDATE: I've managed to get it to (kind of) work with a dsl::lookahead condition: struct expression_statement
{
static constexpr auto rule = [] {
auto key_condition = dsl::lookahead(dsl::semicolon, dsl::lit_c<'}'>));
return key_condition >> dsl::terminator(dsl::semicolon)(dsl::p<expression>);
}();
static constexpr auto value = lexy::callback<ast_node_ptr>(
[](ast_node_ptr &&expr) { return std::make_unique<ast::expression_statement>(std::move(expr)); });
}; However, this matches the closing brace even in things like (for example) string literals. Is there any way to somehow skip the lookahead up until the expression itself has ended? |
Beta Was this translation helpful? Give feedback.
-
You can just use |
Beta Was this translation helpful? Give feedback.
You probably want
dsl::curly_bracketed.list(rule)
: https://lexy.foonathan.net/reference/dsl/brackets/#brackets