summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKurt B. Kaiser <kbk@shore.net>2006-07-17 21:59:27 (GMT)
committerKurt B. Kaiser <kbk@shore.net>2006-07-17 21:59:27 (GMT)
commita2f60a47b5e5138f8a7c46226183f372174166c9 (patch)
tree4cb4a19db911f58451adbc1dc04125a014834cb5
parent7a752e7ad46eb50b9016f0a3182c1a5fd84ba047 (diff)
downloadcpython-a2f60a47b5e5138f8a7c46226183f372174166c9.zip
cpython-a2f60a47b5e5138f8a7c46226183f372174166c9.tar.gz
cpython-a2f60a47b5e5138f8a7c46226183f372174166c9.tar.bz2
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
-rw-r--r--Lib/idlelib/ColorDelegator.py30
1 files changed, 18 insertions, 12 deletions
diff --git a/Lib/idlelib/ColorDelegator.py b/Lib/idlelib/ColorDelegator.py
index f258b34..e55f9e6 100644
--- a/Lib/idlelib/ColorDelegator.py
+++ b/Lib/idlelib/ColorDelegator.py
@@ -8,28 +8,29 @@ from configHandler import idleConf
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 @@ class ColorDelegator(Delegator):
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)