summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2023-03-10 16:08:35 (GMT)
committerKitware Robot <kwrobot@kitware.com>2023-03-10 16:08:52 (GMT)
commit46d5349e8fcfc3966f45b8b2ed586a59d3313eba (patch)
tree058b2e5ed233fe8d3605253c2764a4fa77e0bacf
parentd95ac61225bc216ba81342f82ec5d2903cdc0294 (diff)
parent8c52458a9ee52b296e0846392116485e8f0868ec (diff)
downloadCMake-46d5349e8fcfc3966f45b8b2ed586a59d3313eba.zip
CMake-46d5349e8fcfc3966f45b8b2ed586a59d3313eba.tar.gz
CMake-46d5349e8fcfc3966f45b8b2ed586a59d3313eba.tar.bz2
Merge topic 'help-signatures'
8c52458a9e cmRST: Fix cmake domain directives with newline before argument d4b21bcdd6 cmRST: Fix typo in comment 6a84717d17 cmRST: Convert enum types to enum class Acked-by: Kitware Robot <kwrobot@kitware.com> Acked-by: buildbot <buildbot@kitware.com> Merge-request: !8310
-rw-r--r--Source/cmRST.cxx63
-rw-r--r--Source/cmRST.h36
-rw-r--r--Tests/CMakeLib/testRST.expect15
-rw-r--r--Tests/CMakeLib/testRST.rst15
4 files changed, 70 insertions, 59 deletions
diff --git a/Source/cmRST.cxx b/Source/cmRST.cxx
index 71b77e0..5ff7009 100644
--- a/Source/cmRST.cxx
+++ b/Source/cmRST.cxx
@@ -21,7 +21,7 @@ cmRST::cmRST(std::ostream& os, std::string docroot)
, DocRoot(std::move(docroot))
, CMakeDirective("^.. (cmake:)?("
"command|envvar|genex|signature|variable"
- ")::[ \t]+([^ \t\n]+)$")
+ ")::")
, CMakeModuleDirective("^.. cmake-module::[ \t]+([^ \t\n]+)$")
, ParsedLiteralDirective("^.. parsed-literal::[ \t]*(.*)$")
, CodeBlockDirective("^.. code-block::[ \t]*(.*)$")
@@ -126,27 +126,27 @@ void cmRST::Reset()
if (!this->MarkupLines.empty()) {
cmRST::UnindentLines(this->MarkupLines);
}
- switch (this->Directive) {
- case DirectiveNone:
+ switch (this->DirectiveType) {
+ case Directive::None:
break;
- case DirectiveParsedLiteral:
+ case Directive::ParsedLiteral:
this->ProcessDirectiveParsedLiteral();
break;
- case DirectiveLiteralBlock:
+ case Directive::LiteralBlock:
this->ProcessDirectiveLiteralBlock();
break;
- case DirectiveCodeBlock:
+ case Directive::CodeBlock:
this->ProcessDirectiveCodeBlock();
break;
- case DirectiveReplace:
+ case Directive::Replace:
this->ProcessDirectiveReplace();
break;
- case DirectiveTocTree:
+ case Directive::TocTree:
this->ProcessDirectiveTocTree();
break;
}
- this->Markup = MarkupNone;
- this->Directive = DirectiveNone;
+ this->MarkupType = Markup::None;
+ this->DirectiveType = Directive::None;
this->MarkupLines.clear();
}
@@ -160,9 +160,9 @@ void cmRST::ProcessLine(std::string const& line)
(line.size() >= 3 && line[0] == '.' && line[1] == '.' &&
isspace(line[2]))) {
this->Reset();
- this->Markup =
- (line.find_first_not_of(" \t", 2) == std::string::npos ? MarkupEmpty
- : MarkupNormal);
+ this->MarkupType =
+ (line.find_first_not_of(" \t", 2) == std::string::npos ? Markup::Empty
+ : Markup::Normal);
// XXX(clang-tidy): https://bugs.llvm.org/show_bug.cgi?id=44165
// NOLINTNEXTLINE(bugprone-branch-clone)
if (this->CMakeDirective.find(line)) {
@@ -171,33 +171,33 @@ void cmRST::ProcessLine(std::string const& line)
} else if (this->CMakeModuleDirective.find(line)) {
// Process cmake-module directive: scan .cmake file comments.
std::string file = this->CMakeModuleDirective.match(1);
- if (file.empty() || !this->ProcessInclude(file, IncludeModule)) {
+ if (file.empty() || !this->ProcessInclude(file, Include::Module)) {
this->NormalLine(line);
}
} else if (this->ParsedLiteralDirective.find(line)) {
// Record the literal lines to output after whole block.
- this->Directive = DirectiveParsedLiteral;
+ this->DirectiveType = Directive::ParsedLiteral;
this->MarkupLines.push_back(this->ParsedLiteralDirective.match(1));
} else if (this->CodeBlockDirective.find(line)) {
// Record the literal lines to output after whole block.
// Ignore the language spec and record the opening line as blank.
- this->Directive = DirectiveCodeBlock;
+ this->DirectiveType = Directive::CodeBlock;
this->MarkupLines.emplace_back();
} else if (this->ReplaceDirective.find(line)) {
// Record the replace directive content.
- this->Directive = DirectiveReplace;
+ this->DirectiveType = Directive::Replace;
this->ReplaceName = this->ReplaceDirective.match(1);
this->MarkupLines.push_back(this->ReplaceDirective.match(2));
} else if (this->IncludeDirective.find(line)) {
// Process the include directive or output the directive and its
// content normally if it fails.
std::string file = this->IncludeDirective.match(1);
- if (file.empty() || !this->ProcessInclude(file, IncludeNormal)) {
+ if (file.empty() || !this->ProcessInclude(file, Include::Normal)) {
this->NormalLine(line);
}
} else if (this->TocTreeDirective.find(line)) {
// Record the toctree entries to process after whole block.
- this->Directive = DirectiveTocTree;
+ this->DirectiveType = Directive::TocTree;
this->MarkupLines.push_back(this->TocTreeDirective.match(1));
} else if (this->ProductionListDirective.find(line)) {
// Output productionlist directives and their content normally.
@@ -211,14 +211,15 @@ void cmRST::ProcessLine(std::string const& line)
this->NormalLine(line);
}
}
- // An explicit markup start followed nothing but whitespace and a
+ // An explicit markup start followed by nothing but whitespace and a
// blank line does not consume any indented text following.
- else if (this->Markup == MarkupEmpty && line.empty()) {
+ else if (this->MarkupType == Markup::Empty && line.empty()) {
this->NormalLine(line);
}
// Indented lines following an explicit markup start are explicit markup.
- else if (this->Markup && (line.empty() || isspace(line[0]))) {
- this->Markup = MarkupNormal;
+ else if (this->MarkupType != Markup::None &&
+ (line.empty() || isspace(line[0]))) {
+ this->MarkupType = Markup::Normal;
// Record markup lines if the start line was recorded.
if (!this->MarkupLines.empty()) {
this->MarkupLines.push_back(line);
@@ -227,8 +228,8 @@ void cmRST::ProcessLine(std::string const& line)
// A blank line following a paragraph ending in "::" starts a literal block.
else if (lastLineEndedInColonColon && line.empty()) {
// Record the literal lines to output after whole block.
- this->Markup = MarkupNormal;
- this->Directive = DirectiveLiteralBlock;
+ this->MarkupType = Markup::Normal;
+ this->DirectiveType = Directive::LiteralBlock;
this->MarkupLines.emplace_back();
this->OutputLine("", false);
}
@@ -354,14 +355,14 @@ void cmRST::OutputMarkupLines(bool inlineMarkup)
this->OutputLinePending = true;
}
-bool cmRST::ProcessInclude(std::string file, IncludeType type)
+bool cmRST::ProcessInclude(std::string file, Include type)
{
bool found = false;
if (this->IncludeDepth < 10) {
cmRST r(this->OS, this->DocRoot);
r.IncludeDepth = this->IncludeDepth + 1;
r.OutputLinePending = this->OutputLinePending;
- if (type != IncludeTocTree) {
+ if (type != Include::TocTree) {
r.Replace = this->Replace;
}
if (file[0] == '/') {
@@ -369,8 +370,8 @@ bool cmRST::ProcessInclude(std::string file, IncludeType type)
} else {
file = this->DocDir + "/" + file;
}
- found = r.ProcessFile(file, type == IncludeModule);
- if (type != IncludeTocTree) {
+ found = r.ProcessFile(file, type == Include::Module);
+ if (type != Include::TocTree) {
this->Replace = r.Replace;
}
this->OutputLinePending = r.OutputLinePending;
@@ -408,9 +409,9 @@ void cmRST::ProcessDirectiveTocTree()
if (!line.empty() && line[0] != ':') {
if (this->TocTreeLink.find(line)) {
std::string const& link = this->TocTreeLink.match(1);
- this->ProcessInclude(link + ".rst", IncludeTocTree);
+ this->ProcessInclude(link + ".rst", Include::TocTree);
} else {
- this->ProcessInclude(line + ".rst", IncludeTocTree);
+ this->ProcessInclude(line + ".rst", Include::TocTree);
}
}
}
diff --git a/Source/cmRST.h b/Source/cmRST.h
index ea4ef22..65a8a71 100644
--- a/Source/cmRST.h
+++ b/Source/cmRST.h
@@ -29,26 +29,26 @@ public:
bool ProcessFile(std::string const& fname, bool isModule = false);
private:
- enum IncludeType
+ enum class Include
{
- IncludeNormal,
- IncludeModule,
- IncludeTocTree
+ Normal,
+ Module,
+ TocTree
};
- enum MarkupType
+ enum class Markup
{
- MarkupNone,
- MarkupNormal,
- MarkupEmpty
+ None,
+ Normal,
+ Empty
};
- enum DirectiveType
+ enum class Directive
{
- DirectiveNone,
- DirectiveParsedLiteral,
- DirectiveLiteralBlock,
- DirectiveCodeBlock,
- DirectiveReplace,
- DirectiveTocTree
+ None,
+ ParsedLiteral,
+ LiteralBlock,
+ CodeBlock,
+ Replace,
+ TocTree
};
void ProcessRST(std::istream& is);
@@ -59,7 +59,7 @@ private:
void OutputLine(std::string const& line, bool inlineMarkup);
std::string ReplaceSubstitutions(std::string const& line);
void OutputMarkupLines(bool inlineMarkup);
- bool ProcessInclude(std::string file, IncludeType type);
+ bool ProcessInclude(std::string file, Include type);
void ProcessDirectiveParsedLiteral();
void ProcessDirectiveLiteralBlock();
void ProcessDirectiveCodeBlock();
@@ -72,8 +72,8 @@ private:
int IncludeDepth = 0;
bool OutputLinePending = false;
bool LastLineEndedInColonColon = false;
- MarkupType Markup = MarkupNone;
- DirectiveType Directive = DirectiveNone;
+ Markup MarkupType = Markup::None;
+ Directive DirectiveType = Directive::None;
cmsys::RegularExpression CMakeDirective;
cmsys::RegularExpression CMakeModuleDirective;
cmsys::RegularExpression ParsedLiteralDirective;
diff --git a/Tests/CMakeLib/testRST.expect b/Tests/CMakeLib/testRST.expect
index 076562a..483e220 100644
--- a/Tests/CMakeLib/testRST.expect
+++ b/Tests/CMakeLib/testRST.expect
@@ -46,7 +46,8 @@ Bracket Comment Content
Bracket Comment Content
]
-.. cmake:command:: some_cmd
+.. cmake:command::
+ some_cmd
Command some_cmd description.
@@ -54,7 +55,8 @@ Bracket Comment Content
Command other_cmd description.
-.. cmake:envvar:: some_var
+.. cmake:envvar::
+ some_var
Environment variable some_var description.
@@ -62,7 +64,8 @@ Bracket Comment Content
Environment variable other_var description.
-.. cmake:genex:: SOME_GENEX
+.. cmake:genex::
+ SOME_GENEX
Generator expression SOME_GENEX description.
@@ -70,7 +73,8 @@ Bracket Comment Content
Generator expression $<OTHER_GENEX> description.
-.. cmake:signature:: some_command(SOME_SIGNATURE)
+.. cmake:signature::
+ some_command(SOME_SIGNATURE)
Command some_command SOME_SIGNATURE description.
@@ -78,7 +82,8 @@ Bracket Comment Content
Command other_command OTHER_SIGNATURE description.
-.. cmake:variable:: some_var
+.. cmake:variable::
+ some_var
Variable some_var description.
diff --git a/Tests/CMakeLib/testRST.rst b/Tests/CMakeLib/testRST.rst
index 43b08da..c23b69a 100644
--- a/Tests/CMakeLib/testRST.rst
+++ b/Tests/CMakeLib/testRST.rst
@@ -49,7 +49,8 @@ Inline literal ``__`` followed by inline link `Link Text <InternalDest_>`_.
.. cmake-module:: testRSTmod.cmake
-.. cmake:command:: some_cmd
+.. cmake:command::
+ some_cmd
Command some_cmd description.
@@ -57,7 +58,8 @@ Inline literal ``__`` followed by inline link `Link Text <InternalDest_>`_.
Command other_cmd description.
-.. cmake:envvar:: some_var
+.. cmake:envvar::
+ some_var
Environment variable some_var description.
@@ -65,7 +67,8 @@ Inline literal ``__`` followed by inline link `Link Text <InternalDest_>`_.
Environment variable other_var description.
-.. cmake:genex:: SOME_GENEX
+.. cmake:genex::
+ SOME_GENEX
Generator expression SOME_GENEX description.
@@ -73,7 +76,8 @@ Inline literal ``__`` followed by inline link `Link Text <InternalDest_>`_.
Generator expression $<OTHER_GENEX> description.
-.. cmake:signature:: some_command(SOME_SIGNATURE)
+.. cmake:signature::
+ some_command(SOME_SIGNATURE)
Command some_command SOME_SIGNATURE description.
@@ -81,7 +85,8 @@ Inline literal ``__`` followed by inline link `Link Text <InternalDest_>`_.
Command other_command OTHER_SIGNATURE description.
-.. cmake:variable:: some_var
+.. cmake:variable::
+ some_var
Variable some_var description.