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

Improve Python lexer #1919

Merged
merged 3 commits into from
Feb 1, 2023
Merged

Conversation

dunkmann00
Copy link
Contributor

@dunkmann00 dunkmann00 commented Jan 22, 2023

This includes three changes to the Python lexer:

  1. Move the decorator rule before the operator rule.

    Before this change, decorators were never getting recognized. This
    was because if there was ever an @, it was always satisfying the
    operator rule. This remedies that by first checking for the
    decorator pattern and then the operator pattern.

  2. Recognize functions and classes when they are called.

    Previously, functions and classes were only recognized when they were
    defined. With this change, they will also be recognized and styled
    when they are called.

  3. Don't recognize imported modules as Namespaces.

    It is not desirable to highlight imported modules like namespaces.
    With this change, they are simply recognized as the general Name
    token.

  4. Remove self from @builtins_pseudo to prevent it from getting styled

    self is not a built-in special variable in Python. It is just a local variable
    that is customarily used to indicate the calling object on an instance
    method. As such, it shouldn't be styled the same as actual built-in
    objects.

This includes three changes to the Python lexer:

1) Move the `decorator` rule before the `operator` rule.

   Before this change, decorators were never getting recognized. This
   was because if there was ever an `@`, it was always satisfying the
   `operator` rule. This remedies that by first checking for the
   `decorator` pattern and then the operator pattern.

2) Recognize functions and classes when they are called.

   Previously, functions and classes were only recognized when they were
   defined. With this change, they will also be recognized and styled
   when they are called.

3) Don't recognize imported modules as `Namespace`s.

   It is not desirable to highlight imported modules like namespaces.
   With this change, they are simply recognized as the general `Name`
   token.
@dunkmann00
Copy link
Contributor Author

Hi @tancnle! Any thoughts on this or #1920?

@tancnle
Copy link
Collaborator

tancnle commented Jan 31, 2023

Hi @tancnle! Any thoughts on this or #1920?

@dunkmann00 I will have a look at the PR sometime today. Sorry for the delay 🙇🏼‍♂️

@tancnle tancnle self-requested a review January 31, 2023 00:34
@tancnle tancnle added the needs-review The PR needs to be reviewed label Jan 31, 2023
@tancnle
Copy link
Collaborator

tancnle commented Jan 31, 2023

@dunkmann00 Thank you for the contribution. The PR looks great to me.

  1. See the visual comparison before and after ✨ 🤩
Before After
Screenshot 2023-01-31 at 4 48 02 pm Screenshot 2023-01-31 at 4 48 31 pm
  1. I have added some visual samples to the PR.
  2. I have left a comment on the removal of self.

Please let me know what you think about 2 and 3. 🙏🏼

@tancnle tancnle added author-action The PR has been reviewed but action by the author is needed and removed needs-review The PR needs to be reviewed labels Jan 31, 2023
@dunkmann00
Copy link
Contributor Author

@tancnle The added visual samples look great! I added one more to show that classes also get highlighted when they are created.

Before After
image image

@tancnle tancnle merged commit a218f22 into rouge-ruby:master Feb 1, 2023
@tancnle
Copy link
Collaborator

tancnle commented Feb 1, 2023

Thank you for your effort on this @dunkmann00 🙇🏼 🚀

@dunkmann00
Copy link
Contributor Author

Thanks for reviewing, helping, and merging @tancnle!

@dunkmann00 dunkmann00 deleted the update-python-lexer branch February 2, 2023 01:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
author-action The PR has been reviewed but action by the author is needed
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants