Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit d5d2cd1

Browse files
committed
Color all word instances of "as" after "import", & on the same line, as if
keywords. Cheap approximation to the truth.
1 parent 0fdb90c commit d5d2cd1

1 file changed

Lines changed: 13 additions & 0 deletions

File tree

Tools/idle/ColorDelegator.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,15 @@ def make_pat():
2828

2929
prog = re.compile(make_pat(), re.S)
3030
idprog = re.compile(r"\s+(\w+)", re.S)
31+
asprog = re.compile(r".*?\b(as)\b", re.S)
3132

3233
class ColorDelegator(Delegator):
3334

3435
def __init__(self):
3536
Delegator.__init__(self)
3637
self.prog = prog
3738
self.idprog = idprog
39+
self.asprog = asprog
3840

3941
def setdelegate(self, delegate):
4042
if self.delegate is not None:
@@ -198,6 +200,17 @@ def recolorize_main(self):
198200
self.tag_add("DEFINITION",
199201
head + "+%dc" % a,
200202
head + "+%dc" % b)
203+
elif value == "import":
204+
# color all the "as" words on same line;
205+
# cheap approximation to the truth
206+
while 1:
207+
m1 = self.asprog.match(chars, b)
208+
if not m1:
209+
break
210+
a, b = m1.span(1)
211+
self.tag_add("KEYWORD",
212+
head + "+%dc" % a,
213+
head + "+%dc" % b)
201214
m = self.prog.search(chars, m.end())
202215
if "SYNC" in self.tag_names(next + "-1c"):
203216
head = next

0 commit comments

Comments
 (0)