|
| 1 | +Analyse |
| 2 | +======= |
| 3 | + |
| 4 | +The ``Analyse`` is a :ref:`CLI tool <cli>` that also provides an API for programmatic use. Its primary function is to extract specific, marked content from comments within source code files. |
| 5 | + |
| 6 | +It can extract three types of content: |
| 7 | + |
| 8 | +- Sphinx-Needs ID References |
| 9 | +- Oneline needs (see :ref:`OneLineCommentStyle <oneline>`) |
| 10 | +- Marked reStructuredText (RST) blocks |
| 11 | + |
| 12 | +Configuration |
| 13 | +------------- |
| 14 | + |
| 15 | +The ``Analyse`` is configured using a ``toml`` file. The examples throughout this document are based on the following configuration: |
| 16 | + |
| 17 | +.. literalinclude:: ./../../../tests/data/analyse/default_config.toml |
| 18 | + :caption: default_config.toml |
| 19 | + :language: toml |
| 20 | + |
| 21 | +This configuration instructs the analyse to extract ``Sphinx-Needs ID Refs`` and ``Marked rst text`` using the defined markers. |
| 22 | + |
| 23 | +Sphinx-Needs ID Refs |
| 24 | +-------------------- |
| 25 | + |
| 26 | +Below is an example of a C++ source file containing need ID references and the corresponding JSON output from the analyse. |
| 27 | + |
| 28 | +.. tabs:: |
| 29 | + |
| 30 | + .. code-tab:: cpp |
| 31 | + |
| 32 | + #include <iostream> |
| 33 | + |
| 34 | + // @need-ids: need_001, need_002, need_003, need_004 |
| 35 | + void dummy_func1(){ |
| 36 | + //... |
| 37 | + } |
| 38 | + |
| 39 | + // @need-ids: need_003 |
| 40 | + int main() { |
| 41 | + std::cout << "Starting demo_1..." << std::endl; |
| 42 | + dummy_func1(); |
| 43 | + std::cout << "Demo_1 finished." << std::endl; |
| 44 | + return 0; |
| 45 | + } |
| 46 | + |
| 47 | + .. code-tab:: json |
| 48 | + |
| 49 | + [ |
| 50 | + { |
| 51 | + "filepath": "tests/data/need_id_refs/dummy_1.cpp", |
| 52 | + "remote_url": "https://github.com/useblocks/sphinx-codelinks/blob/fa5a9129d60203355ae9fe4a725246a88522c60c/tests/data/need_id_refs/dummy_1.cpp#L3", |
| 53 | + "source_map": { |
| 54 | + "start": { "row": 2, "column": 13 }, |
| 55 | + "end": { "row": 2, "column": 51 } |
| 56 | + }, |
| 57 | + "tagged_scope": "void dummy_func1(){\n //...\n }", |
| 58 | + "need_ids": ["need_001", "need_002", "need_003", "need_004"], |
| 59 | + "marker": "@need-ids:", |
| 60 | + "type": "need-id-refs" |
| 61 | + }, |
| 62 | + { |
| 63 | + "filepath": "tests/data/need_id_refs/dummy_1.cpp", |
| 64 | + "remote_url": "https://github.com/useblocks/sphinx-codelinks/blob/fa5a9129d60203355ae9fe4a725246a88522c60c/tests/data/need_id_refs/dummy_1.cpp#L8", |
| 65 | + "source_map": { |
| 66 | + "start": { "row": 7, "column": 13 }, |
| 67 | + "end": { "row": 7, "column": 21 } |
| 68 | + }, |
| 69 | + "tagged_scope": "int main() {\n std::cout << \"Starting demo_1...\" << std::endl;\n dummy_func1();\n std::cout << \"Demo_1 finished.\" << std::endl;\n return 0;\n }", |
| 70 | + "need_ids": ["need_003"], |
| 71 | + "marker": "@need-ids:", |
| 72 | + "type": "need-id-refs" |
| 73 | + } |
| 74 | + ] |
| 75 | + |
| 76 | +Marked RST |
| 77 | +---------- |
| 78 | + |
| 79 | +This example demonstrates how the analyse extracts RST blocks from comments. |
| 80 | + |
| 81 | +.. tabs:: |
| 82 | + |
| 83 | + .. code-tab:: cpp |
| 84 | + |
| 85 | + #include <iostream> |
| 86 | + |
| 87 | + /* |
| 88 | + @rst |
| 89 | + .. impl:: implement dummy function 1 |
| 90 | + :id: IMPL_71 |
| 91 | + @endrst |
| 92 | + */ |
| 93 | + void dummy_func1(){ |
| 94 | + //... |
| 95 | + } |
| 96 | +
|
| 97 | + // @rst..impl:: implement main function @endrst |
| 98 | + int main() { |
| 99 | + std::cout << "Starting demo_1..." << std::endl; |
| 100 | + dummy_func1(); |
| 101 | + std::cout << "Demo_1 finished." << std::endl; |
| 102 | + return 0; |
| 103 | + } |
| 104 | + |
| 105 | + |
| 106 | + .. code-tab:: json |
| 107 | + |
| 108 | + [ |
| 109 | + { |
| 110 | + "filepath": "marked_rst/dummy_1.cpp", |
| 111 | + "remote_url": "https://github.com/useblocks/sphinx-codelinks/blob/26b301138eef25c5130518d96eaa7a29a9c6c9fe/marked_rst/dummy_1.cpp#L4", |
| 112 | + "source_map": { |
| 113 | + "start": { "row": 3, "column": 8 }, |
| 114 | + "end": { "row": 3, "column": 61 } |
| 115 | + }, |
| 116 | + "tagged_scope": "void dummy_func1(){\n //...\n }", |
| 117 | + "rst": ".. impl:: implement dummy function 1\n :id: IMPL_71\n", |
| 118 | + "type": "rst" |
| 119 | + }, |
| 120 | + { |
| 121 | + "filepath": "marked_rst/dummy_1.cpp", |
| 122 | + "remote_url": "https://github.com/useblocks/sphinx-codelinks/blob/26b301138eef25c5130518d96eaa7a29a9c6c9fe/marked_rst/dummy_1.cpp#L14", |
| 123 | + "source_map": { |
| 124 | + "start": { "row": 13, "column": 7 }, |
| 125 | + "end": { "row": 13, "column": 40 } |
| 126 | + }, |
| 127 | + "tagged_scope": "int main() {\n std::cout << \"Starting demo_1...\" << std::endl;\n dummy_func1();\n std::cout << \"Demo_1 finished.\" << std::endl;\n return 0;\n }", |
| 128 | + "rst": "..impl:: implement main function ", |
| 129 | + "type": "rst" |
| 130 | + } |
| 131 | + ] |
| 132 | + |
| 133 | +Limitations |
| 134 | +----------- |
| 135 | + |
| 136 | +Please be aware of the following limitations: |
| 137 | + |
| 138 | +- **Supported Languages**: The analyse only supports comment styles for C/C++ (``//``, ``/*...*/``) and Python (``#``). |
| 139 | +- **Single Comment Style**: An analysis run can only process a single comment style at a time. |
| 140 | +- **Configuration Incompatibility**: The TOML configuration file cannot be shared with the ``CodeLink`` Sphinx extensions. |
0 commit comments