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
simplify regexps using re.MULTILINE + more test cases
  • Loading branch information
taleinat committed May 3, 2021
commit ff463a6e03c109a6eb034a1d4ee57a7455d962cc
16 changes: 10 additions & 6 deletions Lib/idlelib/colorizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,16 @@ def any(name, alternates):
def make_pat():
kw = r"\b" + any("KEYWORD", keyword.kwlist) + r"\b"
match_softkw = (
r"(^|(?<=\n))[ \t]*" + # at beginning of string or after \n
r"^[ \t]*" + # at beginning of line + possible indentation
r"(?P<PM_MATCH>match)\b" +
Comment thread
terryjreedy marked this conversation as resolved.
Outdated
r"(?!([ \t]|\\\n)*[=,)\]}])" # not followed by any of =,)]}
)
Comment thread
terryjreedy marked this conversation as resolved.
match_case_default = (
r"(^|(?<=\n))[ \t]*" + # at beginning of string or after \n
r"^[ \t]*" + # at beginning of line + possible indentation
r"(?P<PM_DEFAULT_CASE>case)[ \t]+(?P<PM_DEFAULT_UNDERSCORE>_)[ \t]*:"
Comment thread
terryjreedy marked this conversation as resolved.
Outdated
)
match_case_nondefault = (
r"(^|(?<=\n))[ \t]*" + # at beginning of string or after \n
r"^[ \t]*" + # at beginning of line + possible indentation
r"(?P<PM_NONDEFAULT_CASE>case)\b" +
r"(?!([ \t]|\\\n)*[=,)\]}])" # not followed by any of =,)]}
)
Expand All @@ -48,8 +48,8 @@ def make_pat():
])


prog = re.compile(make_pat(), re.S)
idprog = re.compile(r"\s+(\w+)", re.S)
prog = re.compile(make_pat(), re.DOTALL | re.MULTILINE)
idprog = re.compile(r"\s+(\w+)")
prog_group_name_to_tag = {
"PM_MATCH": "KEYWORD",
"PM_DEFAULT_CASE": "KEYWORD",
Expand Down Expand Up @@ -322,7 +322,7 @@ def _color_delegator(parent): # htest #
top = Toplevel(parent)
top.title("Test ColorDelegator")
x, y = map(int, parent.geometry().split('+')[1:])
top.geometry("700x500+%d+%d" % (x + 20, y + 175))
top.geometry("700x550+%d+%d" % (x + 20, y + 175))
source = textwrap.dedent("""\
Comment thread
terryjreedy marked this conversation as resolved.
Outdated
if True: int ('1') # keyword, builtin, string, comment
elif False: print(0)
Expand All @@ -332,6 +332,10 @@ def _color_delegator(parent): # htest #
async def f(): await g()
# All valid prefixes for unicode and byte strings should be colored.
'x', '''x''', "x", \"""x\"""
'abc\\
def'
'''abc\\
def'''
r'x', u'x', R'x', U'x', f'x', F'x'
fr'x', Fr'x', fR'x', FR'x', rf'x', rF'x', Rf'x', RF'x'
b'x',B'x', br'x',Br'x',bR'x',BR'x', rb'x', rB'x',Rb'x',RB'x'
Expand Down
16 changes: 10 additions & 6 deletions Lib/idlelib/idle_test/test_colorizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@
if'': x or'' # valid string-keyword no-space combinations
async def f(): await g()
'x', '''x''', "x", \"""x\"""
'abc\\
def'
'''abc\\
def'''
match point:
case (x, 0):
print(f"X={x}")
Expand Down Expand Up @@ -379,11 +383,11 @@ def test_recolorize_main(self, mock_notify):
('6.0', ('KEYWORD',)), ('6.10', ('DEFINITION',)), ('6.11', ()),
('7.0', ('STRING',)), ('7.4', ()), ('7.5', ('STRING',)),
('7.12', ()), ('7.14', ('STRING',)),
('8.0', ('KEYWORD',)),
('9.4', ('KEYWORD',)),
('11.4', ('KEYWORD',)), ('11.9', ('KEYWORD',)),
('14.0', ()), ('15.4', ()), ('16.4', ()),
('19.0', ('STRING',)), ('20.1', ('STRING',)),
('12.0', ('KEYWORD',)),
('13.4', ('KEYWORD',)),
('15.4', ('KEYWORD',)), ('15.9', ('KEYWORD',)),
('18.0', ()), ('19.4', ()), ('20.4', ()),
('23.0', ('STRING',)), ('24.1', ('STRING',)),
# SYNC at the end of every line.
('1.55', ('SYNC',)), ('2.50', ('SYNC',)), ('3.34', ('SYNC',)),
)
Expand Down Expand Up @@ -414,7 +418,7 @@ def test_recolorize_main(self, mock_notify):
eq(text.tag_nextrange('STRING', '7.12'), ('7.14', '7.17'))
eq(text.tag_nextrange('STRING', '7.17'), ('7.19', '7.26'))
eq(text.tag_nextrange('SYNC', '7.0'), ('7.26', '8.0'))
eq(text.tag_nextrange('SYNC', '20.0'), ('20.10', '22.0'))
eq(text.tag_nextrange('SYNC', '24.0'), ('24.10', '26.0'))

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