Skip to content

Commit 4266973

Browse files
committed
docs: document the language-aware parsing of source files for traceability
Also, a few minor updates along the way.
1 parent ad6fdac commit 4266973

19 files changed

+403
-99
lines changed
-280 KB
Binary file not shown.
396 KB
Loading
23.3 KB
Loading
396 KB
Loading
23.3 KB
Loading

docs/sphinx/source/strictdoc_01_user_guide.rst

Lines changed: 167 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ Summary of StrictDoc features:
1313
- The documentation files are stored as human-readable text files.
1414
- A simple domain-specific language DSL is used for writing the documents. The
1515
text format for encoding this language is called SDoc (strict-doc).
16-
- StrictDoc reads ``*.sdoc`` files and builds an in-memory representation of a
16+
- StrictDoc reads \*.sdoc files and builds an in-memory representation of a
1717
document tree.
1818
- From this in-memory representation, StrictDoc can generate the documentation
1919
into a number of formats including HTML, RST, ReqIF, PDF, JSON, Excel.
@@ -28,9 +28,9 @@ Summary of StrictDoc features:
2828
- Requirements to source files traceability (experimental). See
2929
:ref:`Traceability between requirements and source code <SECTION-TRACEABILITY-REQS-TO-SOURCE-CODE>`.
3030
- Custom grammar and custom fields support. The StrictDoc's grammar can be
31-
extended to support arbitrary special fields, such as ``PRIORITY``, ``OWNER``,
31+
extended to support arbitrary special fields, such as "PRIORITY", "OWNER",
3232
or even more specialized fields, such as
33-
``Automotive Safety Integrity Level (ASIL)`` or ``Verification method``.
33+
"Automotive Safety Integrity Level (ASIL)" or "Verification method".
3434
See :ref:`Custom grammars <SECTION-CUSTOM-GRAMMARS>`.
3535
- Good performance of the `textX <https://github.com/textX/textX>`_
3636
parser and parallelized incremental generation of documents: generation of
@@ -1722,10 +1722,142 @@ Traceability between requirements and source code
17221722

17231723
**Note:** This feature is experimental, the documentation is incomplete.
17241724

1725-
StrictDoc allows connecting requirements to source code files. Two types of
1726-
links are supported:
1725+
StrictDoc allows connecting requirements to source code files in two ways:
17271726

1728-
1\) A basic link where a requirement links to a whole file.
1727+
1. Linking source files to requirements by adding special markers in the source code without modifying the requirements.
1728+
2. Linking requirements to source files by adding relations in the requirements without altering the source code.
1729+
1730+
The advantage of the first approach is that requirements remain agnostic to the source code and implementation details. Special markers are added solely to the source files, creating traceability back to the requirements.
1731+
1732+
The benefit of the second approach is that traceability to source files is established without any modification to the source code. This can be useful in projects where adding markers to the source code is undesirable or not feasible.
1733+
1734+
Both options can be used independently or in combination, depending on the project setup and allocation of software components.
1735+
1736+
To activate the traceability to source files, configure the project config with a dedicated feature:
1737+
1738+
.. code-block:: yaml
1739+
1740+
[project]
1741+
1742+
features = [
1743+
"REQUIREMENT_TO_SOURCE_TRACEABILITY"
1744+
]
1745+
1746+
By default, StrictDoc looks for source files in a directory from which the ``strictdoc`` command is run. This can be changed by using the ``source_root_path`` project-level option.
1747+
1748+
See :ref:`Project-level options <SDOC_UG_OPTIONS_PROJECT_LEVEL>` for more details about the project-level options.
1749+
1750+
The
1751+
`strictdoc-examples <https://github.com/strictdoc-project/strictdoc-examples>`_
1752+
repository contains executable examples including the example of
1753+
requirements-to-source-code traceability.
1754+
1755+
.. _SECTION-UG-Language-aware-parsing-of-source-code:
1756+
1757+
Language-aware parsing of source code
1758+
-------------------------------------
1759+
1760+
For parsing source code and calculating traceability to requirements, StrictDoc uses a general parser that is agnostic of specific programming languages and their constructs, such as classes or functions. However, for languages with these constructs, establishing traceability to them can simplify the tracing process.
1761+
1762+
As an experimental option, StrictDoc supports parsing source files of selected programming languages (currently Python and C) to recognize language syntax, primarily enabling traceability of functions (in Python, C, and others) and classes (in Python, C++, and others) to requirements.
1763+
1764+
To activate language-aware traceability, configure the project with the following features:
1765+
1766+
.. code:: toml
1767+
1768+
[project]
1769+
1770+
features = [
1771+
"REQUIREMENT_TO_SOURCE_TRACEABILITY",
1772+
"SOURCE_FILE_LANGUAGE_PARSERS"
1773+
]
1774+
1775+
Currently, only Python and C parsers are implemented. Upcoming implementations include parsers for Rust, C++, Bash, and more.
1776+
1777+
Linking source code to requirements
1778+
-----------------------------------
1779+
1780+
To connect a source file to a requirement, a dedicated ``@relation`` marker must be added to the source file. Several marker types are supported, depending on the programming language. For example, the ``scope=class`` option is available for Python files but not for C files, as C does not support classes.
1781+
1782+
.. note::
1783+
1784+
For language-specific parsing of source code, e.g., Python and C, make sure to enable the corresponding option, see :ref:`Language-aware parsing of source code <SECTION-UG-Language-aware-parsing-of-source-code>`.
1785+
1786+
**1\) Linking a file to a requirement**
1787+
1788+
The marker must be added to the top comment of a file. Currently supported only in Python.
1789+
1790+
.. code:: python
1791+
1792+
"""
1793+
This file implements ...
1794+
1795+
@relation(REQ-1, scope=file)
1796+
"""
1797+
1798+
**2\) Linking a class to a requirement (Python only)**
1799+
1800+
.. code:: python
1801+
1802+
class Foo:
1803+
"""
1804+
This class implements ...
1805+
1806+
@relation(REQ-1, scope=file)
1807+
"""
1808+
1809+
**3\) Linking a function to a requirement (Python and C only)**
1810+
1811+
.. code:: python
1812+
1813+
class Foo:
1814+
def bar(self):
1815+
"""
1816+
This function implements ...
1817+
1818+
@relation(REQ-1, scope=function)
1819+
"""
1820+
1821+
or
1822+
1823+
.. code:: c
1824+
1825+
/**
1826+
* Some text.
1827+
*
1828+
* @relation(REQ-1, scope=function)
1829+
*/
1830+
void hello_world(void) {
1831+
print("Hello, World\n");
1832+
}
1833+
1834+
**4\) Linking a range to a requirement**
1835+
1836+
.. code:: python
1837+
1838+
def foo():
1839+
# @relation(REQ-1, scope=range_start)
1840+
print("Hello, World!")
1841+
# @relation(REQ-1, scope=range_end)
1842+
1843+
**5\) Linking a single line to a requirement**
1844+
1845+
.. code:: python
1846+
1847+
def foo():
1848+
# @relation(REQ-1, scope=line)
1849+
print("Hello, World!")
1850+
1851+
Linking requirements to source code
1852+
-----------------------------------
1853+
1854+
The linking of requirements to source files is arranged with a special RELATION type ``File``.
1855+
1856+
.. note::
1857+
1858+
For language-specific parsing of source code, e.g., Python and C, make sure to enable the corresponding option, see :ref:`Language-aware parsing of source code <SECTION-UG-Language-aware-parsing-of-source-code>`.
1859+
1860+
**1\) Linking a requirement to a whole source file**
17291861

17301862
.. code-block:: text
17311863
@@ -1737,53 +1869,51 @@ links are supported:
17371869
TITLE: File reference
17381870
STATEMENT: This requirement references the file.
17391871
1740-
2\) A range-based link where a requirement links to a file and
1741-
additionally in the file, there is a reverse link that connects a source range
1742-
back to the requirement:
1743-
1744-
The requirement declaration contains a reference of the type ``File``:
1872+
**2\) Linking a requirement to range in a source file**
17451873

17461874
.. code-block:: text
17471875
17481876
[REQUIREMENT]
17491877
UID: REQ-002
1878+
TITLE: Range file reference
1879+
STATEMENT: This requirement references the file.py file.
17501880
RELATIONS:
17511881
- TYPE: File
17521882
VALUE: file.py
1753-
TITLE: Range file reference
1754-
STATEMENT: This requirement references the file.py file.
1755-
COMMENT: >>>
1756-
If the file.py contains a source range that is connected back to this
1757-
requirement (REQ-002), the link becomes a link to the source range.
1758-
<<<
1759-
1760-
The source file:
1761-
1762-
.. code-block:: py
1883+
LINE_RANGE: 2, 4
17631884
1764-
# @sdoc[REQ-002]
1765-
def hello_world():
1766-
print("hello world")
1767-
# @sdoc[/REQ-002]
1885+
**3\) Linking a requirement to a function in a source file**
17681886

1769-
To activate the traceability to source files, configure the project config with a dedicated feature:
1887+
.. code-block:: text
17701888
1771-
.. code-block:: yaml
1889+
[REQUIREMENT]
1890+
UID: REQ-002
1891+
TITLE: Function reference
1892+
STATEMENT: This requirement references a function in a file.
1893+
RELATIONS:
1894+
- TYPE: File
1895+
VALUE: file.py
1896+
FUNCTION: hello_world
1897+
- TYPE: File
1898+
VALUE: file.c
1899+
FUNCTION: Foo.hello_world_2
17721900
1773-
[project]
1901+
.. note::
17741902

1775-
features = [
1776-
"REQUIREMENT_TO_SOURCE_TRACEABILITY"
1777-
]
1903+
For linking to functions in classes, a class name has to be added in a format: ``<class name>.<function name>``. This is currently only supported for Python source files.
17781904

1779-
By default, StrictDoc looks for source files in a directory from which the ``strictdoc`` command is run. This can be changed by using the ``source_root_path`` project-level option.
1905+
**4\) Linking a requirement to a class in a source file (Python only)**
17801906

1781-
See :ref:`Project-level options <SDOC_UG_OPTIONS_PROJECT_LEVEL>` for more details about the project-level options.
1907+
.. code-block:: text
17821908
1783-
The
1784-
`strictdoc-examples <https://github.com/strictdoc-project/strictdoc-examples>`_
1785-
repository contains executable examples including the example of
1786-
requirements-to-source-code traceability.
1909+
[REQUIREMENT]
1910+
UID: REQ-002
1911+
TITLE: Class reference
1912+
STATEMENT: This requirement references a class in a file.
1913+
RELATIONS:
1914+
- TYPE: File
1915+
VALUE: file.py
1916+
CLASS: Foo
17871917
17881918
ReqIF support
17891919
=============

docs/sphinx/source/strictdoc_02_faq.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -296,8 +296,6 @@ FRET has an impressive list of
296296

297297
FRET's user interface is built with Electron.
298298

299-
The detailed comparison is coming.
300-
301299
How long has the StrictDoc project been around?
302300
===============================================
303301

@@ -330,6 +328,8 @@ The custom RST parser was replaced with a TextX-based DSL. Since then, StrictDoc
330328

331329
The FastAPI/Turbo/Stimulus-based Web interface prototype was created to complement the text-based interface with a graphical user interface (GUI). When the Web-based GUI is stable, StrictDoc may become useable by non-programmers too.
332330

331+
See also: :ref:`Project milestones <SECTION-DP-Project-milestones>`.
332+
333333
Which StrictDoc statistics are available?
334334
=========================================
335335

docs/sphinx/source/strictdoc_03_development_plan.rst

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ An important feature of StrictDoc is its focus on open data, ensuring ease of da
2929

3030
StrictDoc shall be compatible with other software and engineering tools. This includes at least the compatibility with the Python ecosystem, the model-based systems engineering tools, such as Capella, and the formats providing Software Bill of Materials, such as SPDX.
3131

32+
.. _SECTION-DP-Project-milestones:
33+
3234
Project milestones
3335
==================
3436

@@ -84,7 +86,7 @@ As an open-source project, StrictDoc is developed without strict deadlines, howe
8486
* - 2024-Q3
8587
- HTML2PDF improvements. ReqIF roundtrip for RELATION/ROLE. Consistent automatic escaping of Jinja templates. Passthrough->export command migration.
8688
* - 2024-Q4
87-
- TBD
89+
- Connecting requirements to functions (C, Python) and classes (Python) in source code. Support the linking in both directions independently: from requirements to source using RELATION/File and from source to requirements using @relation markers.
8890

8991
The roadmap diagram
9092
-------------------

docs/sphinx/source/strictdoc_04_release_notes.rst

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,17 @@ $$$$$$$$$$$$$
33

44
This document maintains a record of all changes to StrictDoc since November 2023. It serves as a user-friendly version of the changelog, complementing the automatically generated, commit-by-commit changelog available here: `StrictDoc Changelog <https://github.com/strictdoc-project/strictdoc/blob/main/CHANGELOG.md>`_.
55

6+
Unreleased 0.1.0 (2024-11-01)
7+
=============================
8+
9+
This backward-compatible release introduces several new features for tracing requirements to source files:
10+
11+
- StrictDoc now integrates with `Tree-sitter <https://tree-sitter.github.io/tree-sitter/>`_, enabling it to parse multiple programming languages. Using AST information, it achieves more precise tracing of requirements to source code.
12+
- Language-specific parsers for Python and C have been added, allowing functions (in C and Python) or classes (in Python) to be linked to requirements.
13+
- Both forward linking of requirements to source files and backward linking of source files to requirements are supported. These features can be used independently or together within the same project.
14+
15+
With this release, we are also transitioning to a more `semantic versioning <https://semver.org>`_-oriented release scheme. From now on, the MAJOR.MINOR.PATCH version components will be maintained according to the recommendations of the semantic versioning specification.
16+
617
0.0.60 (2024-10-26)
718
===================
819

docs/sphinx/source/strictdoc_10_contributing.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ following steps:
2222
single contribution.
2323
4. If the contribution is not trivial, read through the complete development
2424
guide.
25+
5. If the contribution is not trivial, please update the Release Notes with a high-level summary of your contribution. Refer to the release notes from previous releases for guidance on what information is desirable.
2526

2627
How can I help?
2728
===============

0 commit comments

Comments
 (0)