cmRST.h 2.8 KB

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