[Python-Dev] IDLE colorizer (original) (raw)
Tim Peters tim.peters at gmail.com
Sun Apr 1 22:20:42 EDT 2018
- Previous message (by thread): [Python-Dev] IDLE colorizer
- Next message (by thread): [Python-Dev] IDLE colorizer
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
[MRAB <python at mrabarnett.plus.com>[
A thread on python-ideas is talking about the prefixes of string literals, and the regex used in IDLE.
Line 25 of Lib\idlelib\colorizer.py is: stringprefix = r"(?i:\br|u|f|fr|rf|b|br|rb)?" which looks slightly wrong to me. The \b will apply only to the first choice. Shouldn't it be more like: stringprefix = r"(?:\b(?i:r|u|f|fr|rf|b|br|rb))?" ?
I believe the change would capture its real intent. It doesn't seem to matter a whole lot, though - IDLE isn't a syntax checker, and applies heuristics to color on the fly based on best guesses. As is, if you type this fragment into an IDLE shell:
kr"sdf"
only the last 5 characters get "string colored", presumably because of the leading \br in the original regexp. But if you type in
ku"sdf"
the last 6 characters get "string colored", because - as you pointed out - the \b part of the original regexp has no effect on anything other than the r following \b.
But in neither case is the fragment legit Python. If you do type in legit Python, it makes no difference (legit string literals always start at a word boundary, regardless of whether the regexp checks for that).
- Previous message (by thread): [Python-Dev] IDLE colorizer
- Next message (by thread): [Python-Dev] IDLE colorizer
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]