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

fix incorrect combination of open charclass predicates #69

Merged
merged 4 commits into from
Nov 23, 2022

Conversation

rwe
Copy link
Contributor

@rwe rwe commented Nov 23, 2022

Open/negated charclass predicates like \W and \S were combined incorrectly.

They were interpreted as as not (whitespace or digits) but their correct interpretation is (not whitespace) or (not digits).

This fixes the misinterpretation and the test. It includes a couple minor nits that made it easier to rebase the fix.

Although I didn't include as a test in this PR because there are plausible reasons that the test suite doesn't already do this, I verified the behaviour against the built-in re module with:

import re
from greenery import parse


def test_expr(expr, value):
    pat = parse(expr)
    rx = re.compile(expr)
    assert bool(rx.match(value)) == bool(pat.matches(value))


for expr in (r"\S\D", r"1\D", r"1\D\S"):
    for negation in (True, False):
        for value in "12x ":
            test_expr(f'[{"^" if negation else ""}{expr}]', value)

I also confirmed consistency with some manual tinkering in javascript.

Returning set() or frozenset() inconsistently casuses problems using
class-based operators like `frozenset.union(*…)`.
"internal" vs. "internals" when they change positions was a bit hard to
follow.
@qntm qntm self-assigned this Nov 23, 2022
@qntm qntm merged commit 13e230c into qntm:main Nov 23, 2022
@rwe rwe deleted the fix-negative-charclasses branch November 23, 2022 20:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants