Skip to content

Commit

Permalink
Merge pull request strictdoc-project#1903 from strictdoc-project/stan…
Browse files Browse the repository at this point in the history
…islaw/mid_to_fields

backend/sdoc: SDocNode: Make MID a normal SDocField
  • Loading branch information
stanislaw authored Jun 30, 2024
2 parents e6713de + da11dd6 commit be1f544
Show file tree
Hide file tree
Showing 59 changed files with 823 additions and 133 deletions.
37 changes: 37 additions & 0 deletions docs/strictdoc_20_L1_Open_Requirements_Tool.sdoc
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,43 @@ ROOT: True
OPTIONS:
ENABLE_MID: True

[GRAMMAR]
ELEMENTS:
- TAG: TEXT
FIELDS:
- TITLE: UID
TYPE: String
REQUIRED: False
- TITLE: STATEMENT
TYPE: String
REQUIRED: False
- TAG: REQUIREMENT
FIELDS:
- TITLE: MID
TYPE: String
REQUIRED: False
- TITLE: UID
TYPE: String
REQUIRED: False
- TITLE: STATUS
TYPE: String
REQUIRED: False
- TITLE: TITLE
TYPE: String
REQUIRED: False
- TITLE: STATEMENT
TYPE: String
REQUIRED: False
- TITLE: RATIONALE
TYPE: String
REQUIRED: False
- TITLE: COMMENT
TYPE: String
REQUIRED: False
RELATIONS:
- TYPE: Parent
- TYPE: File

[FREETEXT]
The StrictDoc project is structured around two distinct requirement documents that guide its development:

Expand Down
37 changes: 37 additions & 0 deletions docs/strictdoc_21_L2_StrictDoc_Requirements.sdoc
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,43 @@ REQ_PREFIX: SDOC-SRS-
OPTIONS:
ENABLE_MID: True

[GRAMMAR]
ELEMENTS:
- TAG: TEXT
FIELDS:
- TITLE: UID
TYPE: String
REQUIRED: False
- TITLE: STATEMENT
TYPE: String
REQUIRED: False
- TAG: REQUIREMENT
FIELDS:
- TITLE: MID
TYPE: String
REQUIRED: False
- TITLE: UID
TYPE: String
REQUIRED: False
- TITLE: STATUS
TYPE: String
REQUIRED: False
- TITLE: TITLE
TYPE: String
REQUIRED: False
- TITLE: STATEMENT
TYPE: String
REQUIRED: False
- TITLE: RATIONALE
TYPE: String
REQUIRED: False
- TITLE: COMMENT
TYPE: String
REQUIRED: False
RELATIONS:
- TYPE: Parent
- TYPE: File

[SECTION]
MID: bd8a7931c1e04df9bf08d291488c67aa
TITLE: SDoc data model
Expand Down
37 changes: 37 additions & 0 deletions docs/strictdoc_28_Backlog.sdoc
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,43 @@ REQ_PREFIX: SDOC-BACKLOG-
OPTIONS:
ENABLE_MID: True

[GRAMMAR]
ELEMENTS:
- TAG: TEXT
FIELDS:
- TITLE: UID
TYPE: String
REQUIRED: False
- TITLE: STATEMENT
TYPE: String
REQUIRED: False
- TAG: REQUIREMENT
FIELDS:
- TITLE: MID
TYPE: String
REQUIRED: False
- TITLE: UID
TYPE: String
REQUIRED: False
- TITLE: STATUS
TYPE: String
REQUIRED: False
- TITLE: TITLE
TYPE: String
REQUIRED: False
- TITLE: STATEMENT
TYPE: String
REQUIRED: False
- TITLE: RATIONALE
TYPE: String
REQUIRED: False
- TITLE: COMMENT
TYPE: String
REQUIRED: False
RELATIONS:
- TYPE: Parent
- TYPE: File

[FREETEXT]
This document outlines the future work items for StrictDoc.

Expand Down
11 changes: 11 additions & 0 deletions docs_extra/DO178_requirements.sdoc
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,19 @@ OPTIONS:

[GRAMMAR]
ELEMENTS:
- TAG: TEXT
FIELDS:
- TITLE: UID
TYPE: String
REQUIRED: False
- TITLE: STATEMENT
TYPE: String
REQUIRED: False
- TAG: REQUIREMENT
FIELDS:
- TITLE: MID
TYPE: String
REQUIRED: False
- TITLE: UID
TYPE: String
REQUIRED: False
Expand Down
37 changes: 37 additions & 0 deletions docs_extra/Zephyr_requirements.sdoc
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,43 @@ ROOT: True
OPTIONS:
ENABLE_MID: True

[GRAMMAR]
ELEMENTS:
- TAG: TEXT
FIELDS:
- TITLE: UID
TYPE: String
REQUIRED: False
- TITLE: STATEMENT
TYPE: String
REQUIRED: False
- TAG: REQUIREMENT
FIELDS:
- TITLE: MID
TYPE: String
REQUIRED: False
- TITLE: UID
TYPE: String
REQUIRED: False
- TITLE: STATUS
TYPE: String
REQUIRED: False
- TITLE: TITLE
TYPE: String
REQUIRED: False
- TITLE: STATEMENT
TYPE: String
REQUIRED: False
- TITLE: RATIONALE
TYPE: String
REQUIRED: False
- TITLE: COMMENT
TYPE: String
REQUIRED: False
RELATIONS:
- TYPE: Parent
- TYPE: File

[REQUIREMENT]
MID: 68e87901205c4b0dbb6a0071479330b5
UID: ZEP-1
Expand Down
1 change: 0 additions & 1 deletion strictdoc/backend/excel/import_/excel_to_sdoc_converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,6 @@ def create_requirement(
requirement = SDocNode(
parent=template_requirement.parent,
requirement_type=template_requirement.requirement_type,
mid=None,
fields=list(template_requirement.enumerate_fields()),
relations=template_requirement.relations,
)
Expand Down
13 changes: 9 additions & 4 deletions strictdoc/backend/reqif/p01_sdoc/reqif_to_sdoc_converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,6 @@ def create_section_from_spec_object(
node: SDocNode = SDocNode(
parent=section,
requirement_type="TEXT",
mid=None,
fields=[node_field],
relations=[],
)
Expand Down Expand Up @@ -499,16 +498,22 @@ def create_requirement_from_spec_object(
spec_object_type.identifier
]
)

if requirement_mid is not None:
fields.insert(
0,
SDocNodeField.create_from_string(
None, "MID", requirement_mid, multiline=False
),
)
requirement = SDocNode(
parent=parent_section,
requirement_type=grammar_element.tag,
mid=requirement_mid,
fields=fields,
relations=[],
)
requirement.ng_level = level

for field_ in fields:
field_.parent = requirement
if foreign_key_id_or_none is not None:
spec_object_parents = reqif_bundle.get_spec_object_parents(
spec_object.identifier
Expand Down
3 changes: 3 additions & 0 deletions strictdoc/backend/reqif/p01_sdoc/sdoc_to_reqif_converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -465,6 +465,9 @@ def _convert_requirement_to_spec_object(

attributes: List[SpecObjectAttribute] = []
for field in requirement.fields_as_parsed:
# The MID field, if exists, is extracted separately as a ReqIF Identifier.
if field.field_name == "MID":
continue
grammar_field = grammar_element.fields_map[field.field_name]
if isinstance(grammar_field, GrammarElementFieldSingleChoice):
data_type_ref = data_types_lookup[field.field_name]
Expand Down
19 changes: 19 additions & 0 deletions strictdoc/backend/sdoc/error_handling.py
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,25 @@ def grammar_reserved_statement_must_be_required(
filename=path_to_sdoc_file,
)

@staticmethod
def grammar_element_has_no_mid_field(
grammar_element: GrammarElement,
path_to_sdoc_file: str,
):
return StrictDocSemanticError(
title=(
f"Grammar element '{grammar_element.tag}' is missing the MID field "
f"which contradicts to the DOCUMENT's ENABLE_MID setting."
),
hint=(
"Either disable the ENABLE_MID option or ensure that every element has the MID field defined."
),
example=None,
line=1,
col=1,
filename=path_to_sdoc_file,
)

@staticmethod
def view_references_nonexisting_grammar_element(
document: SDocDocument,
Expand Down
5 changes: 2 additions & 3 deletions strictdoc/backend/sdoc/grammar/grammar.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,6 @@
SDocNode[noskipws]:
'[' !'SECTION' !SDocCompositeNodeTagName requirement_type = RequirementType ']' '\n'
('MID: ' mid = SingleLineString '\n')?
fields *= SDocNodeField
(
'RELATIONS:' '\n'
Expand All @@ -189,6 +188,8 @@
SDocNodeField[noskipws]:
(
field_name = 'MID' ': ' parts+=SingleLineString '\n'
|
field_name = 'UID' ': ' parts+=/{REGEX_UID}/ '\n'
|
field_name = FieldName ':'
Expand All @@ -211,8 +212,6 @@
SDocCompositeNode[noskipws]:
'[COMPOSITE_' requirement_type = RequirementType ']' '\n'
('MID: ' mid = SingleLineString '\n')?
fields *= SDocNodeField
(
'RELATIONS:' '\n'
Expand Down
2 changes: 1 addition & 1 deletion strictdoc/backend/sdoc/grammar_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def read(

if not grammar.has_text_element():
grammar.add_element_first(
DocumentGrammar.create_default_text_element()
DocumentGrammar.create_default_text_element(grammar)
)

# HACK:
Expand Down
7 changes: 5 additions & 2 deletions strictdoc/backend/sdoc/models/document_grammar.py
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,9 @@ def __init__(

self.is_default = False

self.ng_line_start: Optional[int] = None
self.ng_col_start: Optional[int] = None

@staticmethod
def create_default(parent) -> "DocumentGrammar":
text_element: GrammarElement = (
Expand Down Expand Up @@ -338,7 +341,7 @@ def update_with_elements(self, elements: List[GrammarElement]):
self.elements_by_type = elements_by_type

@staticmethod
def create_default_text_element() -> GrammarElement:
def create_default_text_element(parent=None) -> GrammarElement:
fields: List[
Union[
GrammarElementFieldString,
Expand All @@ -360,7 +363,7 @@ def create_default_text_element() -> GrammarElement:
),
]
text_element = GrammarElement(
parent=None, tag="TEXT", fields=fields, relations=[]
parent=parent, tag="TEXT", fields=fields, relations=[]
)
return text_element

Expand Down
7 changes: 6 additions & 1 deletion strictdoc/backend/sdoc/models/node.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,6 @@ def __init__(
self,
parent: Union[SDocDocument, SDocSection, "SDocCompositeNode"],
requirement_type: str,
mid: Optional[str],
fields: List[SDocNodeField],
relations: List[Reference],
requirements: Optional[List["SDocNode"]] = None,
Expand Down Expand Up @@ -156,6 +155,12 @@ def __init__(
self.ng_byte_end: Optional[int] = None
self.context: SDocNodeContext = SDocNodeContext()

mid: Optional[str] = None
mid_fields: Optional[List[SDocNodeField]] = ordered_fields_lookup.get(
"MID", None
)
if mid_fields is not None:
mid = mid_fields[0].get_text_value()
self.reserved_mid: MID = MID(mid) if mid is not None else MID.create()
self.mid_permanent: bool = mid is not None

Expand Down
1 change: 0 additions & 1 deletion strictdoc/backend/sdoc/models/object_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,6 @@ def create_requirement(
requirement = SDocNode(
parent=parent,
requirement_type=requirement_type,
mid=None,
fields=fields,
relations=[],
)
Expand Down
1 change: 1 addition & 0 deletions strictdoc/backend/sdoc/models/type_system.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@


class RequirementFieldName:
MID = "MID"
UID = "UID"
LEVEL = "LEVEL"
STATUS = "STATUS"
Expand Down
Loading

0 comments on commit be1f544

Please sign in to comment.