-
Notifications
You must be signed in to change notification settings - Fork 744
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
Improve Python lexer #1919
Conversation
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 I will have a look at the PR sometime today. Sorry for the delay 🙇🏼♂️ |
@dunkmann00 Thank you for the contribution. The PR looks great to me.
Please let me know what you think about 2 and 3. 🙏🏼 |
@tancnle The added visual samples look great! I added one more to show that classes also get highlighted when they are created.
|
Thank you for your effort on this @dunkmann00 🙇🏼 🚀 |
Thanks for reviewing, helping, and merging @tancnle! |
This includes three changes to the Python lexer:
Move the
decorator
rule before theoperator
rule.Before this change, decorators were never getting recognized. This
was because if there was ever an
@
, it was always satisfying theoperator
rule. This remedies that by first checking for thedecorator
pattern and then the operator pattern.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.
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.
Remove
self
from@builtins_pseudo
to prevent it from getting styledself
is not a built-in special variable in Python. It is just a local variablethat 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.