summaryrefslogtreecommitdiffstats
path: root/Source
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2022-07-18 20:54:13 (GMT)
committerBrad King <brad.king@kitware.com>2022-07-22 14:32:24 (GMT)
commitb7c82b26b03349d1201a24acbe198ee1bd00ee3e (patch)
tree6577eb58da3df4768de67e08cdd994ea29bcfca3 /Source
parent50876f6b9afbf638fcc86ebfa83de7cc17a5a7e1 (diff)
downloadCMake-b7c82b26b03349d1201a24acbe198ee1bd00ee3e.zip
CMake-b7c82b26b03349d1201a24acbe198ee1bd00ee3e.tar.gz
CMake-b7c82b26b03349d1201a24acbe198ee1bd00ee3e.tar.bz2
cmArgumentParser: Capture keyword errors in parse results
Since commit f46b2e9142 (cmArgumentParser: Model maybe-missing string with wrapper type, 2022-07-06) we know during parsing whether or not it is an error for a keyword to be missing a value. Record such errors in the parse results structure. Offer clients a helper method to report them. This provides clients with an alternative to manually checking `keywordsMissingValue` and generating their own error message.
Diffstat (limited to 'Source')
-rw-r--r--Source/cmArgumentParser.cxx20
-rw-r--r--Source/cmArgumentParser.h20
2 files changed, 39 insertions, 1 deletions
diff --git a/Source/cmArgumentParser.cxx b/Source/cmArgumentParser.cxx
index c997933..25d5c68 100644
--- a/Source/cmArgumentParser.cxx
+++ b/Source/cmArgumentParser.cxx
@@ -5,6 +5,9 @@
#include <algorithm>
#include "cmArgumentParserTypes.h"
+#include "cmMakefile.h"
+#include "cmMessageType.h"
+#include "cmStringAlgorithms.h"
namespace ArgumentParser {
@@ -106,10 +109,27 @@ void Instance::FinishKeyword()
return;
}
if (this->ExpectValue) {
+ if (this->ParseResults != nullptr) {
+ this->ParseResults->AddKeywordError(this->Keyword,
+ " missing required value\n");
+ }
if (this->KeywordsMissingValue != nullptr) {
this->KeywordsMissingValue->emplace_back(this->Keyword);
}
}
}
+bool ParseResult::MaybeReportError(cmMakefile& mf) const
+{
+ if (*this) {
+ return false;
+ }
+ std::string e;
+ for (auto const& ke : this->KeywordErrors) {
+ e = cmStrCat(e, "Error after keyword \"", ke.first, "\":\n", ke.second);
+ }
+ mf.IssueMessage(MessageType::FATAL_ERROR, e);
+ return true;
+}
+
} // namespace ArgumentParser
diff --git a/Source/cmArgumentParser.h b/Source/cmArgumentParser.h
index 0078c04..8fda8b7 100644
--- a/Source/cmArgumentParser.h
+++ b/Source/cmArgumentParser.h
@@ -6,6 +6,7 @@
#include <cassert>
#include <functional>
+#include <map>
#include <string>
#include <utility>
#include <vector>
@@ -20,12 +21,29 @@
template <typename Result>
class cmArgumentParser; // IWYU pragma: keep
+class cmMakefile;
+
namespace ArgumentParser {
class ParseResult
{
+ std::map<cm::string_view, std::string> KeywordErrors;
+
public:
- explicit operator bool() const { return true; }
+ explicit operator bool() const { return this->KeywordErrors.empty(); }
+
+ void AddKeywordError(cm::string_view key, cm::string_view text)
+
+ {
+ this->KeywordErrors[key] += text;
+ }
+
+ std::map<cm::string_view, std::string> const& GetKeywordErrors() const
+ {
+ return this->KeywordErrors;
+ }
+
+ bool MaybeReportError(cmMakefile& mf) const;
};
template <typename Result>