Skip to content

Highlight class vars inside f-strings #56

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 26 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
31d6023
separate pythonClassName from pythonFunction
koka831 Jul 8, 2017
89881c3
remove regex for pythonClassName
koka831 Jul 31, 2017
ac576c5
modify regex for pythonClassName
koka831 Jul 31, 2017
28776a5
use :upper:
koka831 Jul 31, 2017
71b4ecc
fix regex
koka831 Jul 31, 2017
aa9d431
fix
koka831 Jul 31, 2017
ed4966c
use :upper:
koka831 Jul 31, 2017
b412bd0
fix regexp: recog :upper:
koka831 Jul 31, 2017
4d8ecd6
hightlight class variables inside f-strings
richin13 Feb 23, 2019
8e76189
test change
richin13 Feb 23, 2019
83ae752
move {{ and }} matching so that it gets highlighted correctly
lilydjwg Jul 27, 2017
bb4a0b2
Fix raw f-string interpolation
nfnty Aug 4, 2017
5024a66
Remove highlight link from `pythonDot` to `Normal`
nfnty Jan 9, 2019
8892101
Add `pythonNone` to `pythonExpression`
cdonovick Dec 18, 2018
13efe6f
Split builtin objects / types
cdonovick Dec 18, 2018
cbcfd09
Add builtin function `breakpoint`
nfnty Jan 9, 2019
965aa0b
Fix `PendingDeprecationWarning` typo
nfnty Jan 9, 2019
e588125
Fix parsing floats with no number trailing the `.`
nfnty Jan 9, 2019
fd7a886
hightlight class variables inside f-strings
richin13 Feb 23, 2019
583466d
test change
richin13 Feb 23, 2019
81962c1
Merge pull request #1 from richin13/class-patch1
richin13 Oct 13, 2019
3e46cc7
Fix typo
richin13 Oct 13, 2019
ab5aada
Simplify async-related keywords syntax
richin13 Oct 13, 2019
42f36c7
Ignore non-special text inside f-strings
richin13 Oct 13, 2019
ad4f72b
Link pythonClassVar to Special
richin13 Oct 13, 2019
b6c642b
Add more test cases
richin13 Oct 13, 2019
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
22 changes: 13 additions & 9 deletions syntax/python.vim
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,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
Expand All @@ -64,13 +65,17 @@ 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
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
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
Expand All @@ -88,12 +93,9 @@ 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\.@<!<await>'
syn keyword pythonAsync async await
syn match pythonFunction '\%([^[:cntrl:][:space:][:punct:][:digit:]]\|_\)\%([^[:cntrl:][:punct:][:space:]]\|_\)*' display contained
syn match pythonStatement '\<async\s\+def\>' nextgroup=pythonFunction skipwhite
syn match pythonStatement '\<async\s\+with\>'
syn match pythonStatement '\<async\s\+for\>'
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


Expand Down Expand Up @@ -414,8 +416,10 @@ 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
HiLink pythonConditional Conditional
HiLink pythonRepeat Repeat
HiLink pythonException Exception
Expand Down Expand Up @@ -456,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
Expand Down Expand Up @@ -485,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
Expand Down
48 changes: 45 additions & 3 deletions tests/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,53 @@

# 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
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
Expand All @@ -40,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
Expand Down Expand Up @@ -241,6 +278,11 @@ async def Test
f'brackets: {{ 1 + 2 }} and {{{{ 3 + 4 }}}}'
fr'this {that}'


class Atest:
def amethod(self):
print(f"{self.__name__}")

# Doctests.

"""
Expand Down