Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/ahbicht/expressions/ahb_expression_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,11 @@
PREFIX_OPERATOR: "X"i | "O"i | "U"i
MODAL_MARK: /M(uss)?|S(oll)?|K(ann)?/i
// Matches if it looks like a condition expression, but does not yet check if it is a syntactically valid one:
CONDITION_EXPRESSION: /(?!\BU\B)[\[\]\(\)U∧O∨X⊻\d\sP\.UB]+/i
CONDITION_EXPRESSION: /(?!\BU\B)(?:[\[\]\(\)U∧O∨X⊻\d\sP\.UB]|(?:\bFC_UNFULFILLED\b)|(?:\bFC_FULFILLED\b)|(?:\bRC_UNFULFILLED\b)|(?:\bRC_FULFILLED\b)|(?:\bRC_UNKNOWN\b)|(?:\bRC_NEUTRAL\b))+/i
"""
# Regarding the negative lookahead in the condition expression regex see examples https://regex101.com/r/6fFHD4/1
# and CTRL+F for "Mus[2]" in the unittest that fails if you remove the lookahead.
# The combination with the hardcoded RC/FC placeholders is explained here: https://regex101.com/r/7Fjlb9/2
_parser = Lark(GRAMMAR, start="ahb_expression")

_cache: Dict[str, Tree[Token]] = {} #: holds the ahb expression as key and the parsed Tree as value
Expand Down
6 changes: 6 additions & 0 deletions src/ahbicht/expressions/condition_expression_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,13 @@
| package
| condition
| time_condition
| hardcoded_rc
| hardcoded_fc
?brackets: "(" expression ")"
// placeholders for hardcoded format constraints that always evaluate to the same EvaluatedFormatConstraint
hardcoded_fc: "[" ("FC_UNFULFILLED" | "FC_FULFILLED") "]"
// placeholders for hardcoded requirement constraints that always evaluate to the same ConditionFulfilledValue
hardcoded_rc: "[" ("RC_UNFULFILLED" | "RC_FULFILLED" | "RC_NEUTRAL" | "RC_UNKNOWN") "]"
time_condition: "[" TIME_CONDITION_KEY "]" // a rule for point in time-conditions
package: "[" PACKAGE_KEY REPEATABILITY? "]" // a rule for packages
condition: "[" CONDITION_KEY "]" // a rule for condition keys
Expand Down
2 changes: 2 additions & 0 deletions unittests/test_ahb_expression_evaluation.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ def setup_and_teardown_injector(self):
pytest.param("Muss[1]", ModalMark.MUSS, True, True, None, None),
pytest.param("muss[1]", ModalMark.MUSS, True, True, None, None),
pytest.param("M[1]", ModalMark.MUSS, True, True, None, None),
pytest.param("M[RC_FULFILLED]", ModalMark.MUSS, True, True, None, None),
pytest.param("m[1]", ModalMark.MUSS, True, True, None, None),
pytest.param("Soll[1]", ModalMark.SOLL, True, True, None, None),
pytest.param("soll[1]", ModalMark.SOLL, True, True, None, None),
Expand All @@ -59,6 +60,7 @@ def setup_and_teardown_injector(self):
pytest.param("K[1]", ModalMark.KANN, True, True, None, None),
pytest.param("k[1]", ModalMark.KANN, True, True, None, None),
pytest.param("Muss[2]", ModalMark.MUSS, False, True, None, None),
pytest.param("Muss[RC_UNFULFILLED]", ModalMark.MUSS, False, True, None, None),
pytest.param("Muss[1]Soll[2]", ModalMark.MUSS, True, True, None, None),
pytest.param("Muss[2]Soll[1]Kann[4]", ModalMark.SOLL, True, True, None, None),
pytest.param("Muss[2]\tSoll [ 1] Kann[4\t]", ModalMark.SOLL, True, True, None, None),
Expand Down