mirror of https://github.com/python/cpython
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
This commit is contained in:
parent
7a752e7ad4
commit
a2f60a47b5
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue