From 90d1aec2f2dbec1f9a5eb8a8988f0a39c0505093 Mon Sep 17 00:00:00 2001 From: Celtic Minstrel Date: Sun, 18 Nov 2018 00:41:42 -0500 Subject: [PATCH] Fix schema validator ignoring toplevel keys --- src/serialization/parser.cpp | 10 ++++++++++ src/serialization/schema_validator.cpp | 4 +++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/serialization/parser.cpp b/src/serialization/parser.cpp index a464d84de18..e830a1ac4e5 100644 --- a/src/serialization/parser.cpp +++ b/src/serialization/parser.cpp @@ -125,6 +125,10 @@ void parser::operator()() cfg_.clear(); elements.emplace(&cfg_, ""); + if(validator_) { + validator_->open_tag("", cfg_, tok_.get_start_line(), tok_.get_file()); + } + do { tok_.next_token(); @@ -163,6 +167,12 @@ void parser::operator()() // The main element should be there. If it is not, this is a parser error. assert(!elements.empty()); + if(validator_) { + element& el = elements.top(); + validator_->validate(*el.cfg, el.name, el.start_line, el.file); + validator_->close_tag(); + } + if(elements.size() != 1) { utils::string_map i18n_symbols; i18n_symbols["tag"] = elements.top().name; diff --git a/src/serialization/schema_validator.cpp b/src/serialization/schema_validator.cpp index 74ad4808e4c..3108ea66e47 100644 --- a/src/serialization/schema_validator.cpp +++ b/src/serialization/schema_validator.cpp @@ -205,7 +205,9 @@ bool schema_validator::read_config_file(const std::string& filename) */ void schema_validator::open_tag(const std::string& name, const config& parent, int start_line, const std::string& file, bool addittion) { - if(!stack_.empty()) { + if(name.empty()) { + // Opened the root tag; nothing special to do here + } else if(!stack_.empty()) { const wml_tag* tag = nullptr; if(stack_.top()) {