Overview of How CMinx Works¶
In CMinx parsing of a source file is the role of the Antlr4 parsing runtime, generated from the modified CMake.g4 grammar file.
- As per the standard usage, the file contents are read into an Antlr4 FileStream, which is then passed to the generated CMake lexer.
- The lexer generates a token stream, which is then fed into the CMakeParser.
- The parser generates a tree of parse elements, called contexts, which are then walked over by the ParseTreeWalker.
This process is diagrammatically summarized in Fig. 1.
After the parser generates the parse tree, CMinx walks the tree and aggregates the various documentation.
- The walker calls the aggregator methods upon entering or exiting
parse rules, such as entering a
- The parse rule enterDocumented_command cleans the doccomment and
extracts the documented command. For example, if a function definition
is documented, enterDocumented_command will extract the
- The aggregator then locates the subprocessor that corresponds to the extracted command,
for example if the extracted command is
functionthen the subprocessor would be
process_function(). This subhandler is then executed with the parse context and cleaned docstring.
- The documentation aggregator subhandler generates NamedTuples representing the type of documentation generated, such as FunctionDocumentation, complete with all relevant information, and adds them to a documented list.
- From there, Documenter loops over the documentation list, generating equivalent RST via RSTWriter for each type of documentation.
This process is diagrammatically summarized in Fig. 2.