Skip to content

static_assert failed: 'choice requires a branch condition' #223

Answered by foonathan
totalgee asked this question in Q&A
Discussion options

You must be logged in to vote

As you realized, the issue is with choice. A choice requires a branch rule, but a plain sequence with + is not a branch. You need to specify which part of the sequence is being used as the condition with >>. The condition is the part that is being checked to determine whether the branch should of the choice should be taken, and then is potentially backtracked if it does not match. You probably want to use the keyword as condition:

struct cmd_A {
    static constexpr auto rule = dsl::keyword<"A">(identifier) >> dsl::p<argument> + dsl::eof;
    static constexpr auto value = lexy::construct<CmdA>;
};

struct cmd_B {
    static constexpr auto rule = dsl::keyword<"B">(identifier) >> dsl::p<arg…

Replies: 7 comments 1 reply

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Answer selected by foonathan
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
1 reply
@foonathan
Comment options

Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants
Converted from issue

This discussion was converted from issue #222 on January 27, 2025 19:50.