Skip to content

Commit a24f5be

Browse files
f4nb0ychrisbra
authored andcommitted
runtime(python): highlight bytes in python
- Highlight bytes literals - Do not highlight Unicode escape sequences in bytes literals fixes: vim#14033 fixes: vim#17726 closes: vim#17728 Signed-off-by: Rob B <[email protected]> Signed-off-by: Christian Brabandt <[email protected]>
1 parent baa781a commit a24f5be

File tree

8 files changed

+245
-7
lines changed

8 files changed

+245
-7
lines changed

runtime/syntax/python.vim

Lines changed: 35 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
" Vim syntax file
22
" Language: Python
33
" Maintainer: Zvezdan Petkovic <[email protected]>
4-
" Last Change: 2023 Feb 28
4+
" Last Change: 2025 Jul 14
55
" Credits: Neil Schemenauer <[email protected]>
66
" Dmitry Vasiliev
7+
" Rob B
78
"
89
" This version is a major rewrite by Zvezdan Petkovic.
910
"
@@ -144,24 +145,48 @@ syn keyword pythonTodo FIXME NOTE NOTES TODO XXX contained
144145
" Triple-quoted strings can contain doctests.
145146
syn region pythonString matchgroup=pythonQuotes
146147
\ start=+[uU]\=\z(['"]\)+ end="\z1" skip="\\\\\|\\\z1"
147-
\ contains=pythonEscape,@Spell
148+
\ contains=pythonEscape,pythonUnicodeEscape,@Spell
148149
syn region pythonString matchgroup=pythonTripleQuotes
149150
\ start=+[uU]\=\z('''\|"""\)+ end="\z1" keepend
150-
\ contains=pythonEscape,pythonSpaceError,pythonDoctest,@Spell
151+
\ contains=pythonEscape,pythonUnicodeEscape,pythonSpaceError,pythonDoctest,@Spell
151152
syn region pythonRawString matchgroup=pythonQuotes
152-
\ start=+[uU]\=[rR]\z(['"]\)+ end="\z1" skip="\\\\\|\\\z1"
153+
\ start=+[rR]\z(['"]\)+ end="\z1" skip="\\\\\|\\\z1"
153154
\ contains=@Spell
154155
syn region pythonRawString matchgroup=pythonTripleQuotes
155-
\ start=+[uU]\=[rR]\z('''\|"""\)+ end="\z1" keepend
156+
\ start=+[rR]\z('''\|"""\)+ end="\z1" keepend
156157
\ contains=pythonSpaceError,pythonDoctest,@Spell
157158

159+
" Bytes
160+
syn region pythonBytes
161+
\ matchgroup=pythonQuotes
162+
\ start=+\cB\z(['"]\)+
163+
\ end="\z1"
164+
\ skip="\\\\\|\\\z1"
165+
\ contains=pythonEscape
166+
syn region pythonBytes
167+
\ matchgroup=pythonTripleQuotes
168+
\ start=+\cB\z('''\|"""\)+
169+
\ end="\z1"
170+
\ keepend
171+
\ contains=pythonEscape
172+
syn region pythonRawBytes
173+
\ matchgroup=pythonQuotes
174+
\ start=+\c\%(BR\|RB\)\z(['"]\)+
175+
\ end="\z1"
176+
\ skip="\\\\\|\\\z1"
177+
syn region pythonRawBytes
178+
\ matchgroup=pythonTripleQuotes
179+
\ start=+\c\%(BR\|RB\)\z('''\|"""\)+
180+
\ end="\z1"
181+
\ keepend
182+
158183
syn match pythonEscape +\\[abfnrtv'"\\]+ contained
159184
syn match pythonEscape "\\\o\{1,3}" contained
160185
syn match pythonEscape "\\x\x\{2}" contained
161-
syn match pythonEscape "\%(\\u\x\{4}\|\\U\x\{8}\)" contained
186+
syn match pythonUnicodeEscape "\%(\\u\x\{4}\|\\U\x\{8}\)" contained
162187
" Python allows case-insensitive Unicode IDs: http://www.unicode.org/charts/
163188
" The specification: https://www.unicode.org/versions/Unicode16.0.0/core-spec/chapter-4/#G135165
164-
syn match pythonEscape "\\N{\a\+\%(\%(\s\a\+[[:alnum:]]*\)\|\%(-[[:alnum:]]\+\)\)*}" contained
189+
syn match pythonUnicodeEscape "\\N{\a\+\%(\%(\s\a\+[[:alnum:]]*\)\|\%(-[[:alnum:]]\+\)\)*}" contained
165190
syn match pythonEscape "\\$"
166191

167192
" It is very important to understand all details before changing the
@@ -313,9 +338,12 @@ hi def link pythonComment Comment
313338
hi def link pythonTodo Todo
314339
hi def link pythonString String
315340
hi def link pythonRawString String
341+
hi def link pythonBytes String
342+
hi def link pythonRawBytes String
316343
hi def link pythonQuotes String
317344
hi def link pythonTripleQuotes pythonQuotes
318345
hi def link pythonEscape Special
346+
hi def link pythonUnicodeEscape pythonEscape
319347
if !exists("python_no_number_highlight")
320348
hi def link pythonNumber Number
321349
endif
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
>#+0#0000e05#ffffff0| |S|t|r|i|n|g| |a|n|d| |B|y|t|e|s| |l|i|t|e|r|a|l|s| +0#0000000&@47
2+
|#+0#0000e05&| |h|t@1|p|s|:|/@1|d|o|c|s|.|p|y|t|h|o|n|.|o|r|g|/|3|/|r|e|f|e|r|e|n|c|e|/|l|e|x|i|c|a|l|_|a|n|a|l|y|s|i|s|.|h|t|m|l|#|s|t|r|i|n|g|-|a|n|d|-|b|y|t|e
3+
|s|-|l|i|t|e|r|a|l|s| +0#0000000&@64
4+
@75
5+
|#+0#0000e05&| |S|t|r|i|n|g|s| +0#0000000&@65
6+
|t|e|s|t| |=| |'+0#e000002&|S|t|r|i|n|g| |w|i|t|h| |e|s|c|a|p|e|s| |\+0#e000e06&|'| +0#e000002&|a|n|d| |\+0#e000e06&|"| +0#e000002&|a|n|d| |\+0#e000e06&|t|'+0#e000002&| +0#0000000&@29
7+
|t|e|s|t| |=| |"+0#e000002&|S|t|r|i|n|g| |w|i|t|h| |e|s|c|a|p|e|s| |\+0#e000e06&|0|4|0| +0#e000002&|a|n|d| |\+0#e000e06&|x|F@1|"+0#e000002&| +0#0000000&@32
8+
|t|e|s|t| |=| |'+0#e000002&|S|t|r|i|n|g| |w|i|t|h| |e|s|c|a|p|e|s| |\+0#e000e06&|u|0@1|A|1| +0#e000002&|a|n|d| |\+0#e000e06&|U|0@2|1|0|6|0|5| +0#e000002&|a|n|d| |\+0#e000e06&|N|{|I|N|V|E|R|T|E|D| |E|X|C|L|A|M|A|T|I
9+
|O|N| |M|A|R|K|}|'+0#e000002&| +0#0000000&@65
10+
|t|e|s|t| |=| |"+0#e000002&|S|t|r|i|n|g| |w|i|t|h| |e|s|c|a|p|e|d| |\+0#e000e06&@1| +0#e000002&|b|a|c|k|s|l|a|s|h| |a|n|d| |i|g|n|o|r|e|d| |\+0#e000e06&| +0#0000000&@20
11+
|n+0#e000002&|e|w|l|i|n|e|"| +0#0000000&@66
12+
|t|e|s|t| |=| |'+0#e000002&@2|S|t|r|i|n|g| |w|i|t|h| |q|u|o|t|e|s| |'| |a|n|d| |"| +0#0000000&@38
13+
|a+0#e000002&|n|d| |e|s|c|a|p|e|s| |\+0#e000e06&|t| +0#e000002&|a|n|d| |\+0#e000e06&|0|4|0| +0#e000002&|a|n|d| |\+0#e000e06&|x|F@1| +0#0000000&@42
14+
|a+0#e000002&|n|d| |e|s|c|a|p|e|s| |\+0#e000e06&|u|0@1|A|1| +0#e000002&|a|n|d| |\+0#e000e06&|U|0@2|1|0|6|0|5|'+0#e000002&@2| +0#0000000&@38
15+
|t|e|s|t| |=| |"+0#e000002&@2|S|t|r|i|n|g| |w|i|t|h| |q|u|o|t|e|s| |'| |a|n|d| |"| +0#0000000&@38
16+
|a+0#e000002&|n|d| |e|s|c|a|p|e|s| |\+0#e000e06&|t| +0#e000002&|a|n|d| |\+0#e000e06&|0|4|0| +0#e000002&|a|n|d| |\+0#e000e06&|x|F@1| +0#0000000&@42
17+
|a+0#e000002&|n|d| |e|s|c|a|p|e|s| |\+0#e000e06&|u|0@1|A|1| +0#e000002&|a|n|d| |\+0#e000e06&|U|0@2|1|0|6|0|5|"+0#e000002&@2| +0#0000000&@38
18+
@75
19+
|#+0#0000e05&| |R|a|w| |s|t|r|i|n|g|s| +0#0000000&@61
20+
@57|1|,|1| @10|T|o|p|
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
|a+0#e000002#ffffff0|n|d| |e|s|c|a|p|e|s| |\+0#e000e06&|u|0@1|A|1| +0#e000002&|a|n|d| |\+0#e000e06&|U|0@2|1|0|6|0|5|'+0#e000002&@2| +0#0000000&@38
2+
|t|e|s|t| |=| |"+0#e000002&@2|S|t|r|i|n|g| |w|i|t|h| |q|u|o|t|e|s| |'| |a|n|d| |"| +0#0000000&@38
3+
|a+0#e000002&|n|d| |e|s|c|a|p|e|s| |\+0#e000e06&|t| +0#e000002&|a|n|d| |\+0#e000e06&|0|4|0| +0#e000002&|a|n|d| |\+0#e000e06&|x|F@1| +0#0000000&@42
4+
|a+0#e000002&|n|d| |e|s|c|a|p|e|s| |\+0#e000e06&|u|0@1|A|1| +0#e000002&|a|n|d| |\+0#e000e06&|U|0@2|1|0|6|0|5|"+0#e000002&@2| +0#0000000&@38
5+
@75
6+
>#+0#0000e05&| |R|a|w| |s|t|r|i|n|g|s| +0#0000000&@61
7+
|t|e|s|t| |=| |r+0#e000002&|'|R|a|w| |s|t|r|i|n|g| |w|i|t|h| |l|i|t|e|r|a|l| |\|'| |a|n|d| |\|"| |a|n|d| |\|t|'| +0#0000000&@24
8+
|t|e|s|t| |=| |R+0#e000002&|"|R|a|w| |s|t|r|i|n|g| |w|i|t|h| |l|i|t|e|r|a|l| |\|0|4|0| |a|n|d| |\|x|F@1|"| +0#0000000&@27
9+
|t|e|s|t| |=| |r+0#e000002&|'|R|a|w| |s|t|r|i|n|g| |w|i|t|h| |l|i|t|e|r|a|l| |\|u|0@1|A|1| |a|n|d| |\|U|0@2|1|0|6|0|5| |a|n|d| |\|N|{|I|N|V|E|R|T|E|D| |E|X|C|L
10+
|A|M|A|T|I|O|N| |M|A|R|K|}|'| +0#0000000&@60
11+
|t|e|s|t| |=| |R+0#e000002&|"|R|a|w| |s|t|r|i|n|g| |w|i|t|h| |l|i|t|e|r|a|l| |\@1| |b|a|c|k|s|l|a|s|h|e|s| |a|n|d| |l|i|t|e|r|a|l| |\| +0#0000000&@13
12+
|n+0#e000002&|e|w|l|i|n|e|"| +0#0000000&@66
13+
|t|e|s|t| |=| |r+0#e000002&|'@2|R|a|w| |s|t|r|i|n|g| |w|i|t|h| |q|u|o|t|e|s| |'| |a|n|d| |"| +0#0000000&@33
14+
|a+0#e000002&|n|d| |l|i|t|e|r|a|l| |\|t| |a|n|d| |\|0|4|0| |a|n|d| |\|x|F@1| +0#0000000&@42
15+
|a+0#e000002&|n|d| |l|i|t|e|r|a|l| |\|u|0@1|A|1| |a|n|d| |\|U|0@2|1|0|6|0|5|'@2| +0#0000000&@38
16+
|t|e|s|t| |=| |R+0#e000002&|"@2|R|a|w| |s|t|r|i|n|g| |w|i|t|h| |q|u|o|t|e|s| |'| |a|n|d| |"| +0#0000000&@33
17+
|a+0#e000002&|n|d| |l|i|t|e|r|a|l| |\|t| |a|n|d| |\|0|4|0| |a|n|d| |\|x|F@1| +0#0000000&@42
18+
|a+0#e000002&|n|d| |l|i|t|e|r|a|l| |\|u|0@1|A|1| |a|n|d| |\|U|0@2|1|0|6|0|5|"@2| +0#0000000&@38
19+
@75
20+
@57|1|7|,|1| @9|1|5|%|
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
| +0&#ffffff0@74
2+
|#+0#0000e05&| |B|y|t|e|s| +0#0000000&@67
3+
|t|e|s|t| |=| |b+0#e000002&|'|B|y|t|e|s| |w|i|t|h| |e|s|c|a|p|e|s| |\+0#e000e06&|'| +0#e000002&|a|n|d| |\+0#e000e06&|"| +0#e000002&|a|n|d| |\+0#e000e06&|t|'+0#e000002&| +0#0000000&@29
4+
|t|e|s|t| |=| |B+0#e000002&|"|B|y|t|e|s| |w|i|t|h| |e|s|c|a|p|e|s| |\+0#e000e06&|0|4|0| +0#e000002&|a|n|d| |\+0#e000e06&|x|F@1|"+0#e000002&| +0#0000000&@32
5+
|t|e|s|t| |=| |b+0#e000002&|'|B|y|t|e|s| |w|i|t|h| |l|i|t|e|r|a|l| |\|u|0@1|A|1| |a|n|d| |\|U|0@2|1|0|6|0|5| |a|n|d| |\|N|{|I|N|V|E|R|T|E|D| |E|X|C|L|A|M|A|T|I
6+
|O|N| |M|A|R|K|}|'| +0#0000000&@65
7+
>t|e|s|t| |=| |B+0#e000002&|"|B|y|t|e|s| |w|i|t|h| |e|s|c|a|p|e|d| |\+0#e000e06&@1| +0#e000002&|b|a|c|k|s|l|a|s|h| |a|n|d| |i|g|n|o|r|e|d| |\+0#e000e06&| +0#0000000&@20
8+
|n+0#e000002&|e|w|l|i|n|e|"| +0#0000000&@66
9+
|t|e|s|t| |=| |b+0#e000002&|'@2|B|y|t|e|s| |w|i|t|h| |q|u|o|t|e|s| |'| |a|n|d| |"| +0#0000000&@38
10+
|a+0#e000002&|n|d| |e|s|c|a|p|e|s| |\+0#e000e06&|t| +0#e000002&|a|n|d| |\+0#e000e06&|0|4|0| +0#e000002&|a|n|d| |\+0#e000e06&|x|F@1| +0#0000000&@42
11+
|a+0#e000002&|n|d| |l|i|t|e|r|a|l| |\|u|0@1|A|1| |a|n|d| |\|U|0@2|1|0|6|0|5|'@2| +0#0000000&@38
12+
|t|e|s|t| |=| |B+0#e000002&|"@2|B|y|t|e|s| |w|i|t|h| |q|u|o|t|e|s| |'| |a|n|d| |"| +0#0000000&@38
13+
|a+0#e000002&|n|d| |e|s|c|a|p|e|s| |\+0#e000e06&|t| +0#e000002&|a|n|d| |\+0#e000e06&|0|4|0| +0#e000002&|a|n|d| |\+0#e000e06&|x|F@1| +0#0000000&@42
14+
|a+0#e000002&|n|d| |l|i|t|e|r|a|l| |\|u|0@1|A|1| |a|n|d| |\|U|0@2|1|0|6|0|5|"@2| +0#0000000&@38
15+
@75
16+
|#+0#0000e05&| |R|a|w| |b|y|t|e|s| +0#0000000&@63
17+
|t|e|s|t| |=| |b+0#e000002&|r|'|R|a|w| |b|y|t|e|s| |w|i|t|h| |l|i|t|e|r|a|l| |\|'| |a|n|d| |\|"| |a|n|d| |\|t|'| +0#0000000&@24
18+
|t|e|s|t| |=| |b+0#e000002&|R|"|R|a|w| |b|y|t|e|s| |w|i|t|h| |l|i|t|e|r|a|l| |\|0|4|0| |a|n|d| |\|x|F@1|"| +0#0000000&@27
19+
|t|e|s|t| |=| |B+0#e000002&|r|'|R|a|w| |b|y|t|e|s| |w|i|t|h| |l|i|t|e|r|a|l| |\|u|0@1|A|1| |a|n|d| |\|U|0@2|1|0|6|0|5| |a|n|d| |\|N|{|I|N|V|E|R|T|E|D| |E|@+0#4040ff13&@2
20+
| +0#0000000&@56|3|4|,|1| @9|3|8|%|
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
|t+0&#ffffff0|e|s|t| |=| |B+0#e000002&|r|'|R|a|w| |b|y|t|e|s| |w|i|t|h| |l|i|t|e|r|a|l| |\|u|0@1|A|1| |a|n|d| |\|U|0@2|1|0|6|0|5| |a|n|d| |\|N|{|I|N|V|E|R|T|E|D| |E|X|C|L
2+
|A|M|A|T|I|O|N| |M|A|R|K|}|'| +0#0000000&@60
3+
|t|e|s|t| |=| |B+0#e000002&|R|"|R|a|w| |b|y|t|e|s| |w|i|t|h| |l|i|t|e|r|a|l| |\@1| |b|a|c|k|s|l|a|s|h|e|s| |a|n|d| |l|i|t|e|r|a|l| |\| +0#0000000&@13
4+
|n+0#e000002&|e|w|l|i|n|e|"| +0#0000000&@66
5+
|t|e|s|t| |=| |r+0#e000002&|b|'|R|a|w| |b|y|t|e|s| |w|i|t|h| |l|i|t|e|r|a|l| |\|'| |a|n|d| |\|"| |a|n|d| |\|t|'| +0#0000000&@24
6+
>t|e|s|t| |=| |r+0#e000002&|B|"|R|a|w| |b|y|t|e|s| |w|i|t|h| |l|i|t|e|r|a|l| |\|0|4|0| |a|n|d| |\|x|F@1|"| +0#0000000&@27
7+
|t|e|s|t| |=| |R+0#e000002&|b|'|R|a|w| |b|y|t|e|s| |w|i|t|h| |l|i|t|e|r|a|l| |\|u|0@1|A|1| |a|n|d| |\|U|0@2|1|0|6|0|5| |a|n|d| |\|N|{|I|N|V|E|R|T|E|D| |E|X|C|L
8+
|A|M|A|T|I|O|N| |M|A|R|K|}|'| +0#0000000&@60
9+
|t|e|s|t| |=| |R+0#e000002&|B|"|R|a|w| |b|y|t|e|s| |w|i|t|h| |l|i|t|e|r|a|l| |\@1| |b|a|c|k|s|l|a|s|h|e|s| |a|n|d| |l|i|t|e|r|a|l| |\| +0#0000000&@13
10+
|n+0#e000002&|e|w|l|i|n|e|"| +0#0000000&@66
11+
|t|e|s|t| |=| |b+0#e000002&|r|'@2|R|a|w| |b|y|t|e|s| |w|i|t|h| |q|u|o|t|e|s| |'| |a|n|d| |"| +0#0000000&@33
12+
|a+0#e000002&|n|d| |l|i|t|e|r|a|l| |\|t| |a|n|d| |\|0|4|0| |a|n|d| |\|x|F@1| +0#0000000&@42
13+
|a+0#e000002&|n|d| |l|i|t|e|r|a|l| |\|u|0@1|A|1| |a|n|d| |\|U|0@2|1|0|6|0|5|'@2| +0#0000000&@38
14+
|t|e|s|t| |=| |R+0#e000002&|B|"@2|R|a|w| |b|y|t|e|s| |w|i|t|h| |q|u|o|t|e|s| |'| |a|n|d| |"| +0#0000000&@33
15+
|a+0#e000002&|n|d| |l|i|t|e|r|a|l| |\|t| |a|n|d| |\|0|4|0| |a|n|d| |\|x|F@1| +0#0000000&@42
16+
|a+0#e000002&|n|d| |l|i|t|e|r|a|l| |\|u|0@1|A|1| |a|n|d| |\|U|0@2|1|0|6|0|5|"@2| +0#0000000&@38
17+
@75
18+
|#+0#0000e05&| |U|n|i|c|o|d|e| |l|i|t|e|r|a|l|s|:| |P|r|e|f|i|x| |i|s| |a|l@1|o|w|e|d| |b|u|t| |i|g|n|o|r|e|d| |(|h|t@1|p|s|:|/@1|p|e|p|s|.|p|y|t|h|o|n|.|o|r|g|/
19+
|p|e|p|-|0|4|1|4|)| +0#0000000&@65
20+
@57|5|0|,|1| @9|6|0|%|
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
|#+0#0000e05#ffffff0| |U|n|i|c|o|d|e| |l|i|t|e|r|a|l|s|:| |P|r|e|f|i|x| |i|s| |a|l@1|o|w|e|d| |b|u|t| |i|g|n|o|r|e|d| |(|h|t@1|p|s|:|/@1|p|e|p|s|.|p|y|t|h|o|n|.|o|r|g|/
2+
|p|e|p|-|0|4|1|4|)| +0#0000000&@65
3+
|t|e|s|t| |=| |u+0#e000002&|'|S|t|r|i|n|g| |w|i|t|h| |e|s|c|a|p|e|s| |\+0#e000e06&|'| +0#e000002&|a|n|d| |\+0#e000e06&|"| +0#e000002&|a|n|d| |\+0#e000e06&|t|'+0#e000002&| +0#0000000&@28
4+
|t|e|s|t| |=| |U+0#e000002&|"|S|t|r|i|n|g| |w|i|t|h| |e|s|c|a|p|e|s| |\+0#e000e06&|0|4|0| +0#e000002&|a|n|d| |\+0#e000e06&|x|F@1|"+0#e000002&| +0#0000000&@31
5+
|t|e|s|t| |=| |u+0#e000002&|'|S|t|r|i|n|g| |w|i|t|h| |e|s|c|a|p|e|s| |\+0#e000e06&|u|0@1|A|1| +0#e000002&|a|n|d| |\+0#e000e06&|U|0@2|1|0|6|0|5| +0#e000002&|a|n|d| |\+0#e000e06&|N|{|I|N|V|E|R|T|E|D| |E|X|C|L|A|M|A|T
6+
|I|O|N| |M|A|R|K|}|'+0#e000002&| +0#0000000&@64
7+
>t|e|s|t| |=| |U+0#e000002&|"|S|t|r|i|n|g| |w|i|t|h| |e|s|c|a|p|e|d| |\+0#e000e06&@1| +0#e000002&|b|a|c|k|s|l|a|s|h| |a|n|d| |i|g|n|o|r|e|d| |\+0#e000e06&| +0#0000000&@19
8+
|n+0#e000002&|e|w|l|i|n|e|"| +0#0000000&@66
9+
|t|e|s|t| |=| |u+0#e000002&|'@2|S|t|r|i|n|g| |w|i|t|h| |q|u|o|t|e|s| |'| |a|n|d| |"| +0#0000000&@37
10+
|a+0#e000002&|n|d| |e|s|c|a|p|e|s| |\+0#e000e06&|t| +0#e000002&|a|n|d| |\+0#e000e06&|0|4|0| +0#e000002&|a|n|d| |\+0#e000e06&|x|F@1| +0#0000000&@42
11+
|a+0#e000002&|n|d| |e|s|c|a|p|e|s| |\+0#e000e06&|u|0@1|A|1| +0#e000002&|a|n|d| |\+0#e000e06&|U|0@2|1|0|6|0|5|'+0#e000002&@2| +0#0000000&@38
12+
|t|e|s|t| |=| |U+0#e000002&|"@2|S|t|r|i|n|g| |w|i|t|h| |q|u|o|t|e|s| |'| |a|n|d| |"| +0#0000000&@37
13+
|a+0#e000002&|n|d| |e|s|c|a|p|e|s| |\+0#e000e06&|t| +0#e000002&|a|n|d| |\+0#e000e06&|0|4|0| +0#e000002&|a|n|d| |\+0#e000e06&|x|F@1| +0#0000000&@42
14+
|a+0#e000002&|n|d| |e|s|c|a|p|e|s| |\+0#e000e06&|u|0@1|A|1| +0#e000002&|a|n|d| |\+0#e000e06&|U|0@2|1|0|6|0|5|"+0#e000002&@2| +0#0000000&@38
15+
@75
16+
|#+0#0000e05&| |R|a|w| |U|n|i|c|o|d|e| |l|i|t|e|r|a|l|s| |a|r|e| |n|o|t| |a|l@1|o|w|e|d| +0#0000000&@36
17+
|t|e|s|t| |=| |u|r+0#e000002&|'|I|n|v|a|l|i|d| |s|t|r|i|n|g| |w|i|t|h| |\|'| |a|n|d| |\|"| |a|n|d| |\|t|'| +0#0000000&@27
18+
|t|e|s|t| |=| |u|R+0#e000002&|"|I|n|v|a|l|i|d| |s|t|r|i|n|g| |w|i|t|h| |\|0|4|0| |a|n|d| |\|x|F@1|"| +0#0000000&@30
19+
|t|e|s|t| |=| |U|r+0#e000002&|'|I|n|v|a|l|i|d| |s|t|r|i|n|g| |w|i|t|h| |\|u|0@1|A|1| |a|n|d| |\|U|0@2|1|0|6|0|5| |a|n|d| |\|N|{|I|N|V|E|R|T|E|D| |E|X|C|L|@+0#4040ff13&@2
20+
| +0#0000000&@56|6|5|,|1| @9|8|1|%|
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
|t+0&#ffffff0|e|s|t| |=| |U|r+0#e000002&|'|I|n|v|a|l|i|d| |s|t|r|i|n|g| |w|i|t|h| |\|u|0@1|A|1| |a|n|d| |\|U|0@2|1|0|6|0|5| |a|n|d| |\|N|{|I|N|V|E|R|T|E|D| |E|X|C|L|A|M|A
2+
|T|I|O|N| |M|A|R|K|}|'| +0#0000000&@63
3+
|t|e|s|t| |=| |U|R+0#e000002&|"|I|n|v|a|l|i|d| |s|t|r|i|n|g| |w|i|t|h| |\@1| |b|a|c|k|s|l|a|s|h|e|s| |a|n|d| |l|i|t|e|r|a|l| |\| +0#0000000&@16
4+
|n+0#e000002&|e|w|l|i|n|e|"| +0#0000000&@66
5+
|t|e|s|t| |=| |r|u+0#e000002&|'|I|n|v|a|l|i|d| |s|t|r|i|n|g| |w|i|t|h| |\+0#e000e06&|'| +0#e000002&|a|n|d| |\+0#e000e06&|"| +0#e000002&|a|n|d| |\+0#e000e06&|t|'+0#e000002&| +0#0000000&@27
6+
>t|e|s|t| |=| |r|U+0#e000002&|"|I|n|v|a|l|i|d| |s|t|r|i|n|g| |w|i|t|h| |\+0#e000e06&|0|4|0| +0#e000002&|a|n|d| |\+0#e000e06&|x|F@1|"+0#e000002&| +0#0000000&@30
7+
|t|e|s|t| |=| |R|u+0#e000002&|'|I|n|v|a|l|i|d| |s|t|r|i|n|g| |w|i|t|h| |\+0#e000e06&|u|0@1|A|1| +0#e000002&|a|n|d| |\+0#e000e06&|U|0@2|1|0|6|0|5| +0#e000002&|a|n|d| |\+0#e000e06&|N|{|I|N|V|E|R|T|E|D| |E|X|C|L|A|M|A
8+
|T|I|O|N| |M|A|R|K|}|'+0#e000002&| +0#0000000&@63
9+
|t|e|s|t| |=| |R|U+0#e000002&|"|I|n|v|a|l|i|d| |s|t|r|i|n|g| |w|i|t|h| |\+0#e000e06&@1| +0#e000002&|b|a|c|k|s|l|a|s|h|e|s| |a|n|d| |l|i|t|e|r|a|l| |\+0#e000e06&| +0#0000000&@16
10+
|n+0#e000002&|e|w|l|i|n|e|"| +0#0000000&@66
11+
|t|e|s|t| |=| |u|r+0#e000002&|'@2|I|n|v|a|l|i|d| |s|t|r|i|n|g| |w|i|t|h| |'| |a|n|d| |"| +0#0000000&@35
12+
|a+0#e000002&|n|d| |\|t| |a|n|d| |\|0|4|0| |a|n|d| |\|x|F@1| +0#0000000&@50
13+
|a+0#e000002&|n|d| |\|u|0@1|A|1| |a|n|d| |\|U|0@2|1|0|6|0|5|'@2| +0#0000000&@46
14+
|t|e|s|t| |=| |R|U+0#e000002&|"@2|I|n|v|a|l|i|d| |s|t|r|i|n|g| |w|i|t|h| |'| |a|n|d| |"| +0#0000000&@35
15+
|a+0#e000002&|n|d| |\+0#e000e06&|t| +0#e000002&|a|n|d| |\+0#e000e06&|0|4|0| +0#e000002&|a|n|d| |\+0#e000e06&|x|F@1| +0#0000000&@50
16+
|a+0#e000002&|n|d| |\+0#e000e06&|u|0@1|A|1| +0#e000002&|a|n|d| |\+0#e000e06&|U|0@2|1|0|6|0|5|"+0#e000002&@2| +0#0000000&@46
17+
|~+0#4040ff13&| @73
18+
|~| @73
19+
|~| @73
20+
| +0#0000000&@56|8|1|,|1| @9|B|o|t|
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
# String and Bytes literals
2+
# https://docs.python.org/3/reference/lexical_analysis.html#string-and-bytes-literals
3+
4+
# Strings
5+
test = 'String with escapes \' and \" and \t'
6+
test = "String with escapes \040 and \xFF"
7+
test = 'String with escapes \u00A1 and \U00010605 and \N{INVERTED EXCLAMATION MARK}'
8+
test = "String with escaped \\ backslash and ignored \
9+
newline"
10+
test = '''String with quotes ' and "
11+
and escapes \t and \040 and \xFF
12+
and escapes \u00A1 and \U00010605'''
13+
test = """String with quotes ' and "
14+
and escapes \t and \040 and \xFF
15+
and escapes \u00A1 and \U00010605"""
16+
17+
# Raw strings
18+
test = r'Raw string with literal \' and \" and \t'
19+
test = R"Raw string with literal \040 and \xFF"
20+
test = r'Raw string with literal \u00A1 and \U00010605 and \N{INVERTED EXCLAMATION MARK}'
21+
test = R"Raw string with literal \\ backslashes and literal \
22+
newline"
23+
test = r'''Raw string with quotes ' and "
24+
and literal \t and \040 and \xFF
25+
and literal \u00A1 and \U00010605'''
26+
test = R"""Raw string with quotes ' and "
27+
and literal \t and \040 and \xFF
28+
and literal \u00A1 and \U00010605"""
29+
30+
# Bytes
31+
test = b'Bytes with escapes \' and \" and \t'
32+
test = B"Bytes with escapes \040 and \xFF"
33+
test = b'Bytes with literal \u00A1 and \U00010605 and \N{INVERTED EXCLAMATION MARK}'
34+
test = B"Bytes with escaped \\ backslash and ignored \
35+
newline"
36+
test = b'''Bytes with quotes ' and "
37+
and escapes \t and \040 and \xFF
38+
and literal \u00A1 and \U00010605'''
39+
test = B"""Bytes with quotes ' and "
40+
and escapes \t and \040 and \xFF
41+
and literal \u00A1 and \U00010605"""
42+
43+
# Raw bytes
44+
test = br'Raw bytes with literal \' and \" and \t'
45+
test = bR"Raw bytes with literal \040 and \xFF"
46+
test = Br'Raw bytes with literal \u00A1 and \U00010605 and \N{INVERTED EXCLAMATION MARK}'
47+
test = BR"Raw bytes with literal \\ backslashes and literal \
48+
newline"
49+
test = rb'Raw bytes with literal \' and \" and \t'
50+
test = rB"Raw bytes with literal \040 and \xFF"
51+
test = Rb'Raw bytes with literal \u00A1 and \U00010605 and \N{INVERTED EXCLAMATION MARK}'
52+
test = RB"Raw bytes with literal \\ backslashes and literal \
53+
newline"
54+
test = br'''Raw bytes with quotes ' and "
55+
and literal \t and \040 and \xFF
56+
and literal \u00A1 and \U00010605'''
57+
test = RB"""Raw bytes with quotes ' and "
58+
and literal \t and \040 and \xFF
59+
and literal \u00A1 and \U00010605"""
60+
61+
# Unicode literals: Prefix is allowed but ignored (https://peps.python.org/pep-0414)
62+
test = u'String with escapes \' and \" and \t'
63+
test = U"String with escapes \040 and \xFF"
64+
test = u'String with escapes \u00A1 and \U00010605 and \N{INVERTED EXCLAMATION MARK}'
65+
test = U"String with escaped \\ backslash and ignored \
66+
newline"
67+
test = u'''String with quotes ' and "
68+
and escapes \t and \040 and \xFF
69+
and escapes \u00A1 and \U00010605'''
70+
test = U"""String with quotes ' and "
71+
and escapes \t and \040 and \xFF
72+
and escapes \u00A1 and \U00010605"""
73+
74+
# Raw Unicode literals are not allowed
75+
test = ur'Invalid string with \' and \" and \t'
76+
test = uR"Invalid string with \040 and \xFF"
77+
test = Ur'Invalid string with \u00A1 and \U00010605 and \N{INVERTED EXCLAMATION MARK}'
78+
test = UR"Invalid string with \\ backslashes and literal \
79+
newline"
80+
test = ru'Invalid string with \' and \" and \t'
81+
test = rU"Invalid string with \040 and \xFF"
82+
test = Ru'Invalid string with \u00A1 and \U00010605 and \N{INVERTED EXCLAMATION MARK}'
83+
test = RU"Invalid string with \\ backslashes and literal \
84+
newline"
85+
test = ur'''Invalid string with ' and "
86+
and \t and \040 and \xFF
87+
and \u00A1 and \U00010605'''
88+
test = RU"""Invalid string with ' and "
89+
and \t and \040 and \xFF
90+
and \u00A1 and \U00010605"""

0 commit comments

Comments
 (0)