diff --git a/README.md b/README.md index 922c335..382472e 100644 --- a/README.md +++ b/README.md @@ -19,7 +19,7 @@ Features * New exceptions and builtins * Doctests * `@decorator` syntax - * Class variables such as `self` and `cls` + * Class variables such as `self`, `cls`, and `mcs` * Operators * Highlighting of the following errors: * Invalid symbols in source file @@ -72,7 +72,7 @@ let g:python_highlight_all = 1 | `g:python_highlight_space_errors` | Highlight trailing spaces | `0` | | `g:python_highlight_doctests` | Highlight doc-tests | `0` | | `g:python_highlight_func_calls` | Highlight functions calls | `0` | -| `g:python_highlight_class_vars` | Highlight class variables `self` and `cls` | `0` | +| `g:python_highlight_class_vars` | Highlight class variables `self`, `cls`, and `mcs` | `0` | | `g:python_highlight_operators` | Highlight all operators | `0` | | `g:python_highlight_all` | Enable all highlight options above, except for previously set. | `0` | | `g:python_highlight_file_headers_as_comments` | Highlight shebang and coding headers as comments | `0` | diff --git a/doc/python-syntax.txt b/doc/python-syntax.txt index 59eb0ef..79c569e 100644 --- a/doc/python-syntax.txt +++ b/doc/python-syntax.txt @@ -21,7 +21,7 @@ Features * New exceptions and builtins * Doctests * `@decorator` syntax - * Class variables such as `self` and `cls` + * Class variables such as `self`, `cls`, and `mcs` * Operators * Highlighting of the following errors: * Invalid symbols in source file @@ -96,7 +96,7 @@ following command to your `~/.config/nvim/init.vim` or `~/.vimrc`: > Highlight functions calls `g:python_highlight_class_vars` (default `0`) - Highlight class variables `self` and `cls` + Highlight class variables `self`, `cls`, and `mcs` `g:python_highlight_operators` (default `0`) Highlight all operators diff --git a/syntax/python.vim b/syntax/python.vim index a7f6edc..2524aba 100644 --- a/syntax/python.vim +++ b/syntax/python.vim @@ -74,9 +74,10 @@ endif syn keyword pythonStatement break continue del return pass yield global assert lambda with syn keyword pythonStatement raise nextgroup=pythonExClass skipwhite -syn keyword pythonStatement def class nextgroup=pythonFunction skipwhite +syn keyword pythonStatement def nextgroup=pythonFunction skipwhite +syn keyword pythonStatement class nextgroup=pythonClass skipwhite if s:Enabled('g:python_highlight_class_vars') - syn keyword pythonClassVar self cls + syn keyword pythonClassVar self cls mcs endif syn keyword pythonRepeat for while syn keyword pythonConditional if elif else @@ -100,10 +101,11 @@ else syn keyword pythonStatement as nonlocal syn match pythonStatement '\v\.@' syn match pythonFunction '\%([^[:cntrl:][:space:][:punct:][:digit:]]\|_\)\%([^[:cntrl:][:punct:][:space:]]\|_\)*' display contained + syn match pythonClass '\%([^[:cntrl:][:space:][:punct:][:digit:]]\|_\)\%([^[:cntrl:][:punct:][:space:]]\|_\)*' display contained syn match pythonStatement '\' nextgroup=pythonFunction skipwhite syn match pythonStatement '\' syn match pythonStatement '\' - syn cluster pythonExpression contains=pythonStatement,pythonRepeat,pythonConditional,pythonOperator,pythonNumber,pythonHexNumber,pythonOctNumber,pythonBinNumber,pythonFloat,pythonString,pythonBytes,pythonBoolean,pythonNone,pythonSingleton,pythonBuiltinObj,pythonBuiltinFunc,pythonBuiltinType + 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 endif @@ -112,7 +114,7 @@ endif " syn keyword pythonOperator and in is not or if s:Enabled('g:python_highlight_operators') - syn match pythonOperator '\V=\|-\|+\|*\|@\|/\|%\|&\||\|^\|~\|<\|>\|!=' + syn match pythonOperator '\V=\|-\|+\|*\|@\|/\|%\|&\||\|^\|~\|<\|>\|!=\|:=' endif syn match pythonError '[$?]\|\([-+@%&|^~]\)\1\{1,}\|\([=*/<>]\)\2\{2,}\|\([+@/%&|^~<>]\)\3\@![-+*@/%&|^~<>]\|\*\*[*@/%&|^<>]\|=[*@/%&|^<>]\|-[+*@/%&|^~<]\|[]\+=\{2,}\|!\{2,}=\+' display @@ -264,8 +266,8 @@ if s:Enabled('g:python_highlight_string_format') 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,pythonUniString,pythonUniRawString,pythonRawString else 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 - 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 - syn match pythonStrFormat "{{\|}}" contained containedin=pythonString,pythonRawString,pythonFString,pythonRawFString + 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 + syn match pythonStrFormat "{{\|}}" contained containedin=pythonFString,pythonRawFString endif endif @@ -471,7 +473,6 @@ if v:version >= 508 || !exists('did_python_syn_inits') HiLink pythonBytesEscapeError Error HiLink pythonFString String HiLink pythonRawFString String - HiLink pythonStrInterpRegion Special endif HiLink pythonStrFormatting Special @@ -500,6 +501,7 @@ if v:version >= 508 || !exists('did_python_syn_inits') HiLink pythonBuiltinType Structure HiLink pythonExClass Structure + HiLink pythonClass Structure HiLink pythonClassVar Identifier delcommand HiLink diff --git a/tests/test.py b/tests/test.py index 246d109..c0f81ac 100644 --- a/tests/test.py +++ b/tests/test.py @@ -11,6 +11,8 @@ with break continue del return pass raise global assert lambda yield for while if elif else import as try except finally +self cls mcs + from test import var as name raise Exception from ex @@ -24,9 +26,13 @@ def functionname test.functionname() test.functionname () class Classname +class classname +class classname_cls def функция функция() class Класс +class класс + # Keywords: Python 2 @@ -176,7 +182,7 @@ async def Test < <= == != >= > = =- =+ =~ --= += *= **= @= /= //= %= +-= += *= **= @= /= //= %= := &= |= ^= ~= <<= >>= -> @@ -244,8 +250,12 @@ async def Test f"{var}...{arr[123]} normal {var['{'] // 0xff} \"xzcb\" 'xzcb' {var['}'] + 1} text" f"{expr1 if True or False else expr2} {None} wow {','.join(c.lower() for c in 'asdf')}" f"hello {expr:.2f} yes {(lambda: 0b1)():#03x} lol {var!r}" -f'brackets: {{ 1 + 2 }} and {{{{ 3 + 4 }}}}' +f'brackets: {{{ 1 + 2 }}} and {{{{ 3 + 4 }}}}' fr'this {that}' +f"{f'{1+1}'}" +'{{ }}' +f"{"{test}"}" # FIXME: syntax error that should not be highlighted +f'{self.__name__} # Doctests.