1
0
mirror of https://github.com/TomHarte/CLK.git synced 2024-11-25 16:31:42 +00:00

Fix composition with empty nodes.

This commit is contained in:
Thomas Harte 2021-06-19 22:13:17 -04:00
parent 23e26e0333
commit 42a98e1676
2 changed files with 13 additions and 2 deletions

View File

@ -27,8 +27,15 @@ Request::Request(Name name, bool optional) {
}
Request Request::append(Node::Type type, const Request &rhs) {
// Start with the easiest case: this is already an appropriate
// request, and so is the new thing.
// If either side is empty, act appropriately.
if(node.empty() && !rhs.node.empty()) {
return rhs;
}
if(rhs.node.empty()) {
return *this;
}
// Just copy in the RHS child nodes if types match.
if(node.type == type && rhs.node.type == type) {
Request new_request = *this;
new_request.node.children.insert(new_request.node.children.end(), rhs.node.children.begin(), rhs.node.children.end());

View File

@ -240,6 +240,10 @@ struct Request {
bool is_optional = false;
std::vector<Node> children;
bool empty() const {
return type == Type::One && name == Name::None;
}
void add_descriptions(std::vector<Description> &) const;
bool validate(Map &) const;
void visit(