Skip to content

Commit

Permalink
Merge branch 'hotfix/1.12.1'
Browse files Browse the repository at this point in the history
  • Loading branch information
danovaro committed Feb 9, 2025
2 parents c57d5ad + ad0a21c commit 2553b97
Show file tree
Hide file tree
Showing 5 changed files with 207 additions and 85 deletions.
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.12.0
1.12.1
19 changes: 11 additions & 8 deletions src/metkit/mars/MarsLanguage.cc
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,13 @@ MarsLanguage::MarsLanguage(const std::string& verb) : verb_(verb) {
}
}

if (lang.contains("_clear_defaults")) {
const auto& keywords = lang["_clear_defaults"];
for (auto i = 0; i < keywords.size(); ++i) {
if (auto iter = types_.find(keywords[i]); iter != types_.end()) { iter->second->clearDefaults(); }
}
}

std::set<std::string> keywordsInAxis;
for (const std::string& a : hypercube::AxisOrder::instance().axes()) {
keywordsInAxis.insert(a);
Expand All @@ -101,12 +108,10 @@ MarsLanguage::MarsLanguage(const std::string& verb) : verb_(verb) {
if(it != types_.end()) {
t = (*it).second;
}
typesByAxisOrder_.push_back(std::make_pair(a,t));
typesByAxisOrder_.emplace_back(a, t);
}
for (const auto& [k,t] : types_) {
if (keywordsInAxis.find(k) == keywordsInAxis.end()) {
typesByAxisOrder_.push_back(std::make_pair(k,t));
}
if (keywordsInAxis.find(k) == keywordsInAxis.end()) { typesByAxisOrder_.emplace_back(k, t); }
}
}

Expand Down Expand Up @@ -220,9 +225,7 @@ std::string MarsLanguage::bestMatch(const MarsExpandContext& ctx, const std::str

static std::string empty;
if (best.empty()) {
if (!fail) {
return empty;
}
if (!fail) { return empty; }

std::ostringstream oss;
oss << "Cannot match [" << name << "] in " << values << ctx;
Expand Down Expand Up @@ -250,7 +253,7 @@ std::string MarsLanguage::bestMatch(const MarsExpandContext& ctx, const std::str
if (!fail) {
return empty;
}

std::ostringstream oss;
oss << "Ambiguous value '" << name << "' could be";

Expand Down
18 changes: 14 additions & 4 deletions src/metkit/mars/Type.cc
Original file line number Diff line number Diff line change
Expand Up @@ -101,17 +101,26 @@ class Undef : public ContextRule {
public:
Undef(const std::string& k) : ContextRule(k) {}
bool matches(MarsRequest req) const override {
if (!req.has(key_)) {
return false;
}
return true;
return !req.has(key_);
}
private: // methods
void print(std::ostream& out) const override {
out << "Undef[key=" << key_ << "]";
}
};

class Def : public ContextRule {
public:
Def(const std::string& k) : ContextRule(k) {}
bool matches(MarsRequest req) const override {
return req.has(key_);
}
private: // methods
void print(std::ostream& out) const override {
out << "Def[key=" << key_ << "]";
}
};

ContextRule* parseRule(std::string key, eckit::Value r) {

std::set<std::string> vals;
Expand All @@ -128,6 +137,7 @@ ContextRule* parseRule(std::string key, eckit::Value r) {
ASSERT(op.size() == 1);
switch (op[0]) {
case 'u': return new Undef(key);
case 'd': return new Def(key);
case '!':
ASSERT(r.contains("vals"));
eckit::Value vv = r["vals"];
Expand Down
2 changes: 1 addition & 1 deletion src/tools/compare-mars-requests.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env python
#!/usr/bin/env python3

# (C) Copyright 1996- ECMWF.

Expand Down
Loading

0 comments on commit 2553b97

Please sign in to comment.