mirror of
https://github.com/TomHarte/CLK.git
synced 2024-11-29 12:50:28 +00:00
Attempts to implement tree construction.
This commit is contained in:
parent
f4db4c3a73
commit
2e999889bd
@ -18,14 +18,29 @@ Request::Request(Name name, bool optional) {
|
|||||||
node.is_optional = optional;
|
node.is_optional = optional;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Request Request::append(Node::Type type, const Request &rhs) {
|
||||||
|
// Start with the easiest case: this is already an ::All request, and
|
||||||
|
// so is the new thing.
|
||||||
|
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());
|
||||||
|
return new_request;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Otherwise create a new parent node.
|
||||||
|
Request parent;
|
||||||
|
parent.node.type = type;
|
||||||
|
parent.node.children.push_back(this->node);
|
||||||
|
parent.node.children.push_back(rhs.node);
|
||||||
|
return parent;
|
||||||
|
}
|
||||||
|
|
||||||
Request Request::operator &&(const Request &rhs) {
|
Request Request::operator &&(const Request &rhs) {
|
||||||
(void)rhs;
|
return append(Node::Type::All, rhs);
|
||||||
return *this;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Request Request::operator ||(const Request &rhs) {
|
Request Request::operator ||(const Request &rhs) {
|
||||||
(void)rhs;
|
return append(Node::Type::Any, rhs);
|
||||||
return *this;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Request::validate(Map &map) const {
|
bool Request::validate(Map &map) const {
|
||||||
|
@ -179,6 +179,8 @@ struct Request {
|
|||||||
bool validate(Map &) const;
|
bool validate(Map &) const;
|
||||||
};
|
};
|
||||||
Node node;
|
Node node;
|
||||||
|
|
||||||
|
Request append(Node::Type type, const Request &rhs);
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user