Skip to content

Commit be23f9d

Browse files
committed
Merge branch 'master' into multistring
2 parents d076b1f + 2cc00ba commit be23f9d

File tree

4 files changed

+25
-13
lines changed

4 files changed

+25
-13
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ Features
1919
* New exceptions and builtins
2020
* Doctests
2121
* `@decorator` syntax
22-
* Class variables such as `self` and `cls`
22+
* Class variables such as `self`, `cls`, and `mcs`
2323
* Operators
2424
* Highlighting of the following errors:
2525
* Invalid symbols in source file
@@ -72,7 +72,7 @@ let g:python_highlight_all = 1
7272
| `g:python_highlight_space_errors` | Highlight trailing spaces | `0` |
7373
| `g:python_highlight_doctests` | Highlight doc-tests | `0` |
7474
| `g:python_highlight_func_calls` | Highlight functions calls | `0` |
75-
| `g:python_highlight_class_vars` | Highlight class variables `self` and `cls` | `0` |
75+
| `g:python_highlight_class_vars` | Highlight class variables `self`, `cls`, and `mcs` | `0` |
7676
| `g:python_highlight_operators` | Highlight all operators | `0` |
7777
| `g:python_highlight_all` | Enable all highlight options above, except for previously set. | `0` |
7878
| `g:python_highlight_file_headers_as_comments` | Highlight shebang and coding headers as comments | `0` |

doc/python-syntax.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ Features
2121
* New exceptions and builtins
2222
* Doctests
2323
* `@decorator` syntax
24-
* Class variables such as `self` and `cls`
24+
* Class variables such as `self`, `cls`, and `mcs`
2525
* Operators
2626
* Highlighting of the following errors:
2727
* Invalid symbols in source file
@@ -96,7 +96,7 @@ following command to your `~/.config/nvim/init.vim` or `~/.vimrc`: >
9696
Highlight functions calls
9797

9898
`g:python_highlight_class_vars` (default `0`)
99-
Highlight class variables `self` and `cls`
99+
Highlight class variables `self`, `cls`, and `mcs`
100100

101101
`g:python_highlight_operators` (default `0`)
102102
Highlight all operators

syntax/python.vim

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,10 @@ endif
7474

7575
syn keyword pythonStatement break continue del return pass yield global assert lambda with
7676
syn keyword pythonStatement raise nextgroup=pythonExClass skipwhite
77-
syn keyword pythonStatement def class nextgroup=pythonFunction skipwhite
77+
syn keyword pythonStatement def nextgroup=pythonFunction skipwhite
78+
syn keyword pythonStatement class nextgroup=pythonClass skipwhite
7879
if s:Enabled('g:python_highlight_class_vars')
79-
syn keyword pythonClassVar self cls
80+
syn keyword pythonClassVar self cls mcs
8081
endif
8182
syn keyword pythonRepeat for while
8283
syn keyword pythonConditional if elif else
@@ -100,10 +101,11 @@ else
100101
syn keyword pythonStatement as nonlocal
101102
syn match pythonStatement '\v\.@<!<await>'
102103
syn match pythonFunction '\%([^[:cntrl:][:space:][:punct:][:digit:]]\|_\)\%([^[:cntrl:][:punct:][:space:]]\|_\)*' display contained
104+
syn match pythonClass '\%([^[:cntrl:][:space:][:punct:][:digit:]]\|_\)\%([^[:cntrl:][:punct:][:space:]]\|_\)*' display contained
103105
syn match pythonStatement '\<async\s\+def\>' nextgroup=pythonFunction skipwhite
104106
syn match pythonStatement '\<async\s\+with\>'
105107
syn match pythonStatement '\<async\s\+for\>'
106-
syn cluster pythonExpression contains=pythonStatement,pythonRepeat,pythonConditional,pythonOperator,pythonNumber,pythonHexNumber,pythonOctNumber,pythonBinNumber,pythonFloat,pythonString,pythonBytes,pythonBoolean,pythonNone,pythonSingleton,pythonBuiltinObj,pythonBuiltinFunc,pythonBuiltinType
108+
syn cluster pythonExpression contains=pythonStatement,pythonRepeat,pythonConditional,pythonOperator,pythonNumber,pythonHexNumber,pythonOctNumber,pythonBinNumber,pythonFloat,pythonString,pythonFString,pythonRawString,pythonRawFString,pythonBytes,pythonBoolean,pythonNone,pythonSingleton,pythonBuiltinObj,pythonBuiltinFunc,pythonBuiltinType,pythonClassVar
107109
endif
108110

109111

@@ -112,7 +114,7 @@ endif
112114
"
113115
syn keyword pythonOperator and in is not or
114116
if s:Enabled('g:python_highlight_operators')
115-
syn match pythonOperator '\V=\|-\|+\|*\|@\|/\|%\|&\||\|^\|~\|<\|>\|!='
117+
syn match pythonOperator '\V=\|-\|+\|*\|@\|/\|%\|&\||\|^\|~\|<\|>\|!=\|:='
116118
endif
117119
syn match pythonError '[$?]\|\([-+@%&|^~]\)\1\{1,}\|\([=*/<>]\)\2\{2,}\|\([+@/%&|^~<>]\)\3\@![-+*@/%&|^~<>]\|\*\*[*@/%&|^<>]\|=[*@/%&|^<>]\|-[+*@/%&|^~<]\|[<!>]\+=\{2,}\|!\{2,}=\+' display
118120

@@ -263,8 +265,8 @@ if s:Enabled('g:python_highlight_string_format')
263265
syn match pythonStrFormat '{{\|}}' contained containedin=pythonString,pythonMultiString,pythonUniString,pythonUniMultiString,pythonUniRawString,pythonRawString
264266
syn match pythonStrFormat '{\%(\%([^[:cntrl:][:space:][:punct:][:digit:]]\|_\)\%([^[:cntrl:][:punct:][:space:]]\|_\)*\|\d\+\)\=\%(\.\%([^[:cntrl:][:space:][:punct:][:digit:]]\|_\)\%([^[:cntrl:][:punct:][:space:]]\|_\)*\|\[\%(\d\+\|[^!:\}]\+\)\]\)*\%(![rsa]\)\=\%(:\%({\%(\%([^[:cntrl:][:space:][:punct:][:digit:]]\|_\)\%([^[:cntrl:][:punct:][:space:]]\|_\)*\|\d\+\)}\|\%([^}]\=[<>=^]\)\=[ +-]\=#\=0\=\d*,\=\%(\.\d\+\)\=[bcdeEfFgGnosxX%]\=\)\=\)\=}' contained containedin=pythonString,pythonMultiString,pythonUniString,pythonUniMultiString,pythonUniRawString,pythonRawString
265267
else
266-
syn match pythonStrFormat "{\%(\%([^[:cntrl:][:space:][:punct:][:digit:]]\|_\)\%([^[:cntrl:][:punct:][:space:]]\|_\)*\|\d\+\)\=\%(\.\%([^[:cntrl:][:space:][:punct:][:digit:]]\|_\)\%([^[:cntrl:][:punct:][:space:]]\|_\)*\|\[\%(\d\+\|[^!:\}]\+\)\]\)*\%(![rsa]\)\=\%(:\%({\%(\%([^[:cntrl:][:space:][:punct:][:digit:]]\|_\)\%([^[:cntrl:][:punct:][:space:]]\|_\)*\|\d\+\)}\|\%([^}]\=[<>=^]\)\=[ +-]\=#\=0\=\d*,\=\%(\.\d\+\)\=[bcdeEfFgGnosxX%]\=\)\=\)\=}" contained containedin=pythonString,pythonMultiString,pythonRawString
267-
syn region pythonStrInterpRegion start="{"he=e+1,rs=e+1 end="\%(![rsa]\)\=\%(:\%({\%(\%([^[:cntrl:][:space:][:punct:][:digit:]]\|_\)\%([^[:cntrl:][:punct:][:space:]]\|_\)*\|\d\+\)}\|\%([^}]\=[<>=^]\)\=[ +-]\=#\=0\=\d*,\=\%(\.\d\+\)\=[bcdeEfFgGnosxX%]\=\)\=\)\=}"hs=s-1,re=s-1 extend contained containedin=pythonFString,pythonRawFString contains=pythonStrInterpRegion,@pythonExpression
268+
syn match pythonStrFormat "{\%(\%([^[:cntrl:][:space:][:punct:][:digit:]]\|_\)\%([^[:cntrl:][:punct:][:space:]]\|_\)*\|\d\+\)\=\%(\.\%([^[:cntrl:][:space:][:punct:][:digit:]]\|_\)\%([^[:cntrl:][:punct:][:space:]]\|_\)*\|\[\%(\d\+\|[^!:\}]\+\)\]\)*\%(![rsa]\)\=\%(:\%({\%(\%([^[:cntrl:][:space:][:punct:][:digit:]]\|_\)\%([^[:cntrl:][:punct:][:space:]]\|_\)*\|\d\+\)}\|\%([^}]\=[<>=^]\)\=[ +-]\=#\=0\=\d*,\=\%(\.\d\+\)\=[bcdeEfFgGnosxX%]\=\)\=\)\=}" contained containedin=pythonString,pythonRawString
269+
syn region pythonStrInterpRegion matchgroup=pythonStrFormat start="{" end="\%(![rsa]\)\=\%(:\%({\%(\%([^[:cntrl:][:space:][:punct:][:digit:]]\|_\)\%([^[:cntrl:][:punct:][:space:]]\|_\)*\|\d\+\)}\|\%([^}]\=[<>=^]\)\=[ +-]\=#\=0\=\d*,\=\%(\.\d\+\)\=[bcdeEfFgGnosxX%]\=\)\=\)\=}" extend contained containedin=pythonFString,pythonRawFString contains=pythonStrInterpRegion,@pythonExpression
268270
syn match pythonStrFormat "{{\|}}" contained containedin=pythonString,pythonMultiString,pythonRawString,pythonFString,pythonRawFString
269271
endif
270272
endif
@@ -473,7 +475,6 @@ if v:version >= 508 || !exists('did_python_syn_inits')
473475
HiLink pythonBytesEscapeError Error
474476
HiLink pythonFString String
475477
HiLink pythonRawFString String
476-
HiLink pythonStrInterpRegion Special
477478
endif
478479

479480
HiLink pythonStrFormatting Special
@@ -502,6 +503,7 @@ if v:version >= 508 || !exists('did_python_syn_inits')
502503
HiLink pythonBuiltinType Structure
503504

504505
HiLink pythonExClass Structure
506+
HiLink pythonClass Structure
505507
HiLink pythonClassVar Identifier
506508

507509
delcommand HiLink

tests/test.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
with break continue del return pass raise global assert lambda yield
1212
for while if elif else import as try except finally
1313

14+
self cls mcs
15+
1416
from test import var as name
1517

1618
raise Exception from ex
@@ -24,9 +26,13 @@ def functionname
2426
test.functionname()
2527
test.functionname ()
2628
class Classname
29+
class classname
30+
class classname_cls
2731
def функция
2832
функция()
2933
class Класс
34+
class класс
35+
3036

3137
# Keywords: Python 2
3238

@@ -176,7 +182,7 @@ async def Test
176182
< <= == != >= >
177183

178184
= =- =+ =~
179-
-= += *= **= @= /= //= %=
185+
-= += *= **= @= /= //= %= :=
180186
&= |= ^= ~= <<= >>=
181187

182188
->
@@ -244,8 +250,12 @@ async def Test
244250
f"{var}...{arr[123]} normal {var['{'] // 0xff} \"xzcb\" 'xzcb' {var['}'] + 1} text"
245251
f"{expr1 if True or False else expr2} {None} wow {','.join(c.lower() for c in 'asdf')}"
246252
f"hello {expr:.2f} yes {(lambda: 0b1)():#03x} lol {var!r}"
247-
f'brackets: {{ 1 + 2 }} and {{{{ 3 + 4 }}}}'
253+
f'brackets: {{{ 1 + 2 }}} and {{{{ 3 + 4 }}}}'
248254
fr'this {that}'
255+
f"{f'{1+1}'}"
256+
'{{ }}'
257+
f"{"{test}"}" # FIXME: syntax error that should not be highlighted
258+
f'{self.__name__}
249259
250260
# Doctests.
251261

0 commit comments

Comments
 (0)