mirror of
https://github.com/gryf/python-syntax.git
synced 2025-12-17 11:30:27 +01:00
Update to latest vim syntax highlight
This commit is contained in:
@@ -1,3 +1,9 @@
|
||||
Revision 9.1.0 (2024-10-30):
|
||||
|
||||
- Update to official Python syntax in vim
|
||||
- Drop all the old code
|
||||
- Version tag will be aligned with vim upstream and moved if needed
|
||||
|
||||
Revision 3.6.0 (2015-11-XX):
|
||||
|
||||
- Fix 'async def' highlighting. Patch by Joongi Kim
|
||||
|
||||
138
README.rst
138
README.rst
@@ -6,142 +6,24 @@ Python syntax highlighting script for Vim
|
||||
About
|
||||
-----
|
||||
|
||||
Enhanced version of the original Python syntax highlighting script. Based on
|
||||
``python.vim`` from Vim 6.1 distribution by Neil Schemenauer (nas at python dot
|
||||
ca). Check also `python.vim page on vim.org
|
||||
<http://www.vim.org/scripts/script.php?script_id=790>`_.
|
||||
|
||||
Please use the following channels for reporting bugs, offering suggestions or
|
||||
feedback:
|
||||
|
||||
- python.vim issue tracker: https://github.com/hdima/python-syntax/issues
|
||||
- Email: Dmitry Vasiliev (dima at hlabs.org)
|
||||
- Send a message or follow me for updates on Twitter: `@hdima
|
||||
<https://twitter.com/hdima>`__
|
||||
Customized version of Python syntax highlighting script. Based on latest vim
|
||||
Python syntax highlighting.
|
||||
|
||||
Features
|
||||
--------
|
||||
|
||||
Changes from the original ``python.vim`` are:
|
||||
|
||||
- Added support for Python 3 syntax highlighting
|
||||
- Added ``:Python2Syntax`` and ``:Python3Syntax`` commands which allow to
|
||||
switch between Python 2 and Python 3 syntaxes respectively without
|
||||
reloads/restarts
|
||||
- Updated strings highlighting
|
||||
- Enhanced special symbols highlighting inside strings
|
||||
- Enhanced highlighting of numeric constants
|
||||
- Added optional highlighting for %-formatting inside strings
|
||||
- Added highlighting for magic comments: source code encoding and #!
|
||||
(executable) strings
|
||||
- Added highlighting for new exceptions and builtins
|
||||
- Added highlighting for doctests
|
||||
- Added highlighting for new ``@decorator`` syntax introduced in Python 2.4a2
|
||||
- Added highlighting for the following errors:
|
||||
|
||||
- invalid symbols in source file
|
||||
- mixing spaces and tabs
|
||||
- invalid numeric constants
|
||||
- invalid %-formatting inside strings
|
||||
- invalid variable names
|
||||
- trailing spaces (triggered by the ``python_highlight_space_errors`` option)
|
||||
|
||||
Some of these features was later backported into the original ``python.vim``.
|
||||
- Highlighting of ``@decorator`` will catch whole decorator function name,
|
||||
instead of just ``@`` sign.
|
||||
|
||||
How to install
|
||||
--------------
|
||||
|
||||
The easiest installation method is to place `syntax/python.vim
|
||||
<https://github.com/hdima/python-syntax/blob/master/syntax/python.vim>`_ script
|
||||
into your ``~/.vim/syntax/`` directory.
|
||||
To install it, any kind of Vim package manager can be used, like NeoBundle_,
|
||||
Pathogen_, Vundle_ or vim-plug_.
|
||||
|
||||
You can also use `Pathogen <https://github.com/tpope/vim-pathogen>`_ or `Vundle
|
||||
<https://github.com/gmarik/vundle>`_ plugin managers in which case you can
|
||||
install the whole `python.vim repository
|
||||
<https://github.com/hdima/python-syntax>`_ into the corresponding plugins
|
||||
directory.
|
||||
|
||||
Script options
|
||||
--------------
|
||||
|
||||
There are two commands to enable or disable an option:
|
||||
|
||||
``:let OPTION_NAME = 1``
|
||||
Enable option
|
||||
``:let OPTION_NAME = 0``
|
||||
Disable option
|
||||
|
||||
For example to enable all syntax highlighting features you can place the
|
||||
following command in your ``~/.vimrc`` script::
|
||||
|
||||
let python_highlight_all = 1
|
||||
|
||||
Option and commands to select Python version
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
``python_version_2``
|
||||
Enable highlighting for Python 2 (Python 3 highlighting is enabled by
|
||||
default). Also can be set as a local to buffer ``b:python_version_2``
|
||||
variable.
|
||||
|
||||
The following local to buffer commands can be used to switch between two
|
||||
highlighting modes:
|
||||
|
||||
``:Python2Syntax``
|
||||
Switch to Python 2 highlighting mode
|
||||
``:Python3Syntax``
|
||||
Switch to Python 3 highlighting mode
|
||||
|
||||
Options used by the script
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
``python_highlight_builtins``
|
||||
Highlight builtin functions and objects
|
||||
``python_highlight_builtin_objs``
|
||||
Highlight builtin objects only
|
||||
``python_highlight_builtin_funcs``
|
||||
Highlight builtin functions only
|
||||
``python_highlight_exceptions``
|
||||
Highlight standard exceptions
|
||||
``python_highlight_string_formatting``
|
||||
Highlight ``%`` string formatting
|
||||
``python_highlight_string_format``
|
||||
Highlight syntax of ``str.format`` syntax
|
||||
``python_highlight_string_templates``
|
||||
Highlight syntax of ``string.Template``
|
||||
``python_highlight_indent_errors``
|
||||
Highlight indentation errors
|
||||
``python_highlight_space_errors``
|
||||
Highlight trailing spaces
|
||||
``python_highlight_doctests``
|
||||
Highlight doc-tests
|
||||
``python_print_as_function``
|
||||
Highlight ``print`` statement as function for Python 2
|
||||
``python_highlight_file_headers_as_comments``
|
||||
Highlight shebang and coding headers as comments
|
||||
``python_highlight_all``
|
||||
Enable all the options above. *NOTE: This option don't override any
|
||||
previously set options*
|
||||
``python_slow_sync``
|
||||
Can be set to 0 for slow machines
|
||||
|
||||
Contributors
|
||||
------------
|
||||
|
||||
List of the contributors in alphabetical order:
|
||||
|
||||
- `Andrea Riciputi <https://github.com/mrrech>`_
|
||||
- Anton Butanaev
|
||||
- `Antony Lee <https://github.com/anntzer>`_
|
||||
- Caleb Adamantine
|
||||
- `David Briscoe <https://github.com/idbrii>`_
|
||||
- `Elizabeth Myers <https://github.com/Elizafox>`_
|
||||
- `Ihor Gorobets <https://github.com/iho>`_
|
||||
- `Jeroen Ruigrok van der Werven <https://github.com/ashemedai>`_
|
||||
- `John Eikenberry <https://github.com/eikenb>`_
|
||||
- `Joongi Kim <https://github.com/achimnol>`_
|
||||
- `Marc Weber <https://github.com/MarcWeber>`_
|
||||
- `Pedro Algarvio <https://github.com/s0undt3ch>`_
|
||||
- `Victor Salgado <https://github.com/mcsalgado>`_
|
||||
- `Will Gray <https://github.com/graywh>`_
|
||||
- `Yuri Habrusiev <https://github.com/yuriihabrusiev>`_
|
||||
.. _Pathogen: https://github.com/tpope/vim-pathogen
|
||||
.. _Vundle: https://github.com/gmarik/Vundle.vim
|
||||
.. _NeoBundle: https://github.com/Shougo/neobundle.vim
|
||||
.. _vim-plug: https://github.com/junegunn/vim-plug
|
||||
|
||||
26
TODO.txt
26
TODO.txt
@@ -1,26 +0,0 @@
|
||||
Now
|
||||
===
|
||||
|
||||
- It seems python.vim doesn't highlight special characters inside strings by
|
||||
default but only when reloaded? Or maybe only when set to Python 2
|
||||
by default?
|
||||
|
||||
- Add support for slice syntax:
|
||||
http://img155.imageshack.us/img155/7767/screenshotgs.png
|
||||
|
||||
- When we check spelling we don't need to check the whole strings only the
|
||||
content. For example we don't need to check 'u' for spelling in strings
|
||||
like this: u"Some text";
|
||||
|
||||
Later
|
||||
=====
|
||||
|
||||
- Need more accurate way to handle indentation errors. For example
|
||||
mixing spaces and tabs may be used for pretty formatting;
|
||||
|
||||
- Need more checks for errors like: absent brackets, absent quotes,
|
||||
back slash at the end of strings;
|
||||
|
||||
- pythonError tips from
|
||||
http://blog.sontek.net/2008/05/11/python-with-a-modular-ide-vim/ (reported by
|
||||
Giuliani Deon Sanches)
|
||||
65
syntax.txt
65
syntax.txt
@@ -1,65 +0,0 @@
|
||||
PYTHON *python.vim* *ft-python-syntax*
|
||||
|
||||
There are two commands to enable or disable an option for python.vim
|
||||
|
||||
Enable option: >
|
||||
:let option_name = 1
|
||||
<
|
||||
Disable option: >
|
||||
:let option_name = 0
|
||||
<
|
||||
For example to enable all syntax highlighting features you can place the
|
||||
following command in your `~/.vimrc` script: >
|
||||
|
||||
let python_highlight_all = 1
|
||||
<
|
||||
Option and commands to select Python version: >
|
||||
|
||||
:let python_version_2 = 1
|
||||
<
|
||||
Enable highlighting for Python 2 (Python 3 highlighting is enabled by
|
||||
default). Also can be set as a local to buffer `b:python_version_2`
|
||||
variable.
|
||||
|
||||
The following local to buffer commands can be used to switch between two
|
||||
highlighting modes:
|
||||
|
||||
Switch to Python 2 highlighting mode >
|
||||
:Python2Syntax
|
||||
<
|
||||
Switch to Python 3 highlighting mode >
|
||||
:Python3Syntax
|
||||
<
|
||||
Options used by the script
|
||||
|
||||
Highlight builtin functions and objects >
|
||||
:let python_highlight_builtins = 1
|
||||
< Highlight builtin objects only >
|
||||
:let python_highlight_builtin_objs = 1
|
||||
< Highlight builtin functions only >
|
||||
:let python_highlight_builtin_funcs = 1
|
||||
< Highlight standard exceptions >
|
||||
:let python_highlight_exceptions = 1
|
||||
< Highlight `%` string formatting >
|
||||
:let python_highlight_string_formatting = 1
|
||||
< Highlight syntax of `str.format` syntax >
|
||||
:let python_highlight_string_format = 1
|
||||
< Highlight syntax of `string.Template` >
|
||||
:let python_highlight_string_templates = 1
|
||||
< Highlight indentation errors >
|
||||
:let python_highlight_indent_errors = 1
|
||||
< Highlight trailing spaces >
|
||||
:let python_highlight_space_errors = 1
|
||||
< Highlight doc-tests >
|
||||
:let python_highlight_doctests = 1
|
||||
< Highlight `print` statement as function for Python 2 >
|
||||
:let python_print_as_function = 1
|
||||
< Highlight shebang and coding headers as comments >
|
||||
:let python_highlight_file_headers_as_comments = 1
|
||||
< Enable all the options above. NOTE: This option don't override any
|
||||
previously set options >
|
||||
:let python_highlight_all = 1
|
||||
< Can be set to 0 for slow machines >
|
||||
:let python_slow_sync = 1
|
||||
<
|
||||
vim:tw=78:sw=4:ts=8:ft=help:norl:
|
||||
@@ -1,568 +1,340 @@
|
||||
" Vim syntax file
|
||||
" Language: Python
|
||||
" Current Maintainer: Dmitry Vasiliev <dima at hlabs dot org>
|
||||
" Previous Maintainer: Neil Schemenauer <nas at python dot ca>
|
||||
" URL: https://github.com/hdima/python-syntax
|
||||
" Last Change: 2015-11-01
|
||||
" Filenames: *.py
|
||||
" Version: 3.6.0
|
||||
" Language: Python
|
||||
" Maintainer: Zvezdan Petkovic <zpetkovic@acm.org>
|
||||
" Last Change: 2023 Feb 28
|
||||
" Credits: Neil Schemenauer <nas@python.ca>
|
||||
" Dmitry Vasiliev
|
||||
"
|
||||
" Based on python.vim (from Vim 6.1 distribution)
|
||||
" by Neil Schemenauer <nas at python dot ca>
|
||||
" This version is a major rewrite by Zvezdan Petkovic.
|
||||
"
|
||||
" Please use the following channels for reporting bugs, offering suggestions or
|
||||
" feedback:
|
||||
|
||||
" - python.vim issue tracker: https://github.com/hdima/python-syntax/issues
|
||||
" - Email: Dmitry Vasiliev (dima at hlabs.org)
|
||||
" - Send a message or follow me for updates on Twitter: `@hdima
|
||||
" <https://twitter.com/hdima>`__
|
||||
" - introduced highlighting of doctests
|
||||
" - updated keywords, built-ins, and exceptions
|
||||
" - corrected regular expressions for
|
||||
"
|
||||
" Contributors
|
||||
" ============
|
||||
" * functions
|
||||
" * decorators
|
||||
" * strings
|
||||
" * escapes
|
||||
" * numbers
|
||||
" * space error
|
||||
"
|
||||
" List of the contributors in alphabetical order:
|
||||
" - corrected synchronization
|
||||
" - more highlighting is ON by default, except
|
||||
" - space error highlighting is OFF by default
|
||||
"
|
||||
" Andrea Riciputi
|
||||
" Anton Butanaev
|
||||
" Antony Lee
|
||||
" Caleb Adamantine
|
||||
" David Briscoe
|
||||
" Elizabeth Myers
|
||||
" Ihor Gorobets
|
||||
" Jeroen Ruigrok van der Werven
|
||||
" John Eikenberry
|
||||
" Joongi Kim
|
||||
" Marc Weber
|
||||
" Pedro Algarvio
|
||||
" Victor Salgado
|
||||
" Will Gray
|
||||
" Yuri Habrusiev
|
||||
" Optional highlighting can be controlled using these variables.
|
||||
"
|
||||
" Options
|
||||
" =======
|
||||
" let python_no_builtin_highlight = 1
|
||||
" let python_no_doctest_code_highlight = 1
|
||||
" let python_no_doctest_highlight = 1
|
||||
" let python_no_exception_highlight = 1
|
||||
" let python_no_number_highlight = 1
|
||||
" let python_space_error_highlight = 1
|
||||
"
|
||||
" :let OPTION_NAME = 1 Enable option
|
||||
" :let OPTION_NAME = 0 Disable option
|
||||
" All the options above can be switched on together.
|
||||
"
|
||||
" let python_highlight_all = 1
|
||||
"
|
||||
" Option to select Python version
|
||||
" -------------------------------
|
||||
" The use of Python 2 compatible syntax highlighting can be enforced.
|
||||
" The straddling code (Python 2 and 3 compatible), up to Python 3.5,
|
||||
" will be also supported.
|
||||
"
|
||||
" python_version_2 Enable highlighting for Python 2
|
||||
" (Python 3 highlighting is enabled
|
||||
" by default). Can also be set as
|
||||
" a buffer (b:python_version_2)
|
||||
" variable.
|
||||
" let python_use_python2_syntax = 1
|
||||
"
|
||||
" You can also use the following local to buffer commands to switch
|
||||
" between two highlighting modes:
|
||||
"
|
||||
" :Python2Syntax Switch to Python 2 highlighting
|
||||
" mode
|
||||
" :Python3Syntax Switch to Python 3 highlighting
|
||||
" mode
|
||||
"
|
||||
" Option names used by the script
|
||||
" -------------------------------
|
||||
"
|
||||
" python_highlight_builtins Highlight builtin functions and
|
||||
" objects
|
||||
" python_highlight_builtin_objs Highlight builtin objects only
|
||||
" python_highlight_builtin_funcs Highlight builtin functions only
|
||||
" python_highlight_exceptions Highlight standard exceptions
|
||||
" python_highlight_string_formatting Highlight % string formatting
|
||||
" python_highlight_string_format Highlight str.format syntax
|
||||
" python_highlight_string_templates Highlight string.Template syntax
|
||||
" python_highlight_indent_errors Highlight indentation errors
|
||||
" python_highlight_space_errors Highlight trailing spaces
|
||||
" python_highlight_doctests Highlight doc-tests
|
||||
" python_print_as_function Highlight 'print' statement as
|
||||
" function for Python 2
|
||||
" python_highlight_file_headers_as_comments
|
||||
" Highlight shebang and coding
|
||||
" headers as comments
|
||||
"
|
||||
" python_highlight_all Enable all the options above
|
||||
" NOTE: This option don't override
|
||||
" any previously set options
|
||||
"
|
||||
" python_slow_sync Can be set to 0 for slow machines
|
||||
" This option will exclude all modern Python 3.6 or higher features.
|
||||
"
|
||||
|
||||
" For version 5.x: Clear all syntax items
|
||||
" For versions greater than 6.x: Quit when a syntax file was already loaded
|
||||
if version < 600
|
||||
syntax clear
|
||||
elseif exists("b:current_syntax")
|
||||
" quit when a syntax file was already loaded.
|
||||
if exists("b:current_syntax")
|
||||
finish
|
||||
endif
|
||||
|
||||
"
|
||||
" Commands
|
||||
"
|
||||
command! -buffer Python2Syntax let b:python_version_2 = 1 | let &syntax=&syntax
|
||||
command! -buffer Python3Syntax let b:python_version_2 = 0 | let &syntax=&syntax
|
||||
" Use of Python 2 and 3.5 or lower requested.
|
||||
if exists("python_use_python2_syntax")
|
||||
runtime! syntax/python2.vim
|
||||
finish
|
||||
endif
|
||||
|
||||
" Enable option if it's not defined
|
||||
function! s:EnableByDefault(name)
|
||||
if !exists(a:name)
|
||||
let {a:name} = 1
|
||||
" We need nocompatible mode in order to continue lines with backslashes.
|
||||
" Original setting will be restored.
|
||||
let s:cpo_save = &cpo
|
||||
set cpo&vim
|
||||
|
||||
if exists("python_no_doctest_highlight")
|
||||
let python_no_doctest_code_highlight = 1
|
||||
endif
|
||||
|
||||
if exists("python_highlight_all")
|
||||
if exists("python_no_builtin_highlight")
|
||||
unlet python_no_builtin_highlight
|
||||
endif
|
||||
endfunction
|
||||
|
||||
" Check if option is enabled
|
||||
function! s:Enabled(name)
|
||||
return exists(a:name) && {a:name}
|
||||
endfunction
|
||||
|
||||
" Is it Python 2 syntax?
|
||||
function! s:Python2Syntax()
|
||||
if exists("b:python_version_2")
|
||||
return b:python_version_2
|
||||
if exists("python_no_doctest_code_highlight")
|
||||
unlet python_no_doctest_code_highlight
|
||||
endif
|
||||
return s:Enabled("g:python_version_2")
|
||||
endfunction
|
||||
|
||||
"
|
||||
" Default options
|
||||
"
|
||||
|
||||
call s:EnableByDefault("g:python_slow_sync")
|
||||
|
||||
if s:Enabled("g:python_highlight_all")
|
||||
call s:EnableByDefault("g:python_highlight_builtins")
|
||||
if s:Enabled("g:python_highlight_builtins")
|
||||
call s:EnableByDefault("g:python_highlight_builtin_objs")
|
||||
call s:EnableByDefault("g:python_highlight_builtin_funcs")
|
||||
if exists("python_no_doctest_highlight")
|
||||
unlet python_no_doctest_highlight
|
||||
endif
|
||||
call s:EnableByDefault("g:python_highlight_exceptions")
|
||||
call s:EnableByDefault("g:python_highlight_string_formatting")
|
||||
call s:EnableByDefault("g:python_highlight_string_format")
|
||||
call s:EnableByDefault("g:python_highlight_string_templates")
|
||||
call s:EnableByDefault("g:python_highlight_indent_errors")
|
||||
call s:EnableByDefault("g:python_highlight_space_errors")
|
||||
call s:EnableByDefault("g:python_highlight_doctests")
|
||||
call s:EnableByDefault("g:python_print_as_function")
|
||||
endif
|
||||
|
||||
"
|
||||
" Keywords
|
||||
"
|
||||
|
||||
syn keyword pythonStatement break continue del
|
||||
syn keyword pythonStatement exec return
|
||||
syn keyword pythonStatement pass raise
|
||||
syn keyword pythonStatement global assert
|
||||
syn keyword pythonStatement lambda
|
||||
syn keyword pythonStatement with
|
||||
syn keyword pythonStatement def class nextgroup=pythonFunction skipwhite
|
||||
syn keyword pythonRepeat for while
|
||||
syn keyword pythonConditional if elif else
|
||||
" 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
|
||||
syn keyword pythonImport import
|
||||
syn keyword pythonException try except finally
|
||||
syn keyword pythonOperator and in is not or
|
||||
|
||||
syn match pythonStatement "\<yield\>" display
|
||||
syn match pythonImport "\<from\>" display
|
||||
|
||||
if s:Python2Syntax()
|
||||
if !s:Enabled("g:python_print_as_function")
|
||||
syn keyword pythonStatement print
|
||||
if exists("python_no_exception_highlight")
|
||||
unlet python_no_exception_highlight
|
||||
endif
|
||||
syn keyword pythonImport as
|
||||
syn match pythonFunction "[a-zA-Z_][a-zA-Z0-9_]*" display contained
|
||||
else
|
||||
syn keyword pythonStatement as nonlocal None
|
||||
syn match pythonStatement "\<yield\s\+from\>" display
|
||||
syn keyword pythonBoolean True False
|
||||
syn match pythonFunction "\%([^[:cntrl:][:space:][:punct:][:digit:]]\|_\)\%([^[:cntrl:][:punct:][:space:]]\|_\)*" display contained
|
||||
syn keyword pythonStatement await
|
||||
syn match pythonStatement "\<async\s\+def\>" nextgroup=pythonFunction skipwhite
|
||||
syn match pythonStatement "\<async\s\+with\>" display
|
||||
syn match pythonStatement "\<async\s\+for\>" display
|
||||
if exists("python_no_number_highlight")
|
||||
unlet python_no_number_highlight
|
||||
endif
|
||||
let python_space_error_highlight = 1
|
||||
endif
|
||||
|
||||
" Keep Python keywords in alphabetical order inside groups for easy
|
||||
" comparison with the table in the 'Python Language Reference'
|
||||
" https://docs.python.org/reference/lexical_analysis.html#keywords.
|
||||
" Groups are in the order presented in NAMING CONVENTIONS in syntax.txt.
|
||||
" Exceptions come last at the end of each group (class and def below).
|
||||
"
|
||||
" Decorators (new in Python 2.4)
|
||||
" The list can be checked using:
|
||||
"
|
||||
|
||||
syn match pythonDecorator "@" display nextgroup=pythonDecorator skipwhite
|
||||
if s:Python2Syntax()
|
||||
syn match pythonDecorator "[a-zA-Z_][a-zA-Z0-9_]*\%(\.[a-zA-Z_][a-zA-Z0-9_]*\)*" display contained
|
||||
else
|
||||
syn match pythonDecorator "\%([^[:cntrl:][:space:][:punct:][:digit:]]\|_\)\%([^[:cntrl:][:punct:][:space:]]\|_\)*\%(\.\%([^[:cntrl:][:space:][:punct:][:digit:]]\|_\)\%([^[:cntrl:][:punct:][:space:]]\|_\)*\)*" display contained
|
||||
endif
|
||||
syn match pythonDot "\." display containedin=pythonDecorator
|
||||
|
||||
" python3 -c 'import keyword, pprint; pprint.pprint(keyword.kwlist + keyword.softkwlist, compact=True)'
|
||||
"
|
||||
" Comments
|
||||
syn keyword pythonStatement False None True
|
||||
syn keyword pythonStatement as assert break continue del global
|
||||
syn keyword pythonStatement lambda nonlocal pass return with yield
|
||||
syn keyword pythonStatement class def nextgroup=pythonFunction skipwhite
|
||||
syn keyword pythonConditional elif else if
|
||||
syn keyword pythonRepeat for while
|
||||
syn keyword pythonOperator and in is not or
|
||||
syn keyword pythonException except finally raise try
|
||||
syn keyword pythonInclude from import
|
||||
syn keyword pythonAsync async await
|
||||
|
||||
" Soft keywords
|
||||
" These keywords do not mean anything unless used in the right context.
|
||||
" See https://docs.python.org/3/reference/lexical_analysis.html#soft-keywords
|
||||
" for more on this.
|
||||
syn match pythonConditional "^\s*\zscase\%(\s\+.*:.*$\)\@="
|
||||
syn match pythonConditional "^\s*\zsmatch\%(\s\+.*:\s*\%(#.*\)\=$\)\@="
|
||||
|
||||
" Decorators
|
||||
" A dot must be allowed because of @MyClass.myfunc decorators.
|
||||
syn match pythonDecorator "@" display contained
|
||||
syn match pythonDecoratorName "@\s*\h\%(\w\|\.\)*" display contains=pythonDecorator
|
||||
|
||||
" Python 3.5 introduced the use of the same symbol for matrix multiplication:
|
||||
" https://www.python.org/dev/peps/pep-0465/. We now have to exclude the
|
||||
" symbol from highlighting when used in that context.
|
||||
" Single line multiplication.
|
||||
syn match pythonMatrixMultiply
|
||||
\ "\%(\w\|[])]\)\s*@"
|
||||
\ contains=ALLBUT,pythonDecoratorName,pythonDecorator,pythonFunction,pythonDoctestValue
|
||||
\ transparent
|
||||
" Multiplication continued on the next line after backslash.
|
||||
syn match pythonMatrixMultiply
|
||||
\ "[^\\]\\\s*\n\%(\s*\.\.\.\s\)\=\s\+@"
|
||||
\ contains=ALLBUT,pythonDecoratorName,pythonDecorator,pythonFunction,pythonDoctestValue
|
||||
\ transparent
|
||||
" Multiplication in a parenthesized expression over multiple lines with @ at
|
||||
" the start of each continued line; very similar to decorators and complex.
|
||||
syn match pythonMatrixMultiply
|
||||
\ "^\s*\%(\%(>>>\|\.\.\.\)\s\+\)\=\zs\%(\h\|\%(\h\|[[(]\).\{-}\%(\w\|[])]\)\)\s*\n\%(\s*\.\.\.\s\)\=\s\+@\%(.\{-}\n\%(\s*\.\.\.\s\)\=\s\+@\)*"
|
||||
\ contains=ALLBUT,pythonDecoratorName,pythonDecorator,pythonFunction,pythonDoctestValue
|
||||
\ transparent
|
||||
|
||||
syn match pythonFunction "\h\w*" display contained
|
||||
|
||||
syn match pythonComment "#.*$" contains=pythonTodo,@Spell
|
||||
syn keyword pythonTodo FIXME NOTE NOTES TODO XXX contained
|
||||
|
||||
" Triple-quoted strings can contain doctests.
|
||||
syn region pythonString matchgroup=pythonQuotes
|
||||
\ start=+[uU]\=\z(['"]\)+ end="\z1" skip="\\\\\|\\\z1"
|
||||
\ contains=pythonEscape,@Spell
|
||||
syn region pythonString matchgroup=pythonTripleQuotes
|
||||
\ start=+[uU]\=\z('''\|"""\)+ end="\z1" keepend
|
||||
\ contains=pythonEscape,pythonSpaceError,pythonDoctest,@Spell
|
||||
syn region pythonRawString matchgroup=pythonQuotes
|
||||
\ start=+[uU]\=[rR]\z(['"]\)+ end="\z1" skip="\\\\\|\\\z1"
|
||||
\ contains=@Spell
|
||||
syn region pythonRawString matchgroup=pythonTripleQuotes
|
||||
\ start=+[uU]\=[rR]\z('''\|"""\)+ end="\z1" keepend
|
||||
\ contains=pythonSpaceError,pythonDoctest,@Spell
|
||||
|
||||
syn match pythonEscape +\\[abfnrtv'"\\]+ contained
|
||||
syn match pythonEscape "\\\o\{1,3}" contained
|
||||
syn match pythonEscape "\\x\x\{2}" contained
|
||||
syn match pythonEscape "\%(\\u\x\{4}\|\\U\x\{8}\)" contained
|
||||
" Python allows case-insensitive Unicode IDs: http://www.unicode.org/charts/
|
||||
syn match pythonEscape "\\N{\a\+\%(\s\a\+\)*}" contained
|
||||
syn match pythonEscape "\\$"
|
||||
|
||||
" It is very important to understand all details before changing the
|
||||
" regular expressions below or their order.
|
||||
" The word boundaries are *not* the floating-point number boundaries
|
||||
" because of a possible leading or trailing decimal point.
|
||||
" The expressions below ensure that all valid number literals are
|
||||
" highlighted, and invalid number literals are not. For example,
|
||||
"
|
||||
|
||||
syn match pythonComment "#.*$" display contains=pythonTodo,@Spell
|
||||
if !s:Enabled("g:python_highlight_file_headers_as_comments")
|
||||
syn match pythonRun "\%^#!.*$"
|
||||
syn match pythonCoding "\%^.*\%(\n.*\)\?#.*coding[:=]\s*[0-9A-Za-z-_.]\+.*$"
|
||||
endif
|
||||
syn keyword pythonTodo TODO FIXME XXX contained
|
||||
|
||||
" - a decimal point in '4.' at the end of a line is highlighted,
|
||||
" - a second dot in 1.0.0 is not highlighted,
|
||||
" - 08 is not highlighted,
|
||||
" - 08e0 or 08j are highlighted,
|
||||
"
|
||||
" Errors
|
||||
" and so on, as specified in the 'Python Language Reference'.
|
||||
" https://docs.python.org/reference/lexical_analysis.html#numeric-literals
|
||||
if !exists("python_no_number_highlight")
|
||||
" numbers (including complex)
|
||||
syn match pythonNumber "\<0[oO]\%(_\=\o\)\+\>"
|
||||
syn match pythonNumber "\<0[xX]\%(_\=\x\)\+\>"
|
||||
syn match pythonNumber "\<0[bB]\%(_\=[01]\)\+\>"
|
||||
syn match pythonNumber "\<\%([1-9]\%(_\=\d\)*\|0\+\%(_\=0\)*\)\>"
|
||||
syn match pythonNumber "\<\d\%(_\=\d\)*[jJ]\>"
|
||||
syn match pythonNumber "\<\d\%(_\=\d\)*[eE][+-]\=\d\%(_\=\d\)*[jJ]\=\>"
|
||||
syn match pythonNumber
|
||||
\ "\<\d\%(_\=\d\)*\.\%([eE][+-]\=\d\%(_\=\d\)*\)\=[jJ]\=\%(\W\|$\)\@="
|
||||
syn match pythonNumber
|
||||
\ "\%(^\|\W\)\zs\%(\d\%(_\=\d\)*\)\=\.\d\%(_\=\d\)*\%([eE][+-]\=\d\%(_\=\d\)*\)\=[jJ]\=\>"
|
||||
endif
|
||||
|
||||
" Group the built-ins in the order in the 'Python Library Reference' for
|
||||
" easier comparison.
|
||||
" https://docs.python.org/library/constants.html
|
||||
" http://docs.python.org/library/functions.html
|
||||
" Python built-in functions are in alphabetical order.
|
||||
"
|
||||
|
||||
syn match pythonError "\<\d\+\D\+\>" display
|
||||
syn match pythonError "[$?]" display
|
||||
syn match pythonError "[&|]\{2,}" display
|
||||
syn match pythonError "[=]\{3,}" display
|
||||
|
||||
" Mixing spaces and tabs also may be used for pretty formatting multiline
|
||||
" statements
|
||||
if s:Enabled("g:python_highlight_indent_errors")
|
||||
syn match pythonIndentError "^\s*\%( \t\|\t \)\s*\S"me=e-1 display
|
||||
endif
|
||||
|
||||
" Trailing space errors
|
||||
if s:Enabled("g:python_highlight_space_errors")
|
||||
syn match pythonSpaceError "\s\+$" display
|
||||
endif
|
||||
|
||||
" The list can be checked using:
|
||||
"
|
||||
" Strings
|
||||
" python3 -c 'import builtins, pprint; pprint.pprint(dir(builtins), compact=True)'
|
||||
"
|
||||
|
||||
if s:Python2Syntax()
|
||||
" Python 2 strings
|
||||
syn region pythonString start=+[bB]\='+ skip=+\\\\\|\\'\|\\$+ excludenl end=+'+ end=+$+ keepend contains=pythonBytesEscape,pythonBytesEscapeError,pythonUniEscape,pythonUniEscapeError,@Spell
|
||||
syn region pythonString start=+[bB]\="+ skip=+\\\\\|\\"\|\\$+ excludenl end=+"+ end=+$+ keepend contains=pythonBytesEscape,pythonBytesEscapeError,pythonUniEscape,pythonUniEscapeError,@Spell
|
||||
syn region pythonString start=+[bB]\="""+ end=+"""+ keepend contains=pythonBytesEscape,pythonBytesEscapeError,pythonUniEscape,pythonUniEscapeError,pythonDocTest2,pythonSpaceError,@Spell
|
||||
syn region pythonString start=+[bB]\='''+ end=+'''+ keepend contains=pythonBytesEscape,pythonBytesEscapeError,pythonUniEscape,pythonUniEscapeError,pythonDocTest,pythonSpaceError,@Spell
|
||||
else
|
||||
" Python 3 byte strings
|
||||
syn region pythonBytes start=+[bB]'+ skip=+\\\\\|\\'\|\\$+ excludenl end=+'+ end=+$+ keepend contains=pythonBytesError,pythonBytesContent,@Spell
|
||||
syn region pythonBytes start=+[bB]"+ skip=+\\\\\|\\"\|\\$+ excludenl end=+"+ end=+$+ keepend contains=pythonBytesError,pythonBytesContent,@Spell
|
||||
syn region pythonBytes start=+[bB]"""+ end=+"""+ keepend contains=pythonBytesError,pythonBytesContent,pythonDocTest2,pythonSpaceError,@Spell
|
||||
syn region pythonBytes start=+[bB]'''+ end=+'''+ keepend contains=pythonBytesError,pythonBytesContent,pythonDocTest,pythonSpaceError,@Spell
|
||||
|
||||
syn match pythonBytesError ".\+" display contained
|
||||
syn match pythonBytesContent "[\u0000-\u00ff]\+" display contained contains=pythonBytesEscape,pythonBytesEscapeError
|
||||
" The constants added by the `site` module are not listed below because they
|
||||
" should not be used in programs, only in interactive interpreter.
|
||||
" Similarly for some other attributes and functions `__`-enclosed from the
|
||||
" output of the above command.
|
||||
"
|
||||
if !exists("python_no_builtin_highlight")
|
||||
" built-in constants
|
||||
" 'False', 'True', and 'None' are also reserved words in Python 3
|
||||
syn keyword pythonBuiltin False True None
|
||||
syn keyword pythonBuiltin NotImplemented Ellipsis __debug__
|
||||
" constants added by the `site` module
|
||||
syn keyword pythonBuiltin quit exit copyright credits license
|
||||
" built-in functions
|
||||
syn keyword pythonBuiltin abs all any ascii bin bool breakpoint bytearray
|
||||
syn keyword pythonBuiltin bytes callable chr classmethod compile complex
|
||||
syn keyword pythonBuiltin delattr dict dir divmod enumerate eval exec
|
||||
syn keyword pythonBuiltin filter float format frozenset getattr globals
|
||||
syn keyword pythonBuiltin hasattr hash help hex id input int isinstance
|
||||
syn keyword pythonBuiltin issubclass iter len list locals map max
|
||||
syn keyword pythonBuiltin memoryview min next object oct open ord pow
|
||||
syn keyword pythonBuiltin print property range repr reversed round set
|
||||
syn keyword pythonBuiltin setattr slice sorted staticmethod str sum super
|
||||
syn keyword pythonBuiltin tuple type vars zip __import__
|
||||
" avoid highlighting attributes as builtins
|
||||
syn match pythonAttribute /\.\h\w*/hs=s+1
|
||||
\ contains=ALLBUT,pythonBuiltin,pythonFunction,pythonAsync
|
||||
\ transparent
|
||||
endif
|
||||
|
||||
syn match pythonBytesEscape +\\[abfnrtv'"\\]+ display contained
|
||||
syn match pythonBytesEscape "\\\o\o\=\o\=" display contained
|
||||
syn match pythonBytesEscapeError "\\\o\{,2}[89]" display contained
|
||||
syn match pythonBytesEscape "\\x\x\{2}" display contained
|
||||
syn match pythonBytesEscapeError "\\x\x\=\X" display contained
|
||||
syn match pythonBytesEscape "\\$"
|
||||
|
||||
syn match pythonUniEscape "\\u\x\{4}" display contained
|
||||
syn match pythonUniEscapeError "\\u\x\{,3}\X" display contained
|
||||
syn match pythonUniEscape "\\U\x\{8}" display contained
|
||||
syn match pythonUniEscapeError "\\U\x\{,7}\X" display contained
|
||||
syn match pythonUniEscape "\\N{[A-Z ]\+}" display contained
|
||||
syn match pythonUniEscapeError "\\N{[^A-Z ]\+}" display contained
|
||||
|
||||
if s:Python2Syntax()
|
||||
" Python 2 Unicode strings
|
||||
syn region pythonUniString start=+[uU]'+ skip=+\\\\\|\\'\|\\$+ excludenl end=+'+ end=+$+ keepend contains=pythonBytesEscape,pythonBytesEscapeError,pythonUniEscape,pythonUniEscapeError,@Spell
|
||||
syn region pythonUniString start=+[uU]"+ skip=+\\\\\|\\"\|\\$+ excludenl end=+"+ end=+$+ keepend contains=pythonBytesEscape,pythonBytesEscapeError,pythonUniEscape,pythonUniEscapeError,@Spell
|
||||
syn region pythonUniString start=+[uU]"""+ end=+"""+ keepend contains=pythonBytesEscape,pythonBytesEscapeError,pythonUniEscape,pythonUniEscapeError,pythonDocTest2,pythonSpaceError,@Spell
|
||||
syn region pythonUniString start=+[uU]'''+ end=+'''+ keepend contains=pythonBytesEscape,pythonBytesEscapeError,pythonUniEscape,pythonUniEscapeError,pythonDocTest,pythonSpaceError,@Spell
|
||||
else
|
||||
" Python 3 strings
|
||||
syn region pythonString start=+'+ skip=+\\\\\|\\'\|\\$+ excludenl end=+'+ end=+$+ keepend contains=pythonBytesEscape,pythonBytesEscapeError,pythonUniEscape,pythonUniEscapeError,@Spell
|
||||
syn region pythonString start=+"+ skip=+\\\\\|\\"\|\\$+ excludenl end=+"+ end=+$+ keepend contains=pythonBytesEscape,pythonBytesEscapeError,pythonUniEscape,pythonUniEscapeError,@Spell
|
||||
syn region pythonString start=+"""+ end=+"""+ keepend contains=pythonBytesEscape,pythonBytesEscapeError,pythonUniEscape,pythonUniEscapeError,pythonDocTest2,pythonSpaceError,@Spell
|
||||
syn region pythonString start=+'''+ end=+'''+ keepend contains=pythonBytesEscape,pythonBytesEscapeError,pythonUniEscape,pythonUniEscapeError,pythonDocTest,pythonSpaceError,@Spell
|
||||
" From the 'Python Library Reference' class hierarchy at the bottom.
|
||||
" http://docs.python.org/library/exceptions.html
|
||||
if !exists("python_no_exception_highlight")
|
||||
" builtin base exceptions (used mostly as base classes for other exceptions)
|
||||
syn keyword pythonExceptions BaseException Exception
|
||||
syn keyword pythonExceptions ArithmeticError BufferError LookupError
|
||||
" builtin exceptions (actually raised)
|
||||
syn keyword pythonExceptions AssertionError AttributeError EOFError
|
||||
syn keyword pythonExceptions FloatingPointError GeneratorExit ImportError
|
||||
syn keyword pythonExceptions IndentationError IndexError KeyError
|
||||
syn keyword pythonExceptions KeyboardInterrupt MemoryError
|
||||
syn keyword pythonExceptions ModuleNotFoundError NameError
|
||||
syn keyword pythonExceptions NotImplementedError OSError OverflowError
|
||||
syn keyword pythonExceptions RecursionError ReferenceError RuntimeError
|
||||
syn keyword pythonExceptions StopAsyncIteration StopIteration SyntaxError
|
||||
syn keyword pythonExceptions SystemError SystemExit TabError TypeError
|
||||
syn keyword pythonExceptions UnboundLocalError UnicodeDecodeError
|
||||
syn keyword pythonExceptions UnicodeEncodeError UnicodeError
|
||||
syn keyword pythonExceptions UnicodeTranslateError ValueError
|
||||
syn keyword pythonExceptions ZeroDivisionError
|
||||
" builtin exception aliases for OSError
|
||||
syn keyword pythonExceptions EnvironmentError IOError WindowsError
|
||||
" builtin OS exceptions in Python 3
|
||||
syn keyword pythonExceptions BlockingIOError BrokenPipeError
|
||||
syn keyword pythonExceptions ChildProcessError ConnectionAbortedError
|
||||
syn keyword pythonExceptions ConnectionError ConnectionRefusedError
|
||||
syn keyword pythonExceptions ConnectionResetError FileExistsError
|
||||
syn keyword pythonExceptions FileNotFoundError InterruptedError
|
||||
syn keyword pythonExceptions IsADirectoryError NotADirectoryError
|
||||
syn keyword pythonExceptions PermissionError ProcessLookupError TimeoutError
|
||||
" builtin warnings
|
||||
syn keyword pythonExceptions BytesWarning DeprecationWarning FutureWarning
|
||||
syn keyword pythonExceptions ImportWarning PendingDeprecationWarning
|
||||
syn keyword pythonExceptions ResourceWarning RuntimeWarning
|
||||
syn keyword pythonExceptions SyntaxWarning UnicodeWarning
|
||||
syn keyword pythonExceptions UserWarning Warning
|
||||
endif
|
||||
|
||||
if s:Python2Syntax()
|
||||
" Python 2 Unicode raw strings
|
||||
syn region pythonUniRawString start=+[uU][rR]'+ skip=+\\\\\|\\'\|\\$+ excludenl end=+'+ end=+$+ keepend contains=pythonRawEscape,pythonUniRawEscape,pythonUniRawEscapeError,@Spell
|
||||
syn region pythonUniRawString start=+[uU][rR]"+ skip=+\\\\\|\\"\|\\$+ excludenl end=+"+ end=+$+ keepend contains=pythonRawEscape,pythonUniRawEscape,pythonUniRawEscapeError,@Spell
|
||||
syn region pythonUniRawString start=+[uU][rR]"""+ end=+"""+ keepend contains=pythonUniRawEscape,pythonUniRawEscapeError,pythonDocTest2,pythonSpaceError,@Spell
|
||||
syn region pythonUniRawString start=+[uU][rR]'''+ end=+'''+ keepend contains=pythonUniRawEscape,pythonUniRawEscapeError,pythonDocTest,pythonSpaceError,@Spell
|
||||
|
||||
syn match pythonUniRawEscape "\([^\\]\(\\\\\)*\)\@<=\\u\x\{4}" display contained
|
||||
syn match pythonUniRawEscapeError "\([^\\]\(\\\\\)*\)\@<=\\u\x\{,3}\X" display contained
|
||||
if exists("python_space_error_highlight")
|
||||
" trailing whitespace
|
||||
syn match pythonSpaceError display excludenl "\s\+$"
|
||||
" mixed tabs and spaces
|
||||
syn match pythonSpaceError display " \+\t"
|
||||
syn match pythonSpaceError display "\t\+ "
|
||||
endif
|
||||
|
||||
" Python 2/3 raw strings
|
||||
if s:Python2Syntax()
|
||||
syn region pythonRawString start=+[bB]\=[rR]'+ skip=+\\\\\|\\'\|\\$+ excludenl end=+'+ end=+$+ keepend contains=pythonRawEscape,@Spell
|
||||
syn region pythonRawString start=+[bB]\=[rR]"+ skip=+\\\\\|\\"\|\\$+ excludenl end=+"+ end=+$+ keepend contains=pythonRawEscape,@Spell
|
||||
syn region pythonRawString start=+[bB]\=[rR]"""+ end=+"""+ keepend contains=pythonDocTest2,pythonSpaceError,@Spell
|
||||
syn region pythonRawString start=+[bB]\=[rR]'''+ end=+'''+ keepend contains=pythonDocTest,pythonSpaceError,@Spell
|
||||
else
|
||||
syn region pythonRawString start=+[rR]'+ skip=+\\\\\|\\'\|\\$+ excludenl end=+'+ end=+$+ keepend contains=pythonRawEscape,@Spell
|
||||
syn region pythonRawString start=+[rR]"+ skip=+\\\\\|\\"\|\\$+ excludenl end=+"+ end=+$+ keepend contains=pythonRawEscape,@Spell
|
||||
syn region pythonRawString start=+[rR]"""+ end=+"""+ keepend contains=pythonDocTest2,pythonSpaceError,@Spell
|
||||
syn region pythonRawString start=+[rR]'''+ end=+'''+ keepend contains=pythonDocTest,pythonSpaceError,@Spell
|
||||
|
||||
syn region pythonRawBytes start=+[bB][rR]'+ skip=+\\\\\|\\'\|\\$+ excludenl end=+'+ end=+$+ keepend contains=pythonRawEscape,@Spell
|
||||
syn region pythonRawBytes start=+[bB][rR]"+ skip=+\\\\\|\\"\|\\$+ excludenl end=+"+ end=+$+ keepend contains=pythonRawEscape,@Spell
|
||||
syn region pythonRawBytes start=+[bB][rR]"""+ end=+"""+ keepend contains=pythonDocTest2,pythonSpaceError,@Spell
|
||||
syn region pythonRawBytes start=+[bB][rR]'''+ end=+'''+ keepend contains=pythonDocTest,pythonSpaceError,@Spell
|
||||
endif
|
||||
|
||||
syn match pythonRawEscape +\\['"]+ display transparent contained
|
||||
|
||||
if s:Enabled("g:python_highlight_string_formatting")
|
||||
" % operator string formatting
|
||||
if s:Python2Syntax()
|
||||
syn match pythonStrFormatting "%\%(([^)]\+)\)\=[-#0 +]*\d*\%(\.\d\+\)\=[hlL]\=[diouxXeEfFgGcrs%]" contained containedin=pythonString,pythonUniString,pythonUniRawString,pythonRawString
|
||||
syn match pythonStrFormatting "%[-#0 +]*\%(\*\|\d\+\)\=\%(\.\%(\*\|\d\+\)\)\=[hlL]\=[diouxXeEfFgGcrs%]" contained containedin=pythonString,pythonUniString,pythonUniRawString,pythonRawString
|
||||
" Do not spell doctests inside strings.
|
||||
" Notice that the end of a string, either ''', or """, will end the contained
|
||||
" doctest too. Thus, we do *not* need to have it as an end pattern.
|
||||
if !exists("python_no_doctest_highlight")
|
||||
if !exists("python_no_doctest_code_highlight")
|
||||
syn region pythonDoctest
|
||||
\ start="^\s*>>>\s" end="^\s*$"
|
||||
\ contained contains=ALLBUT,pythonDoctest,pythonFunction,@Spell
|
||||
syn region pythonDoctestValue
|
||||
\ start=+^\s*\%(>>>\s\|\.\.\.\s\|"""\|'''\)\@!\S\++ end="$"
|
||||
\ contained
|
||||
else
|
||||
syn match pythonStrFormatting "%\%(([^)]\+)\)\=[-#0 +]*\d*\%(\.\d\+\)\=[hlL]\=[diouxXeEfFgGcrs%]" contained containedin=pythonString,pythonRawString
|
||||
syn match pythonStrFormatting "%[-#0 +]*\%(\*\|\d\+\)\=\%(\.\%(\*\|\d\+\)\)\=[hlL]\=[diouxXeEfFgGcrs%]" contained containedin=pythonString,pythonRawString
|
||||
syn region pythonDoctest
|
||||
\ start="^\s*>>>" end="^\s*$"
|
||||
\ contained contains=@NoSpell
|
||||
endif
|
||||
endif
|
||||
|
||||
if s:Enabled("g:python_highlight_string_format")
|
||||
" str.format syntax
|
||||
if s:Python2Syntax()
|
||||
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
|
||||
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
|
||||
endif
|
||||
" Sync at the beginning of class, function, or method definition.
|
||||
syn sync match pythonSync grouphere NONE "^\%(def\|class\)\s\+\h\w*\s*[(:]"
|
||||
|
||||
" The default highlight links. Can be overridden later.
|
||||
hi def link pythonStatement Statement
|
||||
hi def link pythonConditional Conditional
|
||||
hi def link pythonRepeat Repeat
|
||||
hi def link pythonOperator Operator
|
||||
hi def link pythonException Exception
|
||||
hi def link pythonInclude Include
|
||||
hi def link pythonAsync Statement
|
||||
hi def link pythonDecorator Define
|
||||
hi def link pythonDecoratorName Define
|
||||
hi def link pythonFunction Function
|
||||
hi def link pythonComment Comment
|
||||
hi def link pythonTodo Todo
|
||||
hi def link pythonString String
|
||||
hi def link pythonRawString String
|
||||
hi def link pythonQuotes String
|
||||
hi def link pythonTripleQuotes pythonQuotes
|
||||
hi def link pythonEscape Special
|
||||
if !exists("python_no_number_highlight")
|
||||
hi def link pythonNumber Number
|
||||
endif
|
||||
|
||||
if s:Enabled("g:python_highlight_string_templates")
|
||||
" string.Template format
|
||||
if s:Python2Syntax()
|
||||
syn match pythonStrTemplate "\$\$" contained containedin=pythonString,pythonUniString,pythonUniRawString,pythonRawString
|
||||
syn match pythonStrTemplate "\${[a-zA-Z_][a-zA-Z0-9_]*}" contained containedin=pythonString,pythonUniString,pythonUniRawString,pythonRawString
|
||||
syn match pythonStrTemplate "\$[a-zA-Z_][a-zA-Z0-9_]*" contained containedin=pythonString,pythonUniString,pythonUniRawString,pythonRawString
|
||||
else
|
||||
syn match pythonStrTemplate "\$\$" contained containedin=pythonString,pythonRawString
|
||||
syn match pythonStrTemplate "\${[a-zA-Z_][a-zA-Z0-9_]*}" contained containedin=pythonString,pythonRawString
|
||||
syn match pythonStrTemplate "\$[a-zA-Z_][a-zA-Z0-9_]*" contained containedin=pythonString,pythonRawString
|
||||
endif
|
||||
if !exists("python_no_builtin_highlight")
|
||||
hi def link pythonBuiltin Function
|
||||
endif
|
||||
|
||||
if s:Enabled("g:python_highlight_doctests")
|
||||
" DocTests
|
||||
syn region pythonDocTest start="^\s*>>>" end=+'''+he=s-1 end="^\s*$" contained
|
||||
syn region pythonDocTest2 start="^\s*>>>" end=+"""+he=s-1 end="^\s*$" contained
|
||||
if !exists("python_no_exception_highlight")
|
||||
hi def link pythonExceptions Structure
|
||||
endif
|
||||
|
||||
"
|
||||
" Numbers (ints, longs, floats, complex)
|
||||
"
|
||||
|
||||
if s:Python2Syntax()
|
||||
syn match pythonHexError "\<0[xX]\x*[g-zG-Z]\+\x*[lL]\=\>" display
|
||||
syn match pythonOctError "\<0[oO]\=\o*\D\+\d*[lL]\=\>" display
|
||||
syn match pythonBinError "\<0[bB][01]*\D\+\d*[lL]\=\>" display
|
||||
|
||||
syn match pythonHexNumber "\<0[xX]\x\+[lL]\=\>" display
|
||||
syn match pythonOctNumber "\<0[oO]\o\+[lL]\=\>" display
|
||||
syn match pythonBinNumber "\<0[bB][01]\+[lL]\=\>" display
|
||||
|
||||
syn match pythonNumberError "\<\d\+\D[lL]\=\>" display
|
||||
syn match pythonNumber "\<\d[lL]\=\>" display
|
||||
syn match pythonNumber "\<[0-9]\d\+[lL]\=\>" display
|
||||
syn match pythonNumber "\<\d\+[lLjJ]\>" display
|
||||
|
||||
syn match pythonOctError "\<0[oO]\=\o*[8-9]\d*[lL]\=\>" display
|
||||
syn match pythonBinError "\<0[bB][01]*[2-9]\d*[lL]\=\>" display
|
||||
else
|
||||
syn match pythonHexError "\<0[xX]\x*[g-zG-Z]\x*\>" display
|
||||
syn match pythonOctError "\<0[oO]\=\o*\D\+\d*\>" display
|
||||
syn match pythonBinError "\<0[bB][01]*\D\+\d*\>" display
|
||||
|
||||
syn match pythonHexNumber "\<0[xX]\x\+\>" display
|
||||
syn match pythonOctNumber "\<0[oO]\o\+\>" display
|
||||
syn match pythonBinNumber "\<0[bB][01]\+\>" display
|
||||
|
||||
syn match pythonNumberError "\<\d\+\D\>" display
|
||||
syn match pythonNumberError "\<0\d\+\>" display
|
||||
syn match pythonNumber "\<\d\>" display
|
||||
syn match pythonNumber "\<[1-9]\d\+\>" display
|
||||
syn match pythonNumber "\<\d\+[jJ]\>" display
|
||||
|
||||
syn match pythonOctError "\<0[oO]\=\o*[8-9]\d*\>" display
|
||||
syn match pythonBinError "\<0[bB][01]*[2-9]\d*\>" display
|
||||
if exists("python_space_error_highlight")
|
||||
hi def link pythonSpaceError Error
|
||||
endif
|
||||
|
||||
syn match pythonFloat "\.\d\+\%([eE][+-]\=\d\+\)\=[jJ]\=\>" display
|
||||
syn match pythonFloat "\<\d\+[eE][+-]\=\d\+[jJ]\=\>" display
|
||||
syn match pythonFloat "\<\d\+\.\d*\%([eE][+-]\=\d\+\)\=[jJ]\=" display
|
||||
|
||||
"
|
||||
" Builtin objects and types
|
||||
"
|
||||
|
||||
if s:Enabled("g:python_highlight_builtin_objs")
|
||||
if s:Python2Syntax()
|
||||
syn keyword pythonBuiltinObj None
|
||||
syn keyword pythonBoolean True False
|
||||
endif
|
||||
syn keyword pythonBuiltinObj Ellipsis NotImplemented
|
||||
syn keyword pythonBuiltinObj __debug__ __doc__ __file__ __name__ __package__
|
||||
endif
|
||||
|
||||
"
|
||||
" Builtin functions
|
||||
"
|
||||
|
||||
if s:Enabled("g:python_highlight_builtin_funcs")
|
||||
if s:Python2Syntax()
|
||||
syn keyword pythonBuiltinFunc apply basestring buffer callable coerce
|
||||
syn keyword pythonBuiltinFunc execfile file help intern long raw_input
|
||||
syn keyword pythonBuiltinFunc reduce reload unichr unicode xrange
|
||||
if s:Enabled("g:python_print_as_function")
|
||||
syn keyword pythonBuiltinFunc print
|
||||
endif
|
||||
else
|
||||
syn keyword pythonBuiltinFunc ascii exec memoryview print
|
||||
endif
|
||||
syn keyword pythonBuiltinFunc __import__ abs all any
|
||||
syn keyword pythonBuiltinFunc bin bool bytearray bytes
|
||||
syn keyword pythonBuiltinFunc chr classmethod cmp compile complex
|
||||
syn keyword pythonBuiltinFunc delattr dict dir divmod enumerate eval
|
||||
syn keyword pythonBuiltinFunc filter float format frozenset getattr
|
||||
syn keyword pythonBuiltinFunc globals hasattr hash hex id
|
||||
syn keyword pythonBuiltinFunc input int isinstance
|
||||
syn keyword pythonBuiltinFunc issubclass iter len list locals map max
|
||||
syn keyword pythonBuiltinFunc min next object oct open ord
|
||||
syn keyword pythonBuiltinFunc pow property range
|
||||
syn keyword pythonBuiltinFunc repr reversed round set setattr
|
||||
syn keyword pythonBuiltinFunc slice sorted staticmethod str sum super tuple
|
||||
syn keyword pythonBuiltinFunc type vars zip
|
||||
endif
|
||||
|
||||
"
|
||||
" Builtin exceptions and warnings
|
||||
"
|
||||
|
||||
if s:Enabled("g:python_highlight_exceptions")
|
||||
if s:Python2Syntax()
|
||||
syn keyword pythonExClass StandardError
|
||||
else
|
||||
syn keyword pythonExClass BlockingIOError ChildProcessError
|
||||
syn keyword pythonExClass ConnectionError BrokenPipeError
|
||||
syn keyword pythonExClass ConnectionAbortedError ConnectionRefusedError
|
||||
syn keyword pythonExClass ConnectionResetError FileExistsError
|
||||
syn keyword pythonExClass FileNotFoundError InterruptedError
|
||||
syn keyword pythonExClass IsADirectoryError NotADirectoryError
|
||||
syn keyword pythonExClass PermissionError ProcessLookupError TimeoutError
|
||||
|
||||
syn keyword pythonExClass ResourceWarning
|
||||
endif
|
||||
syn keyword pythonExClass BaseException
|
||||
syn keyword pythonExClass Exception ArithmeticError
|
||||
syn keyword pythonExClass LookupError EnvironmentError
|
||||
|
||||
syn keyword pythonExClass AssertionError AttributeError BufferError EOFError
|
||||
syn keyword pythonExClass FloatingPointError GeneratorExit IOError
|
||||
syn keyword pythonExClass ImportError IndexError KeyError
|
||||
syn keyword pythonExClass KeyboardInterrupt MemoryError NameError
|
||||
syn keyword pythonExClass NotImplementedError OSError OverflowError
|
||||
syn keyword pythonExClass ReferenceError RuntimeError StopIteration
|
||||
syn keyword pythonExClass SyntaxError IndentationError TabError
|
||||
syn keyword pythonExClass SystemError SystemExit TypeError
|
||||
syn keyword pythonExClass UnboundLocalError UnicodeError
|
||||
syn keyword pythonExClass UnicodeEncodeError UnicodeDecodeError
|
||||
syn keyword pythonExClass UnicodeTranslateError ValueError VMSError
|
||||
syn keyword pythonExClass WindowsError ZeroDivisionError
|
||||
|
||||
syn keyword pythonExClass Warning UserWarning BytesWarning DeprecationWarning
|
||||
syn keyword pythonExClass PendingDepricationWarning SyntaxWarning
|
||||
syn keyword pythonExClass RuntimeWarning FutureWarning
|
||||
syn keyword pythonExClass ImportWarning UnicodeWarning
|
||||
endif
|
||||
|
||||
if s:Enabled("g:python_slow_sync")
|
||||
syn sync minlines=2000
|
||||
else
|
||||
" This is fast but code inside triple quoted strings screws it up. It
|
||||
" is impossible to fix because the only way to know if you are inside a
|
||||
" triple quoted string is to start from the beginning of the file.
|
||||
syn sync match pythonSync grouphere NONE "):$"
|
||||
syn sync maxlines=200
|
||||
endif
|
||||
|
||||
if version >= 508 || !exists("did_python_syn_inits")
|
||||
if version <= 508
|
||||
let did_python_syn_inits = 1
|
||||
command -nargs=+ HiLink hi link <args>
|
||||
else
|
||||
command -nargs=+ HiLink hi def link <args>
|
||||
endif
|
||||
|
||||
HiLink pythonStatement Statement
|
||||
HiLink pythonImport Include
|
||||
HiLink pythonFunction Function
|
||||
HiLink pythonConditional Conditional
|
||||
HiLink pythonRepeat Repeat
|
||||
HiLink pythonException Exception
|
||||
HiLink pythonOperator Operator
|
||||
|
||||
HiLink pythonDecorator Define
|
||||
HiLink pythonDottedName Function
|
||||
HiLink pythonDot Normal
|
||||
|
||||
HiLink pythonComment Comment
|
||||
if !s:Enabled("g:python_highlight_file_headers_as_comments")
|
||||
HiLink pythonCoding Special
|
||||
HiLink pythonRun Special
|
||||
endif
|
||||
HiLink pythonTodo Todo
|
||||
|
||||
HiLink pythonError Error
|
||||
HiLink pythonIndentError Error
|
||||
HiLink pythonSpaceError Error
|
||||
|
||||
HiLink pythonString String
|
||||
HiLink pythonRawString String
|
||||
|
||||
HiLink pythonUniEscape Special
|
||||
HiLink pythonUniEscapeError Error
|
||||
|
||||
if s:Python2Syntax()
|
||||
HiLink pythonUniString String
|
||||
HiLink pythonUniRawString String
|
||||
HiLink pythonUniRawEscape Special
|
||||
HiLink pythonUniRawEscapeError Error
|
||||
else
|
||||
HiLink pythonBytes String
|
||||
HiLink pythonRawBytes String
|
||||
HiLink pythonBytesContent String
|
||||
HiLink pythonBytesError Error
|
||||
HiLink pythonBytesEscape Special
|
||||
HiLink pythonBytesEscapeError Error
|
||||
endif
|
||||
|
||||
HiLink pythonStrFormatting Special
|
||||
HiLink pythonStrFormat Special
|
||||
HiLink pythonStrTemplate Special
|
||||
|
||||
HiLink pythonDocTest Special
|
||||
HiLink pythonDocTest2 Special
|
||||
|
||||
HiLink pythonNumber Number
|
||||
HiLink pythonHexNumber Number
|
||||
HiLink pythonOctNumber Number
|
||||
HiLink pythonBinNumber Number
|
||||
HiLink pythonFloat Float
|
||||
HiLink pythonNumberError Error
|
||||
HiLink pythonOctError Error
|
||||
HiLink pythonHexError Error
|
||||
HiLink pythonBinError Error
|
||||
|
||||
HiLink pythonBoolean Boolean
|
||||
|
||||
HiLink pythonBuiltinObj Structure
|
||||
HiLink pythonBuiltinFunc Function
|
||||
|
||||
HiLink pythonExClass Structure
|
||||
|
||||
delcommand HiLink
|
||||
if !exists("python_no_doctest_highlight")
|
||||
hi def link pythonDoctest Special
|
||||
hi def link pythonDoctestValue Define
|
||||
endif
|
||||
|
||||
let b:current_syntax = "python"
|
||||
|
||||
let &cpo = s:cpo_save
|
||||
unlet s:cpo_save
|
||||
|
||||
" vim:set sw=2 sts=2 ts=8 noet:
|
||||
|
||||
345
syntax/python2.vim
Normal file
345
syntax/python2.vim
Normal file
@@ -0,0 +1,345 @@
|
||||
" Vim syntax file
|
||||
" Language: Python 2
|
||||
" Maintainer: Zvezdan Petkovic <zpetkovic@acm.org>
|
||||
" Last Change: 2016 Oct 29
|
||||
" Credits: Neil Schemenauer <nas@python.ca>
|
||||
" Dmitry Vasiliev
|
||||
"
|
||||
" This version is a major rewrite by Zvezdan Petkovic.
|
||||
"
|
||||
" - introduced highlighting of doctests
|
||||
" - updated keywords, built-ins, and exceptions
|
||||
" - corrected regular expressions for
|
||||
"
|
||||
" * functions
|
||||
" * decorators
|
||||
" * strings
|
||||
" * escapes
|
||||
" * numbers
|
||||
" * space error
|
||||
"
|
||||
" - corrected synchronization
|
||||
" - more highlighting is ON by default, except
|
||||
" - space error highlighting is OFF by default
|
||||
"
|
||||
" Optional highlighting can be controlled using these variables.
|
||||
"
|
||||
" let python_no_builtin_highlight = 1
|
||||
" let python_no_doctest_code_highlight = 1
|
||||
" let python_no_doctest_highlight = 1
|
||||
" let python_no_exception_highlight = 1
|
||||
" let python_no_number_highlight = 1
|
||||
" let python_space_error_highlight = 1
|
||||
"
|
||||
" All the options above can be switched on together.
|
||||
"
|
||||
" let python_highlight_all = 1
|
||||
"
|
||||
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
|
||||
" NOTE: This file is a copy of the last commit of runtime/syntax/python.vim
|
||||
" that still supported Python 2. There is support for Python 3, up to 3.5,
|
||||
" and it was kept in the file as is, because it supports the straddling code
|
||||
" (Python 2 and 3 compatible) better.
|
||||
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
|
||||
|
||||
" quit when a syntax file was already loaded.
|
||||
if exists("b:current_syntax")
|
||||
finish
|
||||
endif
|
||||
|
||||
" We need nocompatible mode in order to continue lines with backslashes.
|
||||
" Original setting will be restored.
|
||||
let s:cpo_save = &cpo
|
||||
set cpo&vim
|
||||
|
||||
if exists("python_no_doctest_highlight")
|
||||
let python_no_doctest_code_highlight = 1
|
||||
endif
|
||||
|
||||
if exists("python_highlight_all")
|
||||
if exists("python_no_builtin_highlight")
|
||||
unlet python_no_builtin_highlight
|
||||
endif
|
||||
if exists("python_no_doctest_code_highlight")
|
||||
unlet python_no_doctest_code_highlight
|
||||
endif
|
||||
if exists("python_no_doctest_highlight")
|
||||
unlet python_no_doctest_highlight
|
||||
endif
|
||||
if exists("python_no_exception_highlight")
|
||||
unlet python_no_exception_highlight
|
||||
endif
|
||||
if exists("python_no_number_highlight")
|
||||
unlet python_no_number_highlight
|
||||
endif
|
||||
let python_space_error_highlight = 1
|
||||
endif
|
||||
|
||||
" Keep Python keywords in alphabetical order inside groups for easy
|
||||
" comparison with the table in the 'Python Language Reference'
|
||||
" https://docs.python.org/2/reference/lexical_analysis.html#keywords,
|
||||
" https://docs.python.org/3/reference/lexical_analysis.html#keywords.
|
||||
" Groups are in the order presented in NAMING CONVENTIONS in syntax.txt.
|
||||
" Exceptions come last at the end of each group (class and def below).
|
||||
"
|
||||
" Keywords 'with' and 'as' are new in Python 2.6
|
||||
" (use 'from __future__ import with_statement' in Python 2.5).
|
||||
"
|
||||
" Some compromises had to be made to support both Python 3 and 2.
|
||||
" We include Python 3 features, but when a definition is duplicated,
|
||||
" the last definition takes precedence.
|
||||
"
|
||||
" - 'False', 'None', and 'True' are keywords in Python 3 but they are
|
||||
" built-ins in 2 and will be highlighted as built-ins below.
|
||||
" - 'exec' is a built-in in Python 3 and will be highlighted as
|
||||
" built-in below.
|
||||
" - 'nonlocal' is a keyword in Python 3 and will be highlighted.
|
||||
" - 'print' is a built-in in Python 3 and will be highlighted as
|
||||
" built-in below (use 'from __future__ import print_function' in 2)
|
||||
" - async and await were added in Python 3.5 and are soft keywords.
|
||||
"
|
||||
syn keyword pythonStatement False None True
|
||||
syn keyword pythonStatement as assert break continue del exec global
|
||||
syn keyword pythonStatement lambda nonlocal pass print return with yield
|
||||
syn keyword pythonStatement class def nextgroup=pythonFunction skipwhite
|
||||
syn keyword pythonConditional elif else if
|
||||
syn keyword pythonRepeat for while
|
||||
syn keyword pythonOperator and in is not or
|
||||
syn keyword pythonException except finally raise try
|
||||
syn keyword pythonInclude from import
|
||||
syn keyword pythonAsync async await
|
||||
|
||||
" Decorators (new in Python 2.4)
|
||||
" A dot must be allowed because of @MyClass.myfunc decorators.
|
||||
syn match pythonDecorator "@" display contained
|
||||
syn match pythonDecoratorName "@\s*\h\%(\w\|\.\)*" display contains=pythonDecorator
|
||||
|
||||
" Python 3.5 introduced the use of the same symbol for matrix multiplication:
|
||||
" https://www.python.org/dev/peps/pep-0465/. We now have to exclude the
|
||||
" symbol from highlighting when used in that context.
|
||||
" Single line multiplication.
|
||||
syn match pythonMatrixMultiply
|
||||
\ "\%(\w\|[])]\)\s*@"
|
||||
\ contains=ALLBUT,pythonDecoratorName,pythonDecorator,pythonFunction,pythonDoctestValue
|
||||
\ transparent
|
||||
" Multiplication continued on the next line after backslash.
|
||||
syn match pythonMatrixMultiply
|
||||
\ "[^\\]\\\s*\n\%(\s*\.\.\.\s\)\=\s\+@"
|
||||
\ contains=ALLBUT,pythonDecoratorName,pythonDecorator,pythonFunction,pythonDoctestValue
|
||||
\ transparent
|
||||
" Multiplication in a parenthesized expression over multiple lines with @ at
|
||||
" the start of each continued line; very similar to decorators and complex.
|
||||
syn match pythonMatrixMultiply
|
||||
\ "^\s*\%(\%(>>>\|\.\.\.\)\s\+\)\=\zs\%(\h\|\%(\h\|[[(]\).\{-}\%(\w\|[])]\)\)\s*\n\%(\s*\.\.\.\s\)\=\s\+@\%(.\{-}\n\%(\s*\.\.\.\s\)\=\s\+@\)*"
|
||||
\ contains=ALLBUT,pythonDecoratorName,pythonDecorator,pythonFunction,pythonDoctestValue
|
||||
\ transparent
|
||||
|
||||
syn match pythonFunction "\h\w*" display contained
|
||||
|
||||
syn match pythonComment "#.*$" contains=pythonTodo,@Spell
|
||||
syn keyword pythonTodo FIXME NOTE NOTES TODO XXX contained
|
||||
|
||||
" Triple-quoted strings can contain doctests.
|
||||
syn region pythonString matchgroup=pythonQuotes
|
||||
\ start=+[uU]\=\z(['"]\)+ end="\z1" skip="\\\\\|\\\z1"
|
||||
\ contains=pythonEscape,@Spell
|
||||
syn region pythonString matchgroup=pythonTripleQuotes
|
||||
\ start=+[uU]\=\z('''\|"""\)+ end="\z1" keepend
|
||||
\ contains=pythonEscape,pythonSpaceError,pythonDoctest,@Spell
|
||||
syn region pythonRawString matchgroup=pythonQuotes
|
||||
\ start=+[uU]\=[rR]\z(['"]\)+ end="\z1" skip="\\\\\|\\\z1"
|
||||
\ contains=@Spell
|
||||
syn region pythonRawString matchgroup=pythonTripleQuotes
|
||||
\ start=+[uU]\=[rR]\z('''\|"""\)+ end="\z1" keepend
|
||||
\ contains=pythonSpaceError,pythonDoctest,@Spell
|
||||
|
||||
syn match pythonEscape +\\[abfnrtv'"\\]+ contained
|
||||
syn match pythonEscape "\\\o\{1,3}" contained
|
||||
syn match pythonEscape "\\x\x\{2}" contained
|
||||
syn match pythonEscape "\%(\\u\x\{4}\|\\U\x\{8}\)" contained
|
||||
" Python allows case-insensitive Unicode IDs: http://www.unicode.org/charts/
|
||||
syn match pythonEscape "\\N{\a\+\%(\s\a\+\)*}" contained
|
||||
syn match pythonEscape "\\$"
|
||||
|
||||
" It is very important to understand all details before changing the
|
||||
" regular expressions below or their order.
|
||||
" The word boundaries are *not* the floating-point number boundaries
|
||||
" because of a possible leading or trailing decimal point.
|
||||
" The expressions below ensure that all valid number literals are
|
||||
" highlighted, and invalid number literals are not. For example,
|
||||
"
|
||||
" - a decimal point in '4.' at the end of a line is highlighted,
|
||||
" - a second dot in 1.0.0 is not highlighted,
|
||||
" - 08 is not highlighted,
|
||||
" - 08e0 or 08j are highlighted,
|
||||
"
|
||||
" and so on, as specified in the 'Python Language Reference'.
|
||||
" https://docs.python.org/2/reference/lexical_analysis.html#numeric-literals
|
||||
" https://docs.python.org/3/reference/lexical_analysis.html#numeric-literals
|
||||
if !exists("python_no_number_highlight")
|
||||
" numbers (including longs and complex)
|
||||
syn match pythonNumber "\<0[oO]\=\o\+[Ll]\=\>"
|
||||
syn match pythonNumber "\<0[xX]\x\+[Ll]\=\>"
|
||||
syn match pythonNumber "\<0[bB][01]\+[Ll]\=\>"
|
||||
syn match pythonNumber "\<\%([1-9]\d*\|0\)[Ll]\=\>"
|
||||
syn match pythonNumber "\<\d\+[jJ]\>"
|
||||
syn match pythonNumber "\<\d\+[eE][+-]\=\d\+[jJ]\=\>"
|
||||
syn match pythonNumber
|
||||
\ "\<\d\+\.\%([eE][+-]\=\d\+\)\=[jJ]\=\%(\W\|$\)\@="
|
||||
syn match pythonNumber
|
||||
\ "\%(^\|\W\)\zs\d*\.\d\+\%([eE][+-]\=\d\+\)\=[jJ]\=\>"
|
||||
endif
|
||||
|
||||
" Group the built-ins in the order in the 'Python Library Reference' for
|
||||
" easier comparison.
|
||||
" https://docs.python.org/2/library/constants.html
|
||||
" https://docs.python.org/3/library/constants.html
|
||||
" http://docs.python.org/2/library/functions.html
|
||||
" http://docs.python.org/3/library/functions.html
|
||||
" http://docs.python.org/2/library/functions.html#non-essential-built-in-functions
|
||||
" http://docs.python.org/3/library/functions.html#non-essential-built-in-functions
|
||||
" Python built-in functions are in alphabetical order.
|
||||
if !exists("python_no_builtin_highlight")
|
||||
" built-in constants
|
||||
" 'False', 'True', and 'None' are also reserved words in Python 3
|
||||
syn keyword pythonBuiltin False True None
|
||||
syn keyword pythonBuiltin NotImplemented Ellipsis __debug__
|
||||
" built-in functions
|
||||
syn keyword pythonBuiltin abs all any bin bool bytearray callable chr
|
||||
syn keyword pythonBuiltin classmethod compile complex delattr dict dir
|
||||
syn keyword pythonBuiltin divmod enumerate eval filter float format
|
||||
syn keyword pythonBuiltin frozenset getattr globals hasattr hash
|
||||
syn keyword pythonBuiltin help hex id input int isinstance
|
||||
syn keyword pythonBuiltin issubclass iter len list locals map max
|
||||
syn keyword pythonBuiltin memoryview min next object oct open ord pow
|
||||
syn keyword pythonBuiltin print property range repr reversed round set
|
||||
syn keyword pythonBuiltin setattr slice sorted staticmethod str
|
||||
syn keyword pythonBuiltin sum super tuple type vars zip __import__
|
||||
" Python 2 only
|
||||
syn keyword pythonBuiltin basestring cmp execfile file
|
||||
syn keyword pythonBuiltin long raw_input reduce reload unichr
|
||||
syn keyword pythonBuiltin unicode xrange
|
||||
" Python 3 only
|
||||
syn keyword pythonBuiltin ascii bytes exec
|
||||
" non-essential built-in functions; Python 2 only
|
||||
syn keyword pythonBuiltin apply buffer coerce intern
|
||||
" avoid highlighting attributes as builtins
|
||||
syn match pythonAttribute /\.\h\w*/hs=s+1
|
||||
\ contains=ALLBUT,pythonBuiltin,pythonFunction,pythonAsync
|
||||
\ transparent
|
||||
endif
|
||||
|
||||
" From the 'Python Library Reference' class hierarchy at the bottom.
|
||||
" http://docs.python.org/2/library/exceptions.html
|
||||
" http://docs.python.org/3/library/exceptions.html
|
||||
if !exists("python_no_exception_highlight")
|
||||
" builtin base exceptions (used mostly as base classes for other exceptions)
|
||||
syn keyword pythonExceptions BaseException Exception
|
||||
syn keyword pythonExceptions ArithmeticError BufferError
|
||||
syn keyword pythonExceptions LookupError
|
||||
" builtin base exceptions removed in Python 3
|
||||
syn keyword pythonExceptions EnvironmentError StandardError
|
||||
" builtin exceptions (actually raised)
|
||||
syn keyword pythonExceptions AssertionError AttributeError
|
||||
syn keyword pythonExceptions EOFError FloatingPointError GeneratorExit
|
||||
syn keyword pythonExceptions ImportError IndentationError
|
||||
syn keyword pythonExceptions IndexError KeyError KeyboardInterrupt
|
||||
syn keyword pythonExceptions MemoryError NameError NotImplementedError
|
||||
syn keyword pythonExceptions OSError OverflowError ReferenceError
|
||||
syn keyword pythonExceptions RuntimeError StopIteration SyntaxError
|
||||
syn keyword pythonExceptions SystemError SystemExit TabError TypeError
|
||||
syn keyword pythonExceptions UnboundLocalError UnicodeError
|
||||
syn keyword pythonExceptions UnicodeDecodeError UnicodeEncodeError
|
||||
syn keyword pythonExceptions UnicodeTranslateError ValueError
|
||||
syn keyword pythonExceptions ZeroDivisionError
|
||||
" builtin OS exceptions in Python 3
|
||||
syn keyword pythonExceptions BlockingIOError BrokenPipeError
|
||||
syn keyword pythonExceptions ChildProcessError ConnectionAbortedError
|
||||
syn keyword pythonExceptions ConnectionError ConnectionRefusedError
|
||||
syn keyword pythonExceptions ConnectionResetError FileExistsError
|
||||
syn keyword pythonExceptions FileNotFoundError InterruptedError
|
||||
syn keyword pythonExceptions IsADirectoryError NotADirectoryError
|
||||
syn keyword pythonExceptions PermissionError ProcessLookupError
|
||||
syn keyword pythonExceptions RecursionError StopAsyncIteration
|
||||
syn keyword pythonExceptions TimeoutError
|
||||
" builtin exceptions deprecated/removed in Python 3
|
||||
syn keyword pythonExceptions IOError VMSError WindowsError
|
||||
" builtin warnings
|
||||
syn keyword pythonExceptions BytesWarning DeprecationWarning FutureWarning
|
||||
syn keyword pythonExceptions ImportWarning PendingDeprecationWarning
|
||||
syn keyword pythonExceptions RuntimeWarning SyntaxWarning UnicodeWarning
|
||||
syn keyword pythonExceptions UserWarning Warning
|
||||
" builtin warnings in Python 3
|
||||
syn keyword pythonExceptions ResourceWarning
|
||||
endif
|
||||
|
||||
if exists("python_space_error_highlight")
|
||||
" trailing whitespace
|
||||
syn match pythonSpaceError display excludenl "\s\+$"
|
||||
" mixed tabs and spaces
|
||||
syn match pythonSpaceError display " \+\t"
|
||||
syn match pythonSpaceError display "\t\+ "
|
||||
endif
|
||||
|
||||
" Do not spell doctests inside strings.
|
||||
" Notice that the end of a string, either ''', or """, will end the contained
|
||||
" doctest too. Thus, we do *not* need to have it as an end pattern.
|
||||
if !exists("python_no_doctest_highlight")
|
||||
if !exists("python_no_doctest_code_highlight")
|
||||
syn region pythonDoctest
|
||||
\ start="^\s*>>>\s" end="^\s*$"
|
||||
\ contained contains=ALLBUT,pythonDoctest,pythonFunction,@Spell
|
||||
syn region pythonDoctestValue
|
||||
\ start=+^\s*\%(>>>\s\|\.\.\.\s\|"""\|'''\)\@!\S\++ end="$"
|
||||
\ contained
|
||||
else
|
||||
syn region pythonDoctest
|
||||
\ start="^\s*>>>" end="^\s*$"
|
||||
\ contained contains=@NoSpell
|
||||
endif
|
||||
endif
|
||||
|
||||
" Sync at the beginning of class, function, or method definition.
|
||||
syn sync match pythonSync grouphere NONE "^\%(def\|class\)\s\+\h\w*\s*[(:]"
|
||||
|
||||
" The default highlight links. Can be overridden later.
|
||||
hi def link pythonStatement Statement
|
||||
hi def link pythonConditional Conditional
|
||||
hi def link pythonRepeat Repeat
|
||||
hi def link pythonOperator Operator
|
||||
hi def link pythonException Exception
|
||||
hi def link pythonInclude Include
|
||||
hi def link pythonAsync Statement
|
||||
hi def link pythonDecorator Define
|
||||
hi def link pythonDecoratorName Define
|
||||
hi def link pythonFunction Function
|
||||
hi def link pythonComment Comment
|
||||
hi def link pythonTodo Todo
|
||||
hi def link pythonString String
|
||||
hi def link pythonRawString String
|
||||
hi def link pythonQuotes String
|
||||
hi def link pythonTripleQuotes pythonQuotes
|
||||
hi def link pythonEscape Special
|
||||
if !exists("python_no_number_highlight")
|
||||
hi def link pythonNumber Number
|
||||
endif
|
||||
if !exists("python_no_builtin_highlight")
|
||||
hi def link pythonBuiltin Function
|
||||
endif
|
||||
if !exists("python_no_exception_highlight")
|
||||
hi def link pythonExceptions Structure
|
||||
endif
|
||||
if exists("python_space_error_highlight")
|
||||
hi def link pythonSpaceError Error
|
||||
endif
|
||||
if !exists("python_no_doctest_highlight")
|
||||
hi def link pythonDoctest Special
|
||||
hi def link pythonDoctestValue Define
|
||||
endif
|
||||
|
||||
let b:current_syntax = "python"
|
||||
|
||||
let &cpo = s:cpo_save
|
||||
unlet s:cpo_save
|
||||
|
||||
" vim:set sw=2 sts=2 ts=8 noet:
|
||||
143
test.py
143
test.py
@@ -1,143 +0,0 @@
|
||||
#! /usr/bin/env python
|
||||
# -*- coding: utf-8 -*-
|
||||
# Above the run-comment and file encoding comment.
|
||||
|
||||
# Comments.
|
||||
|
||||
# TODO FIXME XXX
|
||||
|
||||
# Keywords.
|
||||
|
||||
with break continue del exec return pass print raise global assert lambda yield
|
||||
for while if elif else import from as try except finally and in is not or
|
||||
|
||||
yield from
|
||||
|
||||
def functionname
|
||||
class Classname
|
||||
def функция
|
||||
class Класс
|
||||
|
||||
await
|
||||
async def Test
|
||||
async with
|
||||
async for
|
||||
|
||||
# Builtin objects.
|
||||
|
||||
True False Ellipsis None NotImplemented
|
||||
|
||||
# Builtin function and types.
|
||||
|
||||
__import__ abs all any apply basestring bool buffer callable chr classmethod
|
||||
cmp coerce compile complex delattr dict dir divmod enumerate eval execfile file
|
||||
filter float frozenset getattr globals hasattr hash help hex id input int
|
||||
intern isinstance issubclass iter len list locals long map max min object oct
|
||||
open ord pow property range raw_input reduce reload repr reversed round set
|
||||
setattr slice sorted staticmethod str sum super tuple type unichr unicode vars
|
||||
xrange zip
|
||||
|
||||
# Builtin exceptions and warnings.
|
||||
|
||||
BaseException Exception StandardError ArithmeticError LookupError
|
||||
EnvironmentError
|
||||
|
||||
AssertionError AttributeError 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 WindowsError ZeroDivisionError
|
||||
|
||||
Warning UserWarning DeprecationWarning PendingDepricationWarning SyntaxWarning
|
||||
RuntimeWarning FutureWarning ImportWarning UnicodeWarning
|
||||
|
||||
# Decorators.
|
||||
|
||||
@ decoratorname
|
||||
@ object.__init__(arg1, arg2)
|
||||
@ декоратор
|
||||
@ декоратор.décorateur
|
||||
|
||||
# Numbers
|
||||
|
||||
0 1 2 9 10 0x1f .3 12.34 0j 0j 34.2E-3 0b10 0o77 1023434 0x0
|
||||
|
||||
# Erroneous numbers
|
||||
|
||||
077 100L 0xfffffffL 0L 08 0xk 0x 0b102 0o78 0o123LaB
|
||||
|
||||
# Strings
|
||||
|
||||
" test " ' test '
|
||||
"""
|
||||
test
|
||||
"""
|
||||
'''
|
||||
test
|
||||
'''
|
||||
|
||||
" \a\b\c\"\'\n\r \x34\077 \08 \xag"
|
||||
r" \" \' "
|
||||
|
||||
"testтест"
|
||||
|
||||
b"test"
|
||||
|
||||
b"test\r\n\xffff"
|
||||
|
||||
b"тестtest"
|
||||
|
||||
br"test"
|
||||
|
||||
br"\a\b\n\r"
|
||||
|
||||
# Formattings
|
||||
|
||||
" %f "
|
||||
b" %f "
|
||||
|
||||
"{0.name!r:b} {0[n]} {name!s: } {{test}} {{}} {} {.__len__:s}"
|
||||
b"{0.name!r:b} {0[n]} {name!s: } {{test}} {{}} {} {.__len__:s}"
|
||||
|
||||
"${test} ${test ${test}aname $$$ $test+nope"
|
||||
b"${test} ${test ${test}aname $$$ $test+nope"
|
||||
|
||||
# Doctests.
|
||||
|
||||
"""
|
||||
Test:
|
||||
>>> a = 5
|
||||
>>> a
|
||||
5
|
||||
|
||||
Test
|
||||
"""
|
||||
|
||||
'''
|
||||
Test:
|
||||
>>> a = 5
|
||||
>>> a
|
||||
5
|
||||
|
||||
Test
|
||||
'''
|
||||
|
||||
# Erroneous symbols or bad variable names.
|
||||
|
||||
$ ? 6xav
|
||||
|
||||
&& || ===
|
||||
|
||||
# Indentation errors.
|
||||
|
||||
break
|
||||
|
||||
# Trailing space errors.
|
||||
|
||||
|
||||
break
|
||||
"""
|
||||
|
||||
test
|
||||
"""
|
||||
Reference in New Issue
Block a user