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

Syntax highlighting does not support negative literals #6267

Open
hologerry opened this issue Aug 15, 2024 · 8 comments
Open

Syntax highlighting does not support negative literals #6267

hologerry opened this issue Aug 15, 2024 · 8 comments
Assignees

Comments

@hologerry
Copy link

I am using latest VS Code and Python/Pylance extension on macOS.
The color theme is the Dracula https://github.com/dracula/visual-studio-code
The minus symbol - is not highligted with the numbers.
image
I suggest to add something like this -? at the begin of this regexp.
Like this: (-?[0-9]+)
A similar issue of other extension: hashicorp/vscode-terraform#243

@karthiknadig
Copy link
Member

This is likely coming from MagicPython. Just in case this is not, moving to pylance.

@karthiknadig karthiknadig transferred this issue from microsoft/vscode-python Aug 15, 2024
@github-actions github-actions bot added the needs repro Issue has not been reproduced yet label Aug 15, 2024
@StellaHuang95 StellaHuang95 added textmate bug and removed needs repro Issue has not been reproduced yet labels Aug 16, 2024
@hologerry
Copy link
Author

Hi, @karthiknadig thanks! Hope we can have a solution to this.

@rchiodo
Copy link
Contributor

rchiodo commented Aug 16, 2024

I don't think this is an actual bug. You'd have to change the theme.

That character is identified as keyword.operator.arithmetic

Image

The same as *

Image

So - counts as an operator.

@rchiodo rchiodo closed this as completed Aug 16, 2024
@debonte
Copy link
Contributor

debonte commented Aug 16, 2024

So - counts as an operator.

Counts as an operator in what sense? I see that the TextMate grammar is treating it that way, but I don't think that's true from Python's perspective.

Here's what I see in the Python grammar, which indicates that negative numbers are literals.

literal_pattern:
    | signed_number !('+' | '-') 
    | complex_number 
    | strings 
    | 'None' 
    | 'True' 
    | 'False' 

...

signed_number:
    | NUMBER
    | '-' NUMBER

Then for fun I tried https://github.com/iritkatriel/codoscope and it also indicates that there's no operator call involved here:

image

@rchiodo
Copy link
Contributor

rchiodo commented Aug 16, 2024

Wouldn't the UNARY_NEGATIVE be the operator? Oh I guess that was on X, but not 1. So for -1 it should be a literal but for -x there is an operator involved.

@debonte
Copy link
Contributor

debonte commented Aug 16, 2024

Yeah, I added the y = -x line to compare the two scenarios. Sorry that wasn't clear. The highlighted bytecode instructions on the right side are the entirety of the bytecode for x = -1.

@rchiodo rchiodo changed the title Syntax highlighting does not support negative numbers Syntax highlighting does not support negative literals Aug 16, 2024
@debonte
Copy link
Contributor

debonte commented Aug 16, 2024

Reopening since this is a bug. However, @hologerry, be aware that it may not get fixed anytime soon. See #5824 for some context.

@debonte debonte reopened this Aug 16, 2024
@hologerry
Copy link
Author

Hi @debonte, Thanks for clarifying this! It’s great to know, and I hope we can get a better syntax highlighter in the future.

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

No branches or pull requests

5 participants