Sublime Forum

Python multiline/f-string/r-string syntax highlighting

#1

In Python syntax highlighting, is the red in the last example (the combination of multiline, f-string, and r-string) a known bug?

0 Likes

#2

Thanks for the report. No, this wasn’t a known bug, but I just submitted a fix that will likely be included in the next release.

0 Likes

#3

Thank you!

0 Likes

#4

just out of curiosity (aka: OCD), what is the syntax rule for these strings anyway? the ALT+CTRL+SHIFT+P reveals nothing. asking because i can’t get it to highlight at all, not even with the BracketHighlighter plugin.
apologies if this is in the wrong spot. otherwise, TIA.

0 Likes

#5

Could you clarify on your issues? ctrl+alt+shift+p should work perfectly fine and there certainly should be highlighting for strings, unless you either use a broken syntax definition instead of the default Python one, or your color scheme defines no colors. From your description, it looks more like the former, so please confirm that by typing view.settings().get('syntax') in the ST console.

0 Likes

#6

sure. the syntax is PythonImproved. CTRL+ALT+SHIFT+P simply shows source.python. not very illuminating. and here is what i am trying to highlight:

str2 = r```\
    multiline string
    goes in here
```

the highlighting neither works for ‘r’, ‘f’, nor straight ```. i thought it would be something that the MatchingBrackets might handle, but there is nothing in there for this either. :stuck_out_tongue:

granted, my theme does not have rules, but then, no theme i have found does. so that’s why i’m wondering what the syntax rules are for it since i’ve been unable to find them as yet. :mag_right:

if you need more clarification, please ask. happy to provide if it helps someone else as well down the road. :slight_smile:

EDIT: would be nice to know where the rules actually are… i’m sure they are out there somewhere, but my DuckDuckFoo is apparently trash… :confused:

0 Likes

#7

The syntax in that package was last touched two years ago; you will perhaps have better luck going back to the version that ships with Sublime, which is more actively maintained (@FichteFoll is one of the main contributors to that package).

0 Likes

#8

Also, I hope the use of backticks there is a mistake because those are invalid in Python 3 and do something entirely different in Python 2 and instead you were looking for single quotes '. Other than that, I highly recommend using the default Python syntax from a recent Sublime Text build (and to report any issues you encounter, so I can fix them).

0 Likes

#9

yes. backticks were a mistake. i do use single quotes there instead. and i have much more highlighting success with than with the latest update, which i have. but i’ll take a look at how my rules are set up. the theme i’m using has been around for several years. where are the syntax rules located? do you have a URL?

EDIT: for some reason my pyLinter was causing problems. don’t know if it’s connected, but i removed it and ‘boink’, highlighting came back on. weird…

0 Likes

#10

quick followup: highlighting working well with PythonImproved. horribly broken with default Python. looks like the syntax rules have changed significantly and since i don’t know where they are located, i’m sticking with the PythonImproved. rewriting 1000 lines of syntax rules without a reference is futility. but thank you for providing the nudges needed to figure out why things weren’t working. :slight_smile: very much appreciated!

0 Likes

#11

Would you be so kind to show an example of higlighting going wrong?

0 Likes

#12

you bet. here you go; first is PythonImroved syntax, the second one is just Python syntax:

ST3-PythonImproved-Syntax ST3-Python-Syntax

0 Likes

#13

what color scheme are you using? try a standard one to compare it with - its likely not the syntax definition at fault but the color scheme

0 Likes

#14

That difference is certainly suspicious. The example file uses common syntax that the default definition should highlight flawlessly. You either have a color scheme with very specific scopes that favor PythonImproved or use a different python syntax for the default version, because I don’t think it has ever looked like this.

Please try with a default color scheme, as Keith suggested.

0 Likes