Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
7f193fa
modernize ColorDelegator.recolorize_main() code
taleinat May 3, 2021
1b4f728
add htest source example for pattern-matching
taleinat May 3, 2021
f977c50
initial implementation of pattern-matching soft-keyword colorization
taleinat May 3, 2021
df1c1a5
additional test cases for pattern-matching soft keyword colorization
taleinat May 3, 2021
816ea8d
remove dead code comment
taleinat May 3, 2021
146bf70
also ignore match/case immediately followed by )]}
taleinat May 3, 2021
ff463a6
simplify regexps using re.MULTILINE + more test cases
taleinat May 3, 2021
9758870
refactor and mark all lone underscores in case patterns as keywords
taleinat May 6, 2021
4adc318
fix comments in htest code sample
taleinat May 6, 2021
1d9ce7f
handle case guard and capture patterns
taleinat May 6, 2021
21c2f79
use single example source in tests
taleinat May 6, 2021
288fea3
fix highlighting in case guard and capture patterns
taleinat May 6, 2021
2988693
add a NEWS entry
taleinat May 9, 2021
c6015dc
more tests for function defs
taleinat May 9, 2021
68d41fe
improved doc-strings and indentation as per code review
taleinat May 9, 2021
12b7dd5
add test with long multi-line string at beginning of text
taleinat May 9, 2021
4bdbe2a
remove unused import
taleinat May 9, 2021
d550c0f
add more reference links in NEWS entry
taleinat May 9, 2021
ee98cf3
simplify handling of case softkw, and bring back specific handling of…
taleinat May 10, 2021
9a34c3b
add test simulating typing and deleting
taleinat May 10, 2021
25dfd1a
fix highlighting of underscore in case, and its tests
taleinat May 10, 2021
1c87c8a
avoid highlighting match and case in more scenarios (+ tests)
taleinat May 10, 2021
78980da
add info in idle help about soft keyword highlighting
taleinat May 10, 2021
5748063
clean up _assert_highlighting and add a doc-string
taleinat May 10, 2021
6c0f5c2
refactor mocking of notify_range() with _assert_highlighting
taleinat May 10, 2021
4b2b8d7
refactor another test to use _assert_highlighting()
taleinat May 10, 2021
99a67f6
update coverage percentage at head of test file
taleinat May 11, 2021
fae9905
Merge remote-tracking branch 'upstream/main' into idle-colorize-soft-…
taleinat May 11, 2021
b991d56
add a What's New entry
taleinat May 11, 2021
8b4f201
improve wording in NEWS, What's New and docs, and update help.html
taleinat May 11, 2021
ae3e7e1
remove dead code, recently added but no longer used
taleinat May 11, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fix highlighting in case guard and capture patterns
  • Loading branch information
taleinat committed May 6, 2021
commit 288fea305788429caeb5f07013fc894e2626a73b
16 changes: 11 additions & 5 deletions Lib/idlelib/colorizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ def make_pats():
r"(?P<CASE_SOFTKW>case)\b" +
r"(?!(?:[ \t]|\\\n)*[=,)\]}])" + # not followed by any of =,)]}
r"(?P<CASE_PATTERN>.*?)" + # case pattern
r"(?:(?P<CASE_IF>\bif\b).*?)?" + # possible guard
r"(?:(?P<CASE_AS>\bas\b)(?P<CAPTURE_PATTERN>.*?))?" + # possible capture
r"(?P<CASE_IF>\bif\b.*?)?" + # possible guard
r"(?P<CASE_AS>\bas\b.*?)?" + # possible capture
r":"
)
builtinlist = [str(name) for name in dir(builtins)
Expand All @@ -47,13 +47,14 @@ def make_pats():
match_softkw, case_softkw_and_pattern,
any("SYNC", [r"\n"]),
]), re.DOTALL | re.MULTILINE)
guard_prog = re.compile("|".join([builtin, comment, string, kw]))
pattern_prog = re.compile("|".join([
builtin, comment, string, kw, any("UNDERSCORE_SOFTKW", [r"\b_\b"])
]), re.DOTALL)
return prog, pattern_prog
return prog, guard_prog, pattern_prog


prog, pattern_prog = make_pats()
prog, guard_prog, pattern_prog = make_pats()
idprog = re.compile(r"\s+(\w+)")
prog_group_name_to_tag = {
"MATCH_SOFTKW": "KEYWORD",
Expand Down Expand Up @@ -317,11 +318,16 @@ def _add_tags_in_section(self, chars, head):
for m in self.prog.finditer(chars):
for name, matched_text in matched_named_groups(m):
a, b = m.span(name)
if name in {"CASE_PATTERN", "CAPTURE_PATTERN"}:
if name in {"CASE_PATTERN", "CASE_AS"}:
for m1 in pattern_prog.finditer(matched_text):
for name, matched_text in matched_named_groups(m1):
a1, b1 = m1.span()
self._add_tag(a + a1, a + b1, head, name)
elif name == "CASE_IF":
for m1 in guard_prog.finditer(matched_text):
for name, matched_text in matched_named_groups(m1):
a1, b1 = m1.span()
self._add_tag(a + a1, a + b1, head, name)
else:
self._add_tag(a, b, head, name)
if matched_text in ("def", "class"):
Expand Down
10 changes: 7 additions & 3 deletions Lib/idlelib/idle_test/test_colorizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ async def f(): await g()
pass
case _ if _:
raise ValueError("Not a point _")
case _ if ("a" if _ else set()): pass
'''
case _:'''
"match x:"
Comment thread
terryjreedy marked this conversation as resolved.
Expand Down Expand Up @@ -394,8 +395,11 @@ def test_recolorize_main(self, mock_notify):
('23.12', ('KEYWORD',)),
('25.4', ('KEYWORD',)), ('25.9', ('KEYWORD',)), ('25.11', ('KEYWORD',)), ('25.14', (),),
('26.25', ('STRING',)), ('26.38', ('STRING',)),
('28.0', ('STRING',)),
('29.1', ('STRING',)),
('27.4', ('KEYWORD',)), ('27.9', ('KEYWORD',)), ('27.11', ('KEYWORD',)),
('27.15', ('STRING',)), ('27.19', ('KEYWORD',)), ('27.22', ()),
('27.24', ('KEYWORD',)), ('27.29', ('BUILTIN',)), ('27.37', ('KEYWORD',)),
('29.0', ('STRING',)),
('30.1', ('STRING',)),
# SYNC at the end of every line.
('1.55', ('SYNC',)), ('2.50', ('SYNC',)), ('3.34', ('SYNC',)),
)
Expand Down Expand Up @@ -426,7 +430,7 @@ def test_recolorize_main(self, mock_notify):
eq(text.tag_nextrange('STRING', '8.12'), ('8.14', '8.17'))
eq(text.tag_nextrange('STRING', '8.17'), ('8.19', '8.26'))
eq(text.tag_nextrange('SYNC', '8.0'), ('8.26', '9.0'))
eq(text.tag_nextrange('SYNC', '29.0'), ('29.10', '31.0'))
eq(text.tag_nextrange('SYNC', '30.0'), ('30.10', '32.0'))

@mock.patch.object(colorizer.ColorDelegator, 'recolorize')
@mock.patch.object(colorizer.ColorDelegator, 'notify_range')
Expand Down