Skip to content

Commit 6305985

Browse files
authored
Merge pull request #2200 from strictdoc-project/stanislaw/merge_nodes
backend/sdoc: prepare model for [[SECTION]] migration
2 parents 7a17644 + 8b3ab9d commit 6305985

File tree

5 files changed

+38
-3
lines changed

5 files changed

+38
-3
lines changed

strictdoc/backend/sdoc/grammar/grammar.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@
185185
(relations += Reference)
186186
)?
187187
188-
section_contents *= SpaceThenRequirement
188+
section_contents *= SectionOrRequirement
189189
190190
'\n'
191191
'[[/' node_type_close = RequirementType ']]' '\n'

strictdoc/backend/sdoc/models/node.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
)
3232
from strictdoc.helpers.auto_described import auto_described
3333
from strictdoc.helpers.cast import assert_cast
34+
from strictdoc.helpers.exception import StrictDocException
3435
from strictdoc.helpers.mid import MID
3536
from strictdoc.helpers.string import ensure_newline
3637

@@ -121,10 +122,17 @@ def __init__(
121122
] = parent
122123

123124
self.node_type: str = node_type
124-
# FIXME: MERGE NODES
125+
125126
if node_type_close is not None and len(node_type_close) > 0:
126-
assert node_type == node_type_close
127+
if node_type != node_type_close:
128+
raise StrictDocException(
129+
"[[NODE]] syntax error: "
130+
"Opening and closing tags must match: "
131+
f"opening: {node_type}, closing: {node_type_close}."
132+
)
127133
assert is_composite
134+
else:
135+
assert not is_composite
128136

129137
self.is_composite: bool = is_composite
130138

strictdoc/backend/sdoc/processor.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ def get_default_processors(self):
6464
"SDocSection": self.process_section,
6565
"DocumentFromFile": self.process_document_from_file,
6666
"SDocCompositeNode": self.process_composite_requirement,
67+
"SDocCompositeNodeNew": self.process_requirement,
6768
"SDocNode": self.process_requirement,
6869
"SDocNodeField": self.process_node_field,
6970
}

strictdoc/server/reload_config.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ def create(
5757
+ cls.expand_folder("dist", max_depth=3)
5858
+ cls.expand_folder("tests", max_depth=15)
5959
+ cls.expand_folder("output", max_depth=15)
60+
+ cls.expand_folder("Output", max_depth=15)
6061
)
6162

6263
# Changing typical StrictDoc's own source code files should trigger

tests/unit/strictdoc/backend/sdoc/test_dsl_passthrough.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
)
1616
from strictdoc.backend.sdoc.reader import SDReader
1717
from strictdoc.backend.sdoc.writer import SDWriter
18+
from strictdoc.helpers.exception import StrictDocException
1819

1920

2021
def test_001_minimal_doc(default_project_config):
@@ -964,6 +965,30 @@ def test_089_document_config_use_mid(default_project_config):
964965
assert input_sdoc == output
965966

966967

968+
def test__validation__30__composite_node_start_end_tags_do_not_match():
969+
input_sdoc = """\
970+
[DOCUMENT]
971+
TITLE: Test Doc
972+
973+
[[REQUIREMENT]]
974+
UID: TITLE
975+
976+
[[/FOOBAR]]
977+
""".lstrip()
978+
979+
reader = SDReader()
980+
981+
with pytest.raises(Exception) as exc_info:
982+
_ = reader.read(input_sdoc)
983+
984+
assert exc_info.type is StrictDocException
985+
assert exc_info.value.args[0] == (
986+
"[[NODE]] syntax error: "
987+
"Opening and closing tags must match: "
988+
"opening: REQUIREMENT, closing: FOOBAR."
989+
)
990+
991+
967992
def test_edge_case_01_minimal_requirement(default_project_config):
968993
input_sdoc = """
969994
[DOCUMENT]

0 commit comments

Comments
 (0)