Skip to content

Commit 0472735

Browse files
hf-kkleinKonstantin
andauthored
fix: gracefully handle V and v instead of (#570)
denn sie wissen nicht, was sie tun Co-authored-by: Konstantin <[email protected]>
1 parent 01afb67 commit 0472735

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

src/ahbicht/expressions/ahb_expression_parser.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,12 @@
3131
# and CTRL+F for "Mus[2]" in the unittest that fails if you remove the lookahead.
3232
_parser = Lark(GRAMMAR, start="ahb_expression")
3333

34+
_replacements: dict[str, str] = {
35+
"\u00a0": " ", # no-break space,
36+
"V": "∨", # Vogel-V != logical OR
37+
"v": "∨",
38+
}
39+
3440

3541
@tree_copy
3642
@lru_cache(maxsize=1024)
@@ -46,7 +52,8 @@ def parse_ahb_expression_to_single_requirement_indicator_expressions(ahb_express
4652
"""
4753
try:
4854
if ahb_expression is not None:
49-
ahb_expression = ahb_expression.replace("\u00a0", " ") # for sanity: remove no-break space
55+
for key, value in _replacements.items():
56+
ahb_expression = ahb_expression.replace(key, value)
5057
parsed_tree = _parser.parse(ahb_expression)
5158
parsing_logger.debug("Successfully parsed '%s' as AHB expression", ahb_expression)
5259
except (UnexpectedEOF, UnexpectedCharacters, TypeError) as eof:

unittests/test_validity_check.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,9 @@ def configure(binder):
6767
), # unbalanced brackets
6868
pytest.param("Muss [15] ∧ [2050]", True), # contains a 'Geschütztes' Leerzeichen
6969
pytest.param("Muss [15]🙄∧ [2050]", False),
70+
pytest.param(
71+
"X ([950] [509] ∧ ([64] V [70])) V ([960] [522] ∧ [71] ∧ [53])", True
72+
), # nur echt mit 'V' statt LOR
7073
],
7174
)
7275
async def test_is_valid_expression(self, ahb_expression: str, expected_result: bool, inject_cer_evaluators):

0 commit comments

Comments
 (0)