Capturing nested comments #155
-
Goals
Code so farstruct comment {
struct multiline {
static constexpr
auto rule = capture(token(
dsl::brackets(LEXY_LIT("/*"), LEXY_LIT("*/"))
.list((peek(LEXY_LIT("/*"))
>> dsl::recurse_branch<multiline>)
| dsl::code_point)))
;
static constexpr
auto value = ::lexy::as_string<std::string>;
};
static constexpr
auto rule =
capture(token(
LEXY_LIT("//") >> identifier(dsl::code_point - dsl::ascii::newline)
))
| dsl::p<multiline>
;
static constexpr
auto value = ::lexy::as_string<std::string>;
}; Problems:The code above produces the following error at runtime:
Attempted:
|
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 4 replies
-
Your issue is that you use You can avoid that by using the second overload of Note that |
Beta Was this translation helpful? Give feedback.
Your issue is that you use
dsl::token
inside thedsl::capture
. You can then no longer use recursion at all for technical reasons.You can avoid that by using the second overload of
dsl::capture
which takes a token production: https://lexy.foonathan.net/playground/?id=5oeabd1ob&mode=treeNote that
multiline
andsingle
do not produce values on their own, only the final comment will produce a span that contains the entire comment. I'm assuming this is the semantic you wanted? I'm not sure how you want to capture nested comments otherwise.