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

Add python support for match/case #1981

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

fcheung
Copy link

@fcheung fcheung commented Jul 28, 2023

This adds match & case as keywords, used by python 3.10 structural pattern matching ( https://peps.python.org/pep-0634/ )

Screenshot 2023-07-28 at 10 44 42

(screenshot from rouge's visual test page)

This adds match & case as keywords, used by python 3.10 structural pattern matching ( https://peps.python.org/pep-0634/ )
@tancnle tancnle self-requested a review August 18, 2023 12:16
@tancnle tancnle added the needs-review The PR needs to be reviewed label Aug 18, 2023
@tancnle
Copy link
Collaborator

tancnle commented Aug 25, 2023

Thank you for your contribution @fcheung 🙇🏼‍♂️ match and case are a bit special in Python. They are called soft keywords. So in the use case highlighted above, they are keywords but not for other, e.g. as variables.

# Keywords
match point:
    case Point(x, y) if x == y:
        print(f"The point is located on the diagonal Y=X at {x}.")
    case Point(x, y):
        print(f"Point is not on the diagonal.")

# Non-keywords
case = 1
match = 1
match if True else bar

We can port these behaviours from Pygments (see related PR).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs-review The PR needs to be reviewed
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants