Skip to content
This repository has been archived by the owner on Dec 15, 2022. It is now read-only.

Adds new keywords for match statements #338

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

BekaValentine
Copy link

Description of the Change

This PR adds keywords for the new match statements that were added to Python 3.10.

It does so by making them instances of 'keyword.control.conditional.python'.

Alternate Designs

One alternative option would be to have a separate type for the match statement keywords, however, match statements are arguably a flavor of conditional statement. For example,

match xs:
    case []:
        ...
    case [x,y]:
        ....

is functionally the same as

if type(xs) == list and len(xs) == 0:
    ...
elif type(xs) == list and len(xs) == 2:
    [x,y] = xs
    ...

Benefits

Python 3.10 will highlight correctly in Atom.

Possible Drawbacks

Code for previous versions of Python could have erroneous highlighting.

Applicable Issues

(#335)

@BekaValentine
Copy link
Author

I don't know enough about the testing library to properly implement tests for this, unfortunately.

@BekaValentine
Copy link
Author

@maxbrunsfeld would you be up for reviewing this?

@Yang-Wei-Ting
Copy link

Yang-Wei-Ting commented Jun 3, 2022

I tried your patch and currently everything looks good to me.
Except the print is highlighted as a keyword and built-in exception class is not highlighted.

Before:
image

After:
image

Note: I disabled the built-in language-python 0.53.6 package and cloned language-python master branch (HEAD=fd71825) with your patch applied under .atom/packages directory.

@@ -126,6 +128,8 @@ scopes:
'"if"': 'keyword.control'
'"else"': 'keyword.control'
'"elif"': 'keyword.control'
'"match"': 'keyword.control'
'"case"': 'keyword.control'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do these work when Tree-sitter is enabled? I would think that the Tree-sitter parser would need to be upgraded to have the match and case keywords parsed.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants