Remove use of shared_ptr in choice, repeat, and seq factories
This commit is contained in:
parent
d9fb863bea
commit
b3edd8f749
34 changed files with 366 additions and 381 deletions
|
|
@ -8,28 +8,6 @@ Seq::Seq(const Rule &left, const Rule &right) :
|
|||
left(std::make_shared<Rule>(left)),
|
||||
right(std::make_shared<Rule>(right)) {}
|
||||
|
||||
std::shared_ptr<Rule> Seq::build(const std::vector<Rule> &rules) {
|
||||
Rule result;
|
||||
for (const auto &rule : rules) {
|
||||
rule.match(
|
||||
[](Blank) {},
|
||||
[&](Metadata metadata) {
|
||||
if (!metadata.rule->is<Blank>()) {
|
||||
result = Seq{result, rule};
|
||||
}
|
||||
},
|
||||
[&](auto) {
|
||||
if (result.is<Blank>()) {
|
||||
result = rule;
|
||||
} else {
|
||||
result = Seq{result, rule};
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
return std::make_shared<Rule>(result);
|
||||
}
|
||||
|
||||
bool Seq::operator==(const Seq &other) const {
|
||||
return left->operator==(*other.left) && right->operator==(*other.right);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue