resolve cyclic dependency with zstd
[platform/upstream/cmake.git] / Source / cmRST.h
1 /* Distributed under the OSI-approved BSD 3-Clause License.  See accompanying
2    file Copyright.txt or https://cmake.org/licensing for details.  */
3 #pragma once
4
5 #include "cmConfigure.h" // IWYU pragma: keep
6
7 #include <iosfwd>
8 #include <map>
9 #include <set>
10 #include <string>
11 #include <vector>
12
13 #include "cmsys/RegularExpression.hxx"
14
15 /** \class cmRST
16  * \brief Perform basic .rst processing for command-line help
17  *
18  * This class implements a subset of reStructuredText and Sphinx
19  * document processing.  It is used to print command-line help.
20  *
21  * If you modify the capabilities of this class, be sure to update
22  * the Help/manual/cmake-developer.7.rst documentation and to update
23  * the Tests/CMakeLib/testRST.(rst|expect) test input and output.
24  */
25 class cmRST
26 {
27 public:
28   cmRST(std::ostream& os, std::string docroot);
29   bool ProcessFile(std::string const& fname, bool isModule = false);
30
31 private:
32   enum IncludeType
33   {
34     IncludeNormal,
35     IncludeModule,
36     IncludeTocTree
37   };
38   enum MarkupType
39   {
40     MarkupNone,
41     MarkupNormal,
42     MarkupEmpty
43   };
44   enum DirectiveType
45   {
46     DirectiveNone,
47     DirectiveParsedLiteral,
48     DirectiveLiteralBlock,
49     DirectiveCodeBlock,
50     DirectiveReplace,
51     DirectiveTocTree
52   };
53
54   void ProcessRST(std::istream& is);
55   void ProcessModule(std::istream& is);
56   void Reset();
57   void ProcessLine(std::string const& line);
58   void NormalLine(std::string const& line);
59   void OutputLine(std::string const& line, bool inlineMarkup);
60   std::string ReplaceSubstitutions(std::string const& line);
61   void OutputMarkupLines(bool inlineMarkup);
62   bool ProcessInclude(std::string file, IncludeType type);
63   void ProcessDirectiveParsedLiteral();
64   void ProcessDirectiveLiteralBlock();
65   void ProcessDirectiveCodeBlock();
66   void ProcessDirectiveReplace();
67   void ProcessDirectiveTocTree();
68   static void UnindentLines(std::vector<std::string>& lines);
69
70   std::ostream& OS;
71   std::string DocRoot;
72   int IncludeDepth = 0;
73   bool OutputLinePending = false;
74   bool LastLineEndedInColonColon = false;
75   MarkupType Markup = MarkupNone;
76   DirectiveType Directive = DirectiveNone;
77   cmsys::RegularExpression CMakeDirective;
78   cmsys::RegularExpression CMakeModuleDirective;
79   cmsys::RegularExpression ParsedLiteralDirective;
80   cmsys::RegularExpression CodeBlockDirective;
81   cmsys::RegularExpression ReplaceDirective;
82   cmsys::RegularExpression IncludeDirective;
83   cmsys::RegularExpression TocTreeDirective;
84   cmsys::RegularExpression ProductionListDirective;
85   cmsys::RegularExpression NoteDirective;
86   cmsys::RegularExpression VersionDirective;
87   cmsys::RegularExpression ModuleRST;
88   cmsys::RegularExpression CMakeRole;
89   cmsys::RegularExpression InlineLink;
90   cmsys::RegularExpression InlineLiteral;
91   cmsys::RegularExpression Substitution;
92   cmsys::RegularExpression TocTreeLink;
93
94   std::vector<std::string> MarkupLines;
95   std::string DocDir;
96   std::map<std::string, std::string> Replace;
97   std::set<std::string> Replaced;
98   std::string ReplaceName;
99 };