/src/CMake/Source/cmRST.h
Line | Count | Source |
1 | | /* Distributed under the OSI-approved BSD 3-Clause License. See accompanying |
2 | | file LICENSE.rst or https://cmake.org/licensing for details. */ |
3 | | #pragma once |
4 | | |
5 | | #include "cmConfigure.h" // IWYU pragma: keep |
6 | | |
7 | | #include <cstddef> |
8 | | #include <iosfwd> |
9 | | #include <map> |
10 | | #include <set> |
11 | | #include <string> |
12 | | #include <utility> |
13 | | #include <vector> |
14 | | |
15 | | #include "cmsys/RegularExpression.hxx" |
16 | | |
17 | | /** \class cmRST |
18 | | * \brief Perform basic .rst processing for command-line help |
19 | | * |
20 | | * This class implements a subset of reStructuredText and Sphinx |
21 | | * document processing. It is used to print command-line help. |
22 | | * |
23 | | * If you modify the capabilities of this class, be sure to update |
24 | | * the Help/manual/cmake-developer.7.rst documentation and to update |
25 | | * the Tests/CMakeLib/testRST.(rst|expect) test input and output. |
26 | | */ |
27 | | class cmRST |
28 | | { |
29 | | public: |
30 | | cmRST(std::string docroot); |
31 | | bool ProcessFile(std::string const& fname, bool isModule = false); |
32 | | void Write(std::ostream& os); |
33 | | |
34 | | private: |
35 | | enum class Include |
36 | | { |
37 | | Normal, |
38 | | Module, |
39 | | TocTree |
40 | | }; |
41 | | enum class Markup |
42 | | { |
43 | | None, |
44 | | Normal, |
45 | | Empty |
46 | | }; |
47 | | enum class Directive |
48 | | { |
49 | | None, |
50 | | ParsedLiteral, |
51 | | LiteralBlock, |
52 | | CodeBlock, |
53 | | Replace, |
54 | | TocTree |
55 | | }; |
56 | | |
57 | | struct ContentLine |
58 | | { |
59 | | ContentLine() = default; |
60 | | ContentLine(std::string l, size_t c, bool m) |
61 | 0 | : Content{ std::move(l) } |
62 | 0 | , Context{ c } |
63 | 0 | , InlineMarkup{ m } |
64 | 0 | { |
65 | 0 | } |
66 | | |
67 | | std::string Content; |
68 | | size_t Context; |
69 | | bool InlineMarkup; |
70 | | }; |
71 | | |
72 | | void ProcessRST(std::istream& is); |
73 | | void ProcessModule(std::istream& is); |
74 | | void Reset(); |
75 | | void ProcessLine(std::string const& line); |
76 | | void NormalLine(std::string const& line); |
77 | | void OutputLine(std::string const& line, bool inlineMarkup); |
78 | | void WriteLine(std::ostream& os, ContentLine const& content); |
79 | | std::string ReplaceSubstitutions(std::string const& line, size_t context); |
80 | | void OutputMarkupLines(bool inlineMarkup); |
81 | | bool ProcessInclude(std::string file, Include type); |
82 | | void ProcessDirectiveParsedLiteral(); |
83 | | void ProcessDirectiveLiteralBlock(); |
84 | | void ProcessDirectiveCodeBlock(); |
85 | | void ProcessDirectiveReplace(); |
86 | | void ProcessDirectiveTocTree(); |
87 | | static void UnindentLines(std::vector<std::string>& lines); |
88 | | |
89 | | std::string DocRoot; |
90 | | int IncludeDepth = 0; |
91 | | size_t ContextOffset = 0; |
92 | | bool OutputLinePending = false; |
93 | | bool LastLineEndedInColonColon = false; |
94 | | Markup MarkupType = Markup::None; |
95 | | Directive DirectiveType = Directive::None; |
96 | | cmsys::RegularExpression CMakeDirective; |
97 | | cmsys::RegularExpression CMakeModuleDirective; |
98 | | cmsys::RegularExpression ParsedLiteralDirective; |
99 | | cmsys::RegularExpression CodeBlockDirective; |
100 | | cmsys::RegularExpression ReplaceDirective; |
101 | | cmsys::RegularExpression IncludeDirective; |
102 | | cmsys::RegularExpression TocTreeDirective; |
103 | | cmsys::RegularExpression ProductionListDirective; |
104 | | cmsys::RegularExpression NoteDirective; |
105 | | cmsys::RegularExpression VersionDirective; |
106 | | cmsys::RegularExpression ModuleRST; |
107 | | cmsys::RegularExpression CMakeRole; |
108 | | cmsys::RegularExpression InlineLink; |
109 | | cmsys::RegularExpression InlineLiteral; |
110 | | cmsys::RegularExpression Substitution; |
111 | | cmsys::RegularExpression TocTreeLink; |
112 | | cmsys::RegularExpression Header; |
113 | | |
114 | | std::string::size_type LastLength; |
115 | | std::vector<std::string> MarkupLines; |
116 | | std::vector<ContentLine> OutputLines; |
117 | | std::string DocDir; |
118 | | std::vector<std::map<std::string, std::string>> Replace; |
119 | | std::set<std::string> Replaced; |
120 | | std::string ReplaceName; |
121 | | }; |