Skip to content

Commit 92def86

Browse files
committed
adapt comments
1 parent 376739c commit 92def86

File tree

6 files changed

+23
-32
lines changed

6 files changed

+23
-32
lines changed

docs/source/components/directive.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
Directive
44
=========
55

6-
.. attention:: ``src-trace`` directive do NOT supports :ref:`Sphinx-Needs ID Refs <analyse_need_id_refs>`.
6+
.. attention:: ``src-trace`` directive does NOT support :ref:`Sphinx-Needs ID Refs <analyse_need_id_refs>`.
77

88
``src-trace`` Directive generates Sphinx-Needs items from source code comments. There are two ways to define need items in source code:
99

docs/source/components/rst_parser.rst

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,17 @@
1-
Simplified reStructuredText Parser
2-
==================================
1+
RST directive Parser
2+
====================
33

44
The :ref:`analyse <analyse>` module provides a simplified parser for reStructuredText (reST) directives using the ``Lark`` parsing library.
55
It is designed to only parse the RST text extracted by :ref:`RST markers <analyse_rst>`, focusing on specific directive types and their associated options and content.
66
By doing so, the parser avoids the complexity of a full reST parser while still capturing the essential structure needed for Sphinx-Needs integration from the source code.
77

8-
The parser does't have the Sphinx-Needs directive validation logic. It only checks the syntax of the RST directives and extracts the directive type, argument, options, and content.
8+
The parser doesn't have the Sphinx-Needs directive validation logic. It only checks the syntax of the RST directives and extracts:
9+
- directive type
10+
- argument (title)
11+
- options
12+
- content
13+
14+
These extracted data will be furthered used with :external+needs:ref:`add_need <api>` function to create Sphinx-Needs items in ``src-trace`` directive.
915

1016
**Limitations**
1117

docs/source/development/change_log.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ New and Improved
1717
The resolved RST blocks will be dumped into the JSON output along with other extracted markers.
1818
To make the parser more stable, 3 new configuration options are added to control the parsing behavior:
1919

20-
- ``leading_sequences``: List of leading character sequences to strip from each line.
20+
- ``strip_leading_sequences``: List of leading character sequences to strip from each line.
2121

2222
This option allows users to specify a list of leading character sequences (e.g., ``*``, ``-``) that should be stripped
2323
from each line of the marked RST block before parsing.

src/sphinx_codelinks/analyse/analyse.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,7 @@ def extract_marked_rst(
337337
"column": end_column,
338338
},
339339
}
340-
need_directive: None | NeedDirectiveType | UnexpectedInput = None
340+
need_directive: None | NeedDirectiveType | UnexpectedInput
341341
need_directive = parse_rst(
342342
rst_text, self.analyse_config.marked_rst_config.indented_spaces
343343
)
@@ -358,7 +358,7 @@ def extract_marked_rst(
358358
and isinstance(val, str)
359359
):
360360
# convert link options values to list
361-
resolved[key] = val.split(",")
361+
resolved[key] = [item.strip() for item in val.split(",")]
362362
else:
363363
resolved[key] = val
364364

src/sphinx_codelinks/analyse/sn_rst_parser.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
1-
"""Test script for RST directive Lark parser."""
1+
"""Parse reStructuredText (RST) directives using the Lark parser.
2+
3+
This module provides functionality to parse RST directive blocks and extract their components,
4+
such as directive type, title, options, and content for further use by add_need() in src-trace directive.
5+
"""
26

37
# ruff: noqa: N802
4-
# TODO: Not sure Lark is the right tool for this job since the it has a few limitations such as lack of support for dynamic indentation levels while extracting leading spaces in content.
8+
# TODO: Not sure Lark is the right tool for this job since it has a few limitations such as lack of support for dynamic indentation levels while extracting leading spaces in content.
59
# Consider switching to Visitor instead of Transformer to have more control on resolving the tree or implement a custom parser if needed.
610

711
from typing import TypedDict
@@ -11,10 +15,6 @@
1115
from sphinx_codelinks.config import UNIX_NEWLINE
1216

1317

14-
class PreProcessError(Exception):
15-
"""Custom error for preprocess issues."""
16-
17-
1818
class NeedDirectiveType(TypedDict, total=False):
1919
type: str
2020
title: str | None
@@ -66,7 +66,7 @@ def content_line(self, *line):
6666
return line[1].rstrip()
6767

6868
def content_block(self, *lines):
69-
# items is list of lines
69+
# items are list of lines
7070
return {"content": "\n".join(lines)}
7171

7272
def directive_block(self, *blocks):
@@ -75,7 +75,7 @@ def directive_block(self, *blocks):
7575
def directive(self, name, *optionals):
7676
# NAME,, optional title/options/content
7777
need = {"type": name}
78-
# flaten optionals
78+
# flatten optionals
7979
flatten_optionals: list[dict[str, str]] = []
8080
for item in optionals:
8181
if isinstance(item, tuple):
@@ -157,8 +157,8 @@ def preprocess_rst(text: str) -> str:
157157
"""Process valid RST directive text before parsing.
158158
159159
The followings are processed:
160-
- Stripe leading spaces before the directive marker to get relative indentations.
161-
- Stripe trailing spaces at the end
160+
- Strip leading spaces before the directive marker to get relative indentations.
161+
- Strip trailing spaces at the end
162162
- Ensure the text ends with a newline.
163163
"""
164164
if not text:

tests/fixture_files/analyse_rst.yml

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -68,21 +68,6 @@ link_options_rst_marker:
6868
return 0;
6969
}
7070
71-
link_options_rst_marker:
72-
dummy_1.c: |
73-
/*
74-
* @rst
75-
* .. impl:: implement main function
76-
* :id: REQ_001
77-
* :links: IMPL_001, IMPL_002
78-
*
79-
* This is content for the main function implementation.
80-
* @endrst
81-
*/
82-
int main() {
83-
return 0;
84-
}
85-
8671
warning_invalid_type:
8772
dummy_1.c: |
8873
/*

0 commit comments

Comments
 (0)