[Python-checkins] r50692 - python/trunk/Lib/idlelib/ColorDelegator.py
kurt.kaiser
python-checkins at python.org
Mon Jul 17 23:59:28 CEST 2006
Author: kurt.kaiser
Date: Mon Jul 17 23:59:27 2006
New Revision: 50692
Modified:
python/trunk/Lib/idlelib/ColorDelegator.py
Log:
Patch 1479219 - Tal Einat
1. 'as' highlighted as builtin in comment string on import line
2. Comments such as "#False identity" which start with a keyword immediately
after the '#' character aren't colored as comments.
3. u or U beginning unicode string not correctly highlighted
Closes bug 1325071
Modified: python/trunk/Lib/idlelib/ColorDelegator.py
==============================================================================
--- python/trunk/Lib/idlelib/ColorDelegator.py (original)
+++ python/trunk/Lib/idlelib/ColorDelegator.py Mon Jul 17 23:59:27 2006
@@ -8,28 +8,29 @@
DEBUG = False
-def any(name, list):
- return "(?P<%s>" % name + "|".join(list) + ")"
+def any(name, alternates):
+ "Return a named group pattern matching list of alternates."
+ return "(?P<%s>" % name + "|".join(alternates) + ")"
def make_pat():
kw = r"\b" + any("KEYWORD", keyword.kwlist) + r"\b"
builtinlist = [str(name) for name in dir(__builtin__)
if not name.startswith('_')]
# self.file = file("file") :
- # 1st 'file' colorized normal, 2nd as builtin, 3rd as comment
- builtin = r"([^.'\"\\]\b|^)" + any("BUILTIN", builtinlist) + r"\b"
+ # 1st 'file' colorized normal, 2nd as builtin, 3rd as string
+ builtin = r"([^.'\"\\#]\b|^)" + any("BUILTIN", builtinlist) + r"\b"
comment = any("COMMENT", [r"#[^\n]*"])
- sqstring = r"(\b[rR])?'[^'\\\n]*(\\.[^'\\\n]*)*'?"
- dqstring = r'(\b[rR])?"[^"\\\n]*(\\.[^"\\\n]*)*"?'
- sq3string = r"(\b[rR])?'''[^'\\]*((\\.|'(?!''))[^'\\]*)*(''')?"
- dq3string = r'(\b[rR])?"""[^"\\]*((\\.|"(?!""))[^"\\]*)*(""")?'
+ sqstring = r"(\b[rRuU])?'[^'\\\n]*(\\.[^'\\\n]*)*'?"
+ dqstring = r'(\b[rRuU])?"[^"\\\n]*(\\.[^"\\\n]*)*"?'
+ sq3string = r"(\b[rRuU])?'''[^'\\]*((\\.|'(?!''))[^'\\]*)*(''')?"
+ dq3string = r'(\b[rRuU])?"""[^"\\]*((\\.|"(?!""))[^"\\]*)*(""")?'
string = any("STRING", [sq3string, dq3string, sqstring, dqstring])
return kw + "|" + builtin + "|" + comment + "|" + string +\
"|" + any("SYNC", [r"\n"])
prog = re.compile(make_pat(), re.S)
idprog = re.compile(r"\s+(\w+)", re.S)
-asprog = re.compile(r".*?\b(as)\b", re.S)
+asprog = re.compile(r".*?\b(as)\b")
class ColorDelegator(Delegator):
@@ -208,10 +209,15 @@
head + "+%dc" % a,
head + "+%dc" % b)
elif value == "import":
- # color all the "as" words on same line;
- # cheap approximation to the truth
+ # color all the "as" words on same line, except
+ # if in a comment; cheap approximation to the
+ # truth
+ if '#' in chars:
+ endpos = chars.index('#')
+ else:
+ endpos = len(chars)
while True:
- m1 = self.asprog.match(chars, b)
+ m1 = self.asprog.match(chars, b, endpos)
if not m1:
break
a, b = m1.span(1)
More information about the Python-checkins
mailing list