From a68fa352f201e2927fdf55c0e3948bf48ab19e80 Mon Sep 17 00:00:00 2001 From: Vaclav Lunak Date: Wed, 7 Feb 2024 08:38:28 +0100 Subject: [PATCH] update the item differ to filter out subrules of a single number (NNN.Na-b) --- src/difftool/itemdiffer.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/difftool/itemdiffer.py b/src/difftool/itemdiffer.py index 4e735ea..e3cebd3 100644 --- a/src/difftool/itemdiffer.py +++ b/src/difftool/itemdiffer.py @@ -40,11 +40,13 @@ def _is_change(self, rule_slice: list[str]) -> (list[str], bool): Check that the marked block is actually a change of something other than rule renumbering. """ # matches a mention of a rule number / range of numbers - # TODO actually inspect how this regex works if not rule_slice: return False - rule_mention_regex = r"^(?:rules? )?\d{3}(?:\.\d+[a-z]*)*(?:–\d{3}(?:\.\d+[a-z]?)?)?\)?[.,]?\)?" - return not re.fullmatch(rule_mention_regex, " ".join(rule_slice)) + rule_regex = r"(?:\d{3}(?:\.\d+[a-z]?)?)" + rule_mention_regex = r"(?:rule )?" + rule_regex + r"\)?[,.]?" + rule_mention_range_regex = r"(?:rules )?" + rule_regex + r"–(?:[a-z]|" + rule_regex + r")\)?[,.]?" + text = " ".join(rule_slice) + return not re.fullmatch(rule_mention_regex, text) and not re.fullmatch(rule_mention_range_regex, text) def diff_items(self, old_item, new_item) -> Union[None, tuple]: old_rule_num = old_item and old_item["ruleNumber"]