From 31d6023a3c766a617a251e9d989342c5f2397fd8 Mon Sep 17 00:00:00 2001 From: koka Date: Sat, 8 Jul 2017 22:52:22 +0900 Subject: [PATCH 01/25] separate pythonClassName from pythonFunction --- syntax/python.vim | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/syntax/python.vim b/syntax/python.vim index ffd88f9..4a00eea 100644 --- a/syntax/python.vim +++ b/syntax/python.vim @@ -63,7 +63,9 @@ 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=pythonClassName skipwhite +syn match pythonClassName '[A-Z][a-zA-Z0-9_]*' display contained if s:Enabled('g:python_highlight_class_vars') syn keyword pythonClassVar self cls endif @@ -407,6 +409,7 @@ if v:version >= 508 || !exists('did_python_syn_inits') HiLink pythonRaiseFromStatement Statement HiLink pythonImport Include HiLink pythonFunction Function + HiLink pythonClassName Structure HiLink pythonConditional Conditional HiLink pythonRepeat Repeat HiLink pythonException Exception From 89881c3974a2d982c4c24dd3991514e0ae1c72d1 Mon Sep 17 00:00:00 2001 From: koka Date: Mon, 31 Jul 2017 22:57:08 +0900 Subject: [PATCH 02/25] remove regex for pythonClassName --- syntax/python.vim | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/syntax/python.vim b/syntax/python.vim index 4a00eea..535fe4e 100644 --- a/syntax/python.vim +++ b/syntax/python.vim @@ -65,7 +65,8 @@ syn keyword pythonStatement break continue del return pass yield global asse syn keyword pythonStatement raise nextgroup=pythonExClass skipwhite syn keyword pythonStatement def nextgroup=pythonFunction skipwhite syn keyword pythonStatement class nextgroup=pythonClassName skipwhite -syn match pythonClassName '[A-Z][a-zA-Z0-9_]*' display contained +" for all developers, commented out CamelCase regex for className +"syn match pythonClassName '[A-Z][a-zA-Z0-9_]*' display contained if s:Enabled('g:python_highlight_class_vars') syn keyword pythonClassVar self cls endif From ac576c5d863662bb04c25a53da03a0e22ce27d71 Mon Sep 17 00:00:00 2001 From: koka Date: Mon, 31 Jul 2017 23:09:32 +0900 Subject: [PATCH 03/25] modify regex for pythonClassName following pythonFunction way. --- syntax/python.vim | 2 ++ tests/test.py | 2 ++ 2 files changed, 4 insertions(+) diff --git a/syntax/python.vim b/syntax/python.vim index 535fe4e..d43e7f4 100644 --- a/syntax/python.vim +++ b/syntax/python.vim @@ -88,10 +88,12 @@ if s:Python2Syntax() syn keyword pythonStatement exec syn keyword pythonImport as syn match pythonFunction '[a-zA-Z_][a-zA-Z0-9_]*' display contained + syn match pythonClassName '[A-Z][a-zA-Z0-9_]*' display contained else syn keyword pythonStatement as nonlocal syn match pythonStatement '\v\.@' syn match pythonFunction '\%([^[:cntrl:][:space:][:punct:][:digit:]]\|_\)\%([^[:cntrl:][:punct:][:space:]]\|_\)*' display contained + syn match pythonClassName '\%([^[:cntrl:][:space:][:punct:][:digit:]]\|_\)\%([^[:cntrl:][:punct:][:space:]]\|_\)*' display contained syn match pythonStatement '\' nextgroup=pythonFunction skipwhite syn match pythonStatement '\' syn match pythonStatement '\' diff --git a/tests/test.py b/tests/test.py index 058f3f7..cea906a 100644 --- a/tests/test.py +++ b/tests/test.py @@ -19,8 +19,10 @@ def functionname class Classname +class classname def функция class Класс +class функция # Keywords: Python 2 From 28776a52be718444025c7a9af8f85fcd3e0ef1c9 Mon Sep 17 00:00:00 2001 From: koka Date: Mon, 31 Jul 2017 23:40:05 +0900 Subject: [PATCH 04/25] use :upper: --- syntax/python.vim | 7 +++---- tests/test.py | 3 ++- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/syntax/python.vim b/syntax/python.vim index d43e7f4..0f49224 100644 --- a/syntax/python.vim +++ b/syntax/python.vim @@ -65,8 +65,8 @@ syn keyword pythonStatement break continue del return pass yield global asse syn keyword pythonStatement raise nextgroup=pythonExClass skipwhite syn keyword pythonStatement def nextgroup=pythonFunction skipwhite syn keyword pythonStatement class nextgroup=pythonClassName skipwhite -" for all developers, commented out CamelCase regex for className -"syn match pythonClassName '[A-Z][a-zA-Z0-9_]*' display contained +syn match pythonClassName '[:upper:]*' display contained + if s:Enabled('g:python_highlight_class_vars') syn keyword pythonClassVar self cls endif @@ -88,13 +88,12 @@ if s:Python2Syntax() syn keyword pythonStatement exec syn keyword pythonImport as syn match pythonFunction '[a-zA-Z_][a-zA-Z0-9_]*' display contained - syn match pythonClassName '[A-Z][a-zA-Z0-9_]*' display contained else syn keyword pythonStatement as nonlocal syn match pythonStatement '\v\.@' syn match pythonFunction '\%([^[:cntrl:][:space:][:punct:][:digit:]]\|_\)\%([^[:cntrl:][:punct:][:space:]]\|_\)*' display contained - syn match pythonClassName '\%([^[:cntrl:][:space:][:punct:][:digit:]]\|_\)\%([^[:cntrl:][:punct:][:space:]]\|_\)*' display contained syn match pythonStatement '\' nextgroup=pythonFunction skipwhite + syn match pythonStatement '\' nextgroup=pythonClassName skipwhite syn match pythonStatement '\' syn match pythonStatement '\' syn cluster pythonExpression contains=pythonStatement,pythonRepeat,pythonConditional,pythonOperator,pythonNumber,pythonHexNumber,pythonOctNumber,pythonBinNumber,pythonFloat,pythonString,pythonBytes,pythonBoolean,pythonBuiltinObj,pythonBuiltinFunc diff --git a/tests/test.py b/tests/test.py index cea906a..ac08e25 100644 --- a/tests/test.py +++ b/tests/test.py @@ -22,7 +22,8 @@ class Classname class classname def функция class Класс -class функция +class класс + # Keywords: Python 2 From 71b4ecc84ca307de157cff7b041d1252b6afeffc Mon Sep 17 00:00:00 2001 From: koka Date: Tue, 1 Aug 2017 00:41:51 +0900 Subject: [PATCH 05/25] fix regex --- syntax/python.vim | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/syntax/python.vim b/syntax/python.vim index 0f49224..e774162 100644 --- a/syntax/python.vim +++ b/syntax/python.vim @@ -53,6 +53,7 @@ if s:Enabled('g:python_highlight_all') call s:EnableByDefault('g:python_highlight_space_errors') call s:EnableByDefault('g:python_highlight_doctests') call s:EnableByDefault('g:python_print_as_function') + call s:EnableByDefault('g:python_highlight_class_names') call s:EnableByDefault('g:python_highlight_class_vars') call s:EnableByDefault('g:python_highlight_operators') endif @@ -64,9 +65,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 nextgroup=pythonFunction skipwhite -syn keyword pythonStatement class nextgroup=pythonClassName skipwhite -syn match pythonClassName '[:upper:]*' display contained - +if s:Enabled('g:python_highlight_class_names') + syn keyword pythonStatement class nextgroup=pythonClassName skipwhite + syn match pythonClassName '^[:upper:]\%([^[:cntrl:][:space:][:punct:][:digit:]]\|_\)\%([^[:cntrl:][:punct:][:space:]]\|_\)*' display contained +endif if s:Enabled('g:python_highlight_class_vars') syn keyword pythonClassVar self cls endif @@ -93,7 +95,6 @@ else syn match pythonStatement '\v\.@' syn match pythonFunction '\%([^[:cntrl:][:space:][:punct:][:digit:]]\|_\)\%([^[:cntrl:][:punct:][:space:]]\|_\)*' display contained syn match pythonStatement '\' nextgroup=pythonFunction skipwhite - syn match pythonStatement '\' nextgroup=pythonClassName skipwhite syn match pythonStatement '\' syn match pythonStatement '\' syn cluster pythonExpression contains=pythonStatement,pythonRepeat,pythonConditional,pythonOperator,pythonNumber,pythonHexNumber,pythonOctNumber,pythonBinNumber,pythonFloat,pythonString,pythonBytes,pythonBoolean,pythonBuiltinObj,pythonBuiltinFunc From aa9d431248f453a16411cd878590dab26bbe2afe Mon Sep 17 00:00:00 2001 From: koka Date: Tue, 1 Aug 2017 00:47:02 +0900 Subject: [PATCH 06/25] fix --- syntax/python.vim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/syntax/python.vim b/syntax/python.vim index e774162..da4d2b6 100644 --- a/syntax/python.vim +++ b/syntax/python.vim @@ -67,7 +67,7 @@ syn keyword pythonStatement raise nextgroup=pythonExClass skipwhite syn keyword pythonStatement def nextgroup=pythonFunction skipwhite if s:Enabled('g:python_highlight_class_names') syn keyword pythonStatement class nextgroup=pythonClassName skipwhite - syn match pythonClassName '^[:upper:]\%([^[:cntrl:][:space:][:punct:][:digit:]]\|_\)\%([^[:cntrl:][:punct:][:space:]]\|_\)*' display contained + syn match pythonClassName '\%([^[:cntrl:][:space:][:punct:][:digit:]]\|_\)\%([^[:cntrl:][:punct:][:space:]]\|_\)*' display contained endif if s:Enabled('g:python_highlight_class_vars') syn keyword pythonClassVar self cls From ed4966cc480b5c532809405d3552dc68470486e0 Mon Sep 17 00:00:00 2001 From: koka Date: Tue, 1 Aug 2017 00:49:36 +0900 Subject: [PATCH 07/25] use :upper: --- syntax/python.vim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/syntax/python.vim b/syntax/python.vim index da4d2b6..d78c775 100644 --- a/syntax/python.vim +++ b/syntax/python.vim @@ -67,7 +67,7 @@ syn keyword pythonStatement raise nextgroup=pythonExClass skipwhite syn keyword pythonStatement def nextgroup=pythonFunction skipwhite if s:Enabled('g:python_highlight_class_names') syn keyword pythonStatement class nextgroup=pythonClassName skipwhite - syn match pythonClassName '\%([^[:cntrl:][:space:][:punct:][:digit:]]\|_\)\%([^[:cntrl:][:punct:][:space:]]\|_\)*' display contained + syn match pythonClassName '[:upper:]\%([^[:cntrl:][:space:][:punct:][:digit:]]\|_\)\%([^[:cntrl:][:punct:][:space:]]\|_\)*' display contained endif if s:Enabled('g:python_highlight_class_vars') syn keyword pythonClassVar self cls From b412bd0b46e1af993e1eeea2a2bcb271e5edb31b Mon Sep 17 00:00:00 2001 From: koka Date: Tue, 1 Aug 2017 01:08:08 +0900 Subject: [PATCH 08/25] fix regexp: recog :upper: --- syntax/python.vim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/syntax/python.vim b/syntax/python.vim index d78c775..6a4ca79 100644 --- a/syntax/python.vim +++ b/syntax/python.vim @@ -67,7 +67,7 @@ syn keyword pythonStatement raise nextgroup=pythonExClass skipwhite syn keyword pythonStatement def nextgroup=pythonFunction skipwhite if s:Enabled('g:python_highlight_class_names') syn keyword pythonStatement class nextgroup=pythonClassName skipwhite - syn match pythonClassName '[:upper:]\%([^[:cntrl:][:space:][:punct:][:digit:]]\|_\)\%([^[:cntrl:][:punct:][:space:]]\|_\)*' display contained + syn match pythonClassName '\%([[:upper:]][^[:cntrl:][:space:][:punct:][:digit:]]\|_\)\%([^[:cntrl:][:punct:][:space:]]\|_\)*' display contained endif if s:Enabled('g:python_highlight_class_vars') syn keyword pythonClassVar self cls From 4d8ecd681b3524a402cb44caf2a1d67c15b7bc90 Mon Sep 17 00:00:00 2001 From: Ricardo Madriz Date: Sat, 23 Feb 2019 17:21:56 -0600 Subject: [PATCH 09/25] hightlight class variables inside f-strings --- syntax/python.vim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/syntax/python.vim b/syntax/python.vim index 8fc77e3..22dc9b4 100644 --- a/syntax/python.vim +++ b/syntax/python.vim @@ -93,7 +93,7 @@ else 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,pythonBytes,pythonBoolean,pythonNone,pythonSingleton,pythonBuiltinObj,pythonBuiltinFunc,pythonBuiltinType,pythonClassVar endif From 8e76189bffc1cb60879352d9b9f93be51fb50bdb Mon Sep 17 00:00:00 2001 From: Ricardo Madriz Date: Sat, 23 Feb 2019 17:22:04 -0600 Subject: [PATCH 10/25] test change --- tests/test.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/tests/test.py b/tests/test.py index 5c494fd..727c16d 100644 --- a/tests/test.py +++ b/tests/test.py @@ -241,6 +241,11 @@ async def Test f'brackets: {{ 1 + 2 }} and {{{{ 3 + 4 }}}}' fr'this {that}' + +class Atest: + def amethod(self): + print(f"{self.__name__}") + # Doctests. """ From 83ae752ca0d7b879919e83363765ea481ad93897 Mon Sep 17 00:00:00 2001 From: lilydjwg Date: Thu, 27 Jul 2017 16:28:05 +0800 Subject: [PATCH 11/25] move {{ and }} matching so that it gets highlighted correctly --- syntax/python.vim | 4 ++-- tests/test.py | 1 + 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/syntax/python.vim b/syntax/python.vim index 6a4ca79..a5a0da6 100644 --- a/syntax/python.vim +++ b/syntax/python.vim @@ -257,9 +257,9 @@ if s:Enabled('g:python_highlight_string_format') syn match pythonStrFormat '{{\|}}' contained containedin=pythonString,pythonUniString,pythonUniRawString,pythonRawString 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 "{{\|}}" contained containedin=pythonString,pythonRawString,pythonFString,pythonRawFString 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 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 contains=pythonStrInterpRegion,@pythonExpression + syn match pythonStrFormat "{{\|}}" contained containedin=pythonString,pythonRawString,pythonFString,pythonRawFString endif endif diff --git a/tests/test.py b/tests/test.py index ac08e25..13e4df2 100644 --- a/tests/test.py +++ b/tests/test.py @@ -238,6 +238,7 @@ async def Test f"{var}...{arr[123]} normal {var['{'] // 0xff} \"xzcb\" 'xzcb' {var['}'] + 1} text" f"{expr1 if True or False else expr2} 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 }}}}' # Doctests. From bb4a0b24ae03359aa15ebeccf8e0a939953c419c Mon Sep 17 00:00:00 2001 From: nfnty Date: Fri, 4 Aug 2017 13:51:08 +0200 Subject: [PATCH 12/25] Fix raw f-string interpolation Fixes #32 --- syntax/python.vim | 2 +- tests/test.py | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/syntax/python.vim b/syntax/python.vim index a5a0da6..4f6cc33 100644 --- a/syntax/python.vim +++ b/syntax/python.vim @@ -258,7 +258,7 @@ 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 contains=pythonStrInterpRegion,@pythonExpression + 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 endif endif diff --git a/tests/test.py b/tests/test.py index 13e4df2..413f809 100644 --- a/tests/test.py +++ b/tests/test.py @@ -239,6 +239,7 @@ async def Test f"{expr1 if True or False else expr2} 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 }}}}' +fr'this {that}' # Doctests. From 5024a66f93a4190919f3939f570e011dde045467 Mon Sep 17 00:00:00 2001 From: nfnty Date: Wed, 9 Jan 2019 15:15:36 +0000 Subject: [PATCH 13/25] Remove highlight link from `pythonDot` to `Normal` Linking `pythonDot` to `Normal` breaks `CursorLine` highlighting. ``` hi Normal guifg=#ffffff guibg=#000000 hi CursorLine guibg=#111111 ``` Closes #48 --- syntax/python.vim | 1 - 1 file changed, 1 deletion(-) diff --git a/syntax/python.vim b/syntax/python.vim index 4f6cc33..ae336cd 100644 --- a/syntax/python.vim +++ b/syntax/python.vim @@ -420,7 +420,6 @@ if v:version >= 508 || !exists('did_python_syn_inits') HiLink pythonDecorator Define HiLink pythonDottedName Function - HiLink pythonDot Normal HiLink pythonComment Comment if !s:Enabled('g:python_highlight_file_headers_as_comments') From 8892101db2811eb02966af10482bac1fc747945f Mon Sep 17 00:00:00 2001 From: Caleb Donovick Date: Tue, 18 Dec 2018 15:37:19 -0800 Subject: [PATCH 14/25] Add `pythonNone` to `pythonExpression` Closes #54 --- syntax/python.vim | 2 +- tests/test.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/syntax/python.vim b/syntax/python.vim index ae336cd..71a77ba 100644 --- a/syntax/python.vim +++ b/syntax/python.vim @@ -97,7 +97,7 @@ else 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,pythonBuiltinObj,pythonBuiltinFunc + syn cluster pythonExpression contains=pythonStatement,pythonRepeat,pythonConditional,pythonOperator,pythonNumber,pythonHexNumber,pythonOctNumber,pythonBinNumber,pythonFloat,pythonString,pythonBytes,pythonBoolean,pythonNone,pythonBuiltinObj,pythonBuiltinFunc endif diff --git a/tests/test.py b/tests/test.py index 413f809..35ce361 100644 --- a/tests/test.py +++ b/tests/test.py @@ -236,7 +236,7 @@ async def Test b"${test} ${test ${test}aname $$$ $test+nope" f"{var}...{arr[123]} normal {var['{'] // 0xff} \"xzcb\" 'xzcb' {var['}'] + 1} text" -f"{expr1 if True or False else expr2} wow {','.join(c.lower() for c in 'asdf')}" +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 }}}}' fr'this {that}' From 13efe6fb9bed6e09ed31e1a2a90cb47b541e2090 Mon Sep 17 00:00:00 2001 From: Caleb Donovick Date: Tue, 18 Dec 2018 15:29:50 -0800 Subject: [PATCH 15/25] Split builtin objects / types Closes #55 --- README.md | 1 + doc/python-syntax.txt | 3 +++ syntax/python.vim | 21 ++++++++++++++++----- tests/test.py | 2 ++ 4 files changed, 22 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 8c35ec2..c1b6b0d 100644 --- a/README.md +++ b/README.md @@ -61,6 +61,7 @@ let g:python_highlight_all = 1 | `b:python_version_2` | Python 2 mode (buffer local) | `0` | | `g:python_highlight_builtins` | Highlight builtin functions and objects | `0` | | `g:python_highlight_builtin_objs` | Highlight builtin objects only | `0` | +| `g:python_highlight_builtin_types` | Highlight builtin types only | `0` | | `g:python_highlight_builtin_funcs` | Highlight builtin functions only | `0` | | `g:python_highlight_builtin_funcs_kwarg` | Highlight builtin functions when used as kwarg | `1` | | `g:python_highlight_exceptions` | Highlight standard exceptions | `0` | diff --git a/doc/python-syntax.txt b/doc/python-syntax.txt index a1ccf16..01bd1fe 100644 --- a/doc/python-syntax.txt +++ b/doc/python-syntax.txt @@ -62,6 +62,9 @@ following command to your `~/.config/nvim/init.vim` or `~/.vimrc`: > `g:python_highlight_builtin_objs` (default `0`) Highlight builtin objects only +`g:python_highlight_builtin_types` (default `0`) + Highlight builtin types only + `g:python_highlight_builtin_funcs` (default `0`) Highlight builtin functions only diff --git a/syntax/python.vim b/syntax/python.vim index 71a77ba..570c1d1 100644 --- a/syntax/python.vim +++ b/syntax/python.vim @@ -44,6 +44,7 @@ if s:Enabled('g:python_highlight_all') if s:Enabled('g:python_highlight_builtins') call s:EnableByDefault('g:python_highlight_builtin_objs') call s:EnableByDefault('g:python_highlight_builtin_funcs') + call s:EnableByDefault('g:python_highlight_builtin_types') endif call s:EnableByDefault('g:python_highlight_exceptions') call s:EnableByDefault('g:python_highlight_string_formatting') @@ -97,7 +98,7 @@ else 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,pythonBuiltinObj,pythonBuiltinFunc + syn cluster pythonExpression contains=pythonStatement,pythonRepeat,pythonConditional,pythonOperator,pythonNumber,pythonHexNumber,pythonOctNumber,pythonBinNumber,pythonFloat,pythonString,pythonBytes,pythonBoolean,pythonNone,pythonSingleton,pythonBuiltinObj,pythonBuiltinFunc,pythonBuiltinType endif @@ -335,14 +336,13 @@ else endif " -" Builtin objects and types +" Builtin objects " if s:Enabled('g:python_highlight_builtin_objs') syn keyword pythonNone None syn keyword pythonBoolean True False - syn keyword pythonBuiltinObj Ellipsis NotImplemented - syn match pythonBuiltinObj '\v\.@' + syn keyword pythonSingleton Ellipsis NotImplemented syn keyword pythonBuiltinObj __debug__ __doc__ __file__ __name__ __package__ syn keyword pythonBuiltinObj __loader__ __spec__ __path__ __cached__ endif @@ -373,6 +373,15 @@ if s:Enabled('g:python_highlight_builtin_funcs') unlet s:funcs_re endif +" +" Builtin types +" + +if s:Enabled('g:python_highlight_builtin_types') + syn match pythonBuiltinType '\v\.@' +endif + + " " Builtin exceptions and warnings " @@ -475,9 +484,11 @@ if v:version >= 508 || !exists('did_python_syn_inits') HiLink pythonBoolean Boolean HiLink pythonNone Constant + HiLink pythonSingleton Constant - HiLink pythonBuiltinObj Structure + HiLink pythonBuiltinObj Identifier HiLink pythonBuiltinFunc Function + HiLink pythonBuiltinType Structure HiLink pythonExClass Structure HiLink pythonClassVar Identifier diff --git a/tests/test.py b/tests/test.py index 35ce361..1904944 100644 --- a/tests/test.py +++ b/tests/test.py @@ -41,6 +41,8 @@ async def Test True False Ellipsis None NotImplemented +__debug__ __doc__ __file__ __name__ __package__ __loader__ __spec__ __path__ __cached__ + # Bultin types bool bytearray dict float frozenset int list object set str tuple From cbcfd0964ddf402ccc86abdc40fe7564163b2dae Mon Sep 17 00:00:00 2001 From: nfnty Date: Wed, 9 Jan 2019 15:59:09 +0000 Subject: [PATCH 16/25] Add builtin function `breakpoint` Fixes #46 --- syntax/python.vim | 2 +- tests/test.py | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/syntax/python.vim b/syntax/python.vim index 570c1d1..90b6df8 100644 --- a/syntax/python.vim +++ b/syntax/python.vim @@ -360,7 +360,7 @@ if s:Enabled('g:python_highlight_builtin_funcs') let s:funcs_re .= '|print' endif else - let s:funcs_re .= '|ascii|exec|print' + let s:funcs_re .= '|ascii|breakpoint|exec|print' endif let s:funcs_re = 'syn match pythonBuiltinFunc ''\v\.@' diff --git a/tests/test.py b/tests/test.py index 1904944..c1defac 100644 --- a/tests/test.py +++ b/tests/test.py @@ -55,6 +55,7 @@ async def Test any() bin() bool() +breakpoint() bytearray() callable() chr() From 965aa0b6be00464ba7e8da3d80c0770d04f6e4b5 Mon Sep 17 00:00:00 2001 From: nfnty Date: Wed, 9 Jan 2019 16:13:17 +0000 Subject: [PATCH 17/25] Fix `PendingDeprecationWarning` typo Fixes #44 --- syntax/python.vim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/syntax/python.vim b/syntax/python.vim index 90b6df8..070c69f 100644 --- a/syntax/python.vim +++ b/syntax/python.vim @@ -387,7 +387,7 @@ endif " if s:Enabled('g:python_highlight_exceptions') - let s:exs_re = 'BaseException|Exception|ArithmeticError|LookupError|EnvironmentError|AssertionError|AttributeError|BufferError|EOFError|FloatingPointError|GeneratorExit|IOError|ImportError|IndexError|KeyError|KeyboardInterrupt|MemoryError|NameError|NotImplementedError|OSError|OverflowError|ReferenceError|RuntimeError|StopIteration|SyntaxError|IndentationError|TabError|SystemError|SystemExit|TypeError|UnboundLocalError|UnicodeError|UnicodeEncodeError|UnicodeDecodeError|UnicodeTranslateError|ValueError|VMSError|WindowsError|ZeroDivisionError|Warning|UserWarning|BytesWarning|DeprecationWarning|PendingDepricationWarning|SyntaxWarning|RuntimeWarning|FutureWarning|ImportWarning|UnicodeWarning' + let s:exs_re = 'BaseException|Exception|ArithmeticError|LookupError|EnvironmentError|AssertionError|AttributeError|BufferError|EOFError|FloatingPointError|GeneratorExit|IOError|ImportError|IndexError|KeyError|KeyboardInterrupt|MemoryError|NameError|NotImplementedError|OSError|OverflowError|ReferenceError|RuntimeError|StopIteration|SyntaxError|IndentationError|TabError|SystemError|SystemExit|TypeError|UnboundLocalError|UnicodeError|UnicodeEncodeError|UnicodeDecodeError|UnicodeTranslateError|ValueError|VMSError|WindowsError|ZeroDivisionError|Warning|UserWarning|BytesWarning|DeprecationWarning|PendingDeprecationWarning|SyntaxWarning|RuntimeWarning|FutureWarning|ImportWarning|UnicodeWarning' if s:Python2Syntax() let s:exs_re .= '|StandardError' From e588125531b42e4360f3e5fbaa2d00280750e612 Mon Sep 17 00:00:00 2001 From: nfnty Date: Wed, 9 Jan 2019 16:17:04 +0000 Subject: [PATCH 18/25] Fix parsing floats with no number trailing the `.` Fixes #41 --- syntax/python.vim | 2 +- tests/test.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/syntax/python.vim b/syntax/python.vim index 070c69f..732a750 100644 --- a/syntax/python.vim +++ b/syntax/python.vim @@ -332,7 +332,7 @@ else syn match pythonFloat '\.\d\%([_0-9]*\d\)\=\%([eE][+-]\=\d\%([_0-9]*\d\)\=\)\=[jJ]\=\>' display syn match pythonFloat '\<\d\%([_0-9]*\d\)\=[eE][+-]\=\d\%([_0-9]*\d\)\=[jJ]\=\>' display - syn match pythonFloat '\<\d\%([_0-9]*\d\)\=\.\d\%([_0-9]*\d\)\=\%([eE][+-]\=\d\%([_0-9]*\d\)\=\)\=[jJ]\=' display + syn match pythonFloat '\<\d\%([_0-9]*\d\)\=\.\d\=\%([_0-9]*\d\)\=\%([eE][+-]\=\d\%([_0-9]*\d\)\=\)\=[jJ]\=' display endif " diff --git a/tests/test.py b/tests/test.py index c1defac..a30ef6b 100644 --- a/tests/test.py +++ b/tests/test.py @@ -189,7 +189,7 @@ async def Test # Numbers -0 1 2 9 10 0x1f .3 12.34 0j 124j 34.2E-3 0b10 0o77 1023434 0x0 +0 1 2 9 10 0x1f 1. .3 12.34 0j 124j 34.2E-3 0b10 0o77 1023434 0x0 1_1 1_1.2_2 1_2j 0x_1f 0x1_f 34_56e-3 34_56e+3_1 0o7_7 # Erroneous numbers From fd7a8868eb293e040ed6676655c3c34769641511 Mon Sep 17 00:00:00 2001 From: Ricardo Madriz Date: Sat, 23 Feb 2019 17:21:56 -0600 Subject: [PATCH 19/25] hightlight class variables inside f-strings --- syntax/python.vim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/syntax/python.vim b/syntax/python.vim index 732a750..d86cdc5 100644 --- a/syntax/python.vim +++ b/syntax/python.vim @@ -98,7 +98,7 @@ else 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,pythonBytes,pythonBoolean,pythonNone,pythonSingleton,pythonBuiltinObj,pythonBuiltinFunc,pythonBuiltinType,pythonClassVar endif From 583466d270dc68fdd10ae6563781289a5817e353 Mon Sep 17 00:00:00 2001 From: Ricardo Madriz Date: Sat, 23 Feb 2019 17:22:04 -0600 Subject: [PATCH 20/25] test change --- tests/test.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/tests/test.py b/tests/test.py index a30ef6b..5c37896 100644 --- a/tests/test.py +++ b/tests/test.py @@ -244,6 +244,11 @@ async def Test f'brackets: {{ 1 + 2 }} and {{{{ 3 + 4 }}}}' fr'this {that}' + +class Atest: + def amethod(self): + print(f"{self.__name__}") + # Doctests. """ From 3e46cc73e3c150114477936fd378d202cdadc4dc Mon Sep 17 00:00:00 2001 From: Ricardo Madriz Date: Sat, 12 Oct 2019 23:06:31 -0600 Subject: [PATCH 21/25] Fix typo --- syntax/python.vim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/syntax/python.vim b/syntax/python.vim index d86cdc5..1fa7bcc 100644 --- a/syntax/python.vim +++ b/syntax/python.vim @@ -75,7 +75,7 @@ if s:Enabled('g:python_highlight_class_vars') endif syn keyword pythonRepeat for while syn keyword pythonConditional if elif else -syn keyword pythonException try except finally +syn keyword pythonExceptions try except finally " The standard pyrex.vim unconditionally removes the pythonInclude group, so " we provide a dummy group here to avoid crashing pyrex.vim. syn keyword pythonInclude import From ab5aadac25f9e5ecf6a584fc8103cacf99b0cc36 Mon Sep 17 00:00:00 2001 From: Ricardo Madriz Date: Sat, 12 Oct 2019 23:14:20 -0600 Subject: [PATCH 22/25] Simplify async-related keywords syntax --- syntax/python.vim | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/syntax/python.vim b/syntax/python.vim index 1fa7bcc..a3af865 100644 --- a/syntax/python.vim +++ b/syntax/python.vim @@ -93,11 +93,8 @@ if s:Python2Syntax() syn match pythonFunction '[a-zA-Z_][a-zA-Z0-9_]*' display contained else syn keyword pythonStatement as nonlocal - syn match pythonStatement '\v\.@' + syn keyword pythonAsync async await syn match pythonFunction '\%([^[: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,pythonClassVar endif @@ -419,6 +416,7 @@ if v:version >= 508 || !exists('did_python_syn_inits') HiLink pythonStatement Statement HiLink pythonRaiseFromStatement Statement + HiLink pythonAsync Statement HiLink pythonImport Include HiLink pythonFunction Function HiLink pythonClassName Structure From 42f36c71d6a4de03dc3d44db17ea3015cf3caf9b Mon Sep 17 00:00:00 2001 From: Ricardo Madriz Date: Sat, 12 Oct 2019 23:16:12 -0600 Subject: [PATCH 23/25] Ignore non-special text inside f-strings --- syntax/python.vim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/syntax/python.vim b/syntax/python.vim index a3af865..d5e0628 100644 --- a/syntax/python.vim +++ b/syntax/python.vim @@ -460,7 +460,7 @@ if v:version >= 508 || !exists('did_python_syn_inits') HiLink pythonBytesEscapeError Error HiLink pythonFString String HiLink pythonRawFString String - HiLink pythonStrInterpRegion Special + HiLink pythonStrInterpRegion Ignored endif HiLink pythonStrFormatting Special From ad4f72bf73f4577c007039bbd17986873bcbbdf2 Mon Sep 17 00:00:00 2001 From: Ricardo Madriz Date: Sat, 12 Oct 2019 23:17:12 -0600 Subject: [PATCH 24/25] Link pythonClassVar to Special --- syntax/python.vim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/syntax/python.vim b/syntax/python.vim index d5e0628..54b9a8b 100644 --- a/syntax/python.vim +++ b/syntax/python.vim @@ -489,7 +489,7 @@ if v:version >= 508 || !exists('did_python_syn_inits') HiLink pythonBuiltinType Structure HiLink pythonExClass Structure - HiLink pythonClassVar Identifier + HiLink pythonClassVar Special delcommand HiLink endif From b6c642b518a755f43354d607cb7111af59b630f4 Mon Sep 17 00:00:00 2001 From: Ricardo Madriz Date: Sat, 12 Oct 2019 23:19:34 -0600 Subject: [PATCH 25/25] Add more test cases --- tests/test.py | 40 +++++++++++++++++++++++++++++++++++++--- 1 file changed, 37 insertions(+), 3 deletions(-) diff --git a/tests/test.py b/tests/test.py index 5c37896..9a052db 100644 --- a/tests/test.py +++ b/tests/test.py @@ -8,15 +8,32 @@ # Keywords. -with break continue del return pass raise global assert lambda yield -for while if elif else import as try except finally - from test import var as name +import as +with break continue del return pass raise global assert lambda yield +async await +for while if elif else try except finally +while True: + continue; break; return; yield + +try: + v = int(0.1) + raise RuntimeError() +except: + pass +else: + pass +finally: + pass + raise Exception from ex yield from +with open() as f_x: + pass + def functionname class Classname class classname @@ -24,7 +41,20 @@ def функция class Класс class класс +class A: + def __new__(cls): + super() + pass + + def method(self): + print(f'{self.__class__.__name__}') + var = a_var(kw=True) + afloat = 0.1 + print(f'The float is {afloat + 1}') + +if __name__ == '__main__': + main() # Keywords: Python 2 exec @@ -43,6 +73,10 @@ async def Test __debug__ __doc__ __file__ __name__ __package__ __loader__ __spec__ __path__ __cached__ +# Dunders +__slots__ __all__ __version__ __qualname__ __module__ __defaults__ __code__ +__globals__ __dict__ __closure__ __annotations__ __kwdefaults__ + # Bultin types bool bytearray dict float frozenset int list object set str tuple