Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update the differ rule range filter #69

Merged
merged 2 commits into from
Feb 7, 2024
Merged
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
8 changes: 5 additions & 3 deletions src/difftool/itemdiffer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down
Loading