add a way to conditionally use rules according to predicate
parent
0915a9e6b5
commit
6845f5a8d8
|
@ -118,6 +118,18 @@ struct make_rule {
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
make_rule &cond(std::function<bool(string_range)> cond_f) noexcept {
|
||||||
|
p_cond = std::move(cond_f);
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool cond(string_range target) const {
|
||||||
|
if (!p_cond) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return p_cond(target);
|
||||||
|
}
|
||||||
|
|
||||||
iterator_range<std::string const *> depends() const noexcept {
|
iterator_range<std::string const *> depends() const noexcept {
|
||||||
return iterator_range<std::string const *>(
|
return iterator_range<std::string const *>(
|
||||||
p_deps.data(), p_deps.data() + p_deps.size()
|
p_deps.data(), p_deps.data() + p_deps.size()
|
||||||
|
@ -159,6 +171,7 @@ private:
|
||||||
make_pattern p_target;
|
make_pattern p_target;
|
||||||
std::vector<std::string> p_deps{};
|
std::vector<std::string> p_deps{};
|
||||||
body_func p_body{};
|
body_func p_body{};
|
||||||
|
std::function<bool(string_range)> p_cond{};
|
||||||
bool p_action = false;
|
bool p_action = false;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -176,6 +176,9 @@ void make::find_rules(string_range target, std::vector<rule_inst> &rlist) {
|
||||||
rule_inst *frule = nullptr;
|
rule_inst *frule = nullptr;
|
||||||
std::size_t pfnl = 0, psubl = 0;
|
std::size_t pfnl = 0, psubl = 0;
|
||||||
for (auto &rule: p_rules) {
|
for (auto &rule: p_rules) {
|
||||||
|
if (!rule.cond(target)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
auto &tgt = rule.target();
|
auto &tgt = rule.target();
|
||||||
auto [fnl, subl] = tgt.match(target);
|
auto [fnl, subl] = tgt.match(target);
|
||||||
if ((fnl + subl) > 0) {
|
if ((fnl + subl) > 0) {
|
||||||
|
|
Loading…
Reference in New Issue