Header lexy/dsl/if.hpp
Rule lexy::dsl::if_
lexy/dsl/if.hpp
namespace lexy::dsl
{
constexpr rule auto if_(branch-rule auto branch);
}
if_
is a rule that tries to parse a branch rule.
- Parsing
Tries to parse
branch
. If that backtracks, succeeds without consuming anything.- Errors
All errors raised by
branch
during branch parsing. The rule then fails ifbranch
has failed.- Values
All values produced by
branch
.
Example 1. Only parse a fraction if preceded by a dot
Note | if_(branch) is functionally equivalent to the choice branch | lexy::dsl::else_ . |
Tip | Use lexy::dsl::opt if you need a value to indicate that branch was not parsed. |