|
|
@@ -18,7 +18,7 @@ public:
|
|
|
private:
|
|
|
schema::Version version_;
|
|
|
std::unordered_map<std::string_view, MakeConstraint> make_;
|
|
|
- std::unordered_set<std::string_view> special_keywords_;
|
|
|
+ std::unordered_set<std::string_view> permitted_;
|
|
|
|
|
|
// TODO(samjaffe): Migrate this back to constraintsfactory
|
|
|
std::unordered_set<std::string_view> keywords_{"$defs",
|
|
|
@@ -49,14 +49,17 @@ private:
|
|
|
public:
|
|
|
Vocabulary() = default;
|
|
|
Vocabulary(schema::Version version, std::unordered_map<std::string_view, MakeConstraint> make)
|
|
|
- : version_(version), make_(std::move(make)) {}
|
|
|
+ : version_(version), make_(std::move(make)) {
|
|
|
+ for (auto const & [keyword, _] : make_) {
|
|
|
+ permitted_.emplace(keyword);
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
void restrict(std::unordered_set<std::string> const & permitted_keywords) & {
|
|
|
- for (auto it = make_.begin(); it != make_.end();) {
|
|
|
- if (permitted_keywords.contains(std::string(it->first))) {
|
|
|
- ++it;
|
|
|
- } else {
|
|
|
- it = make_.erase(it);
|
|
|
+ permitted_.clear();
|
|
|
+ for (auto const & [keyword, _] : make_) {
|
|
|
+ if (permitted_keywords.contains(std::string(keyword))) {
|
|
|
+ permitted_.insert(keyword);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
@@ -68,7 +71,7 @@ public:
|
|
|
* I expect to resolve a constraint out of it.
|
|
|
*/
|
|
|
bool is_keyword(std::string_view word) const {
|
|
|
- return make_.contains(word) && keywords_.contains(word);
|
|
|
+ return permitted_.contains(word) && make_.contains(word) && keywords_.contains(word);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -79,7 +82,9 @@ public:
|
|
|
return is_keyword(word) && property_keywords_.contains(word);
|
|
|
}
|
|
|
|
|
|
- bool is_constraint(std::string_view word) const { return make_.contains(word) && make_.at(word); }
|
|
|
+ bool is_constraint(std::string_view word) const {
|
|
|
+ return permitted_.contains(word) && make_.contains(word) && make_.at(word);
|
|
|
+ }
|
|
|
|
|
|
auto constraint(std::string_view word, ParserContext<A> const & context) const {
|
|
|
return std::make_pair(is_constraint(word) ? make_.at(word)(context) : nullptr,
|