diff --git a/.vintrc.yaml b/.vintrc.yaml new file mode 100644 index 0000000..b371660 --- /dev/null +++ b/.vintrc.yaml @@ -0,0 +1,3 @@ +policies: + ProhibitImplicitScopeVariable: + enabled: false diff --git a/AUTHORS b/AUTHORS new file mode 100644 index 0000000..605a3bf --- /dev/null +++ b/AUTHORS @@ -0,0 +1,26 @@ +# This is the list of python-syntax authors for copyright purposes. +# +# This does not necessarily list everyone who has contributed code, since in +# some cases, their employer may be the copyright holder. To see the full list +# of contributors, see the revision history in source control. + +Andrea Riciputi +Anton Butanaev +Antony Lee +Caleb Adamantine +David Briscoe +Dmitry Vasiliev +Elizabeth Myers +Ihor Gorobets +Jeroen Ruigrok van der Werven +John Eikenberry +Joongi Kim +lilydjwg +Marc Weber +Michael Doronin +Neil Schemenauer +nfnty +Pedro Algarvio +Victor Salgado +Will Gray +Yuri Habrusiev diff --git a/CHANGES.txt b/CHANGES.txt deleted file mode 100644 index 2d3b520..0000000 --- a/CHANGES.txt +++ /dev/null @@ -1,224 +0,0 @@ -Revision 3.6.0 (2015-11-XX): - - - Fix 'async def' highlighting. Patch by Joongi Kim - - Add dummy 'pythonInclude' group to avoid crashing standard pyrex.vim. - Patch by Antony Lee - -Revision 3.5.0 (2015-06-10): - - - Add support for 'async ...' and 'await' keywords introduced in - Python 3.5. Patch by Ihor Gorobets - -Revision 3.3.7 (2014-12-27): - - - Add support for Python 3 non-ASCII decorator names. - Patch by Victor Salgado - -Revision 3.3.6 (2013-11-18): - - - Highlight 'yield from' statement introduced in Python 3.3. Reported by - Elizabeth Myers. - -Revision 3.3.5 (2013-08-31): - - - Highlight 'import', 'from' and 'as' as include statements. - Patch by David Briscoe - - Added new option 'python_highlight_file_headers_as_comments' (disabled by - default) to highlight shebang and coding file headers as comments. - Proposed by David Briscoe. - -Revision 3.3.4 (2013-08-11): - - - Highlight True and False as booleans. Patch by Yuri Habrusiev. - -Revision 3.3.3 (2013-06-02): - - - More lightweight syntax reloading. Patch by Will Gray. - -Revision 3.3.2 (2013-06-01): - - - Fixed behaviour of b:python_version_2 variable. Reported by Will Gray. - -Revision 3.3.1 (2013-05-12): - - - The script was moved to its own repository at - https://github.com/hdima/python-syntax - -Revision 3.3.0 (2013-03-10): - - - Merge Python 2 and Python 3 script versions into the single python.vim - script - -Revision 3.0.7 (2012-02-11): - - - Updated email and URL - -Revision 2.6.7 (2012-02-11): - - - Updated email and URL - -Revision 3.0.6 (2010-11-14): - - - Fixed highlighting for str.format syntax. Patch by Anton Butanaev. - -Revision 3.0.5 (2010-11-11): - - - Fixed highlighting for bytes. Patch by Anton Butanaev. - - Fixed highlighting for numbers. - -Revision 3.0.4 (2010-11-09): - - - Fixed highlighting for raw bytes literals. Patch by Anton Butanaev. - -Revision 3.0.3 (2010-04-09): - - - Applied patch by Andrea Riciputi with new configuration options - "python_highlight_builtin_objs" and "python_highlight_builtin_funcs" - -Revision 3.0.2 (2009-07-24): - - - Applied patch by Caleb Adamantine which fixes highlighting for decorators - -Revision 3.0.1 (2009-05-03): - - - Fixed compatibility with pyrex.vim - -Revision 3.0.0 (2008-12-07): - - - Added support for non-ASCII identifiers; - - Added support for new text strings and binary data (bytes); - - Updated support for numeric literals; - - Updated support for str.format; - - Added new builtins introduced in Python 2.6: "ascii", "exec", - "memoryview", "print"; - - Added new keyword "nonlocal"; - - Removed exception "StandardError"; - - Removed builtins: "apply", "basestring", "buffer", "callable", "coerce", - "execfile", "file", "help", "intern", "long", "raw_input", "reduce", - "reload", "unichr", "unicode", "xrange"; - -Revision 2.6.6 (2010-04-09): - - - Applied patch by Andrea Riciputi with new configuration options - "python_highlight_builtin_objs" and "python_highlight_builtin_funcs" - -Revision 2.6.5 (2009-07-24): - - - Applied patch by Caleb Adamantine which fixes highlighting for decorators - -Revision 2.6.4 (2009-05-03): - - - Fixed compatibility with pyrex.vim - -Revision 2.6.3 (2008-09-29): - - - Return back trailing 'L' support for numbers. Actually it was changed for - future Python 3.0 syntax but in wrong file; - -Revision 2.6.2 (2008-09-22): - - - Added "VMSError" exception; - - Added support for b"..." syntax; - - Added support for str.format brace escaping; - -Revision 2.6.1 (2008-09-21): - - - Added new builtins and exceptions introduced in Python 2.6: "bin", - "bytearray", "bytes", "format", "next", "BufferError", "BytesWarning"; - - Added builtin "__debug__"; - - Added global variables: "__doc__", "__file__", "__name__", "__package__"; - - Removed "OverflowWarning" (removed in Python 2.5); - - Added option "python_print_as_function" for highlight "print" as a - function; - - Added support for new integer literal syntax "0o" and "0b"; - - Added support for string.Template syntax controlled by - "python_highlight_string_templates" option; - - Added support for str.format syntax controlled by - "python_highlight_string_format" option; - - Removed highlighting for "--" and "++" because it's a valid Python - expressions which can be interpreted as "a + +b"; - -Revision 2.5.6 (2007-02-04): - - - Applied patch by Pedro Algarvio to enable spell checking only for - the right spots (strings and comments); - -Revision 2.5.5 (2006-09-26): - - - added new warnings (ImportWarning, UnicodeWarning) - introduced in Python 2.5; - -Revision 2.5.4 (2006-05-11): - - - added highlighting for erroneous operators: &&, ||, ++, --, === - (inspired by http://www.vim.org/tips/tip.php?tip_id=969, thanks - Jeroen Ruigrok van der Werven for the link); - - added highlighting for new 'with' statement and 'BaseException', - 'GeneratorExit' exceptions introduced in Python 2.5; - - added highlighting for 'OverflowWarning' exception which had been - forgotten; - - returned more robust recognition for function names; - -Revision 2.5.3: - - - fixed %-formatting highlighting for raw unicode strings; - -Revision 2.5.2: - - - slightly simplified option handling; - - fixed regexp for indentation errors; - - fixed highlighting for backslashed symbols inside strings; - - added highlighting for trailing-space errors (triggered by new - option: python_highlight_space_errors); - - added highlighting for variable name errors; - - added highlighting for hex number errors; - -Revision 2.5.1 (2005-03-13): - - - added new builtins 'all' and 'any' (Python 2.5a0) - -Revision 2.4.2 (2004-08-05): - - - added highlighting for new @decorator syntax introduced in python 2.4a2 - -Revision 2.4.1 (2004-03-17): - - - new versioning scheme (based on python version numbers); - - added highlighting for new types/builtins introduced in python 2.4 - (set, frozenset, reversed, sorted); - - new option added: python_slow_sync (set this for slow but more - robust syntax synchronization); - - added highlighting for doctests; - -Revision 1.19: - - - new option added: python_highlight_indent_errors; - - python_highlight_all now not override previously set options, - for example code: - let python_highlight_indent_errors = 0 - let python_highlight_all = 1 - set all highlight options except indentation errors highlighting option; - -Revision 1.17: - - - changed header, "Based on..." string added; - -Revision 1.16: - - - added basestring builtin; - -Revision 1.15 (first public revision). - - The changes since the original (vim6.1) python.vim are: - - - changed string highlighting; - - enhanced special symbols highlighting inside strings; - - enhanced constant numbers highlighting; - - added optional highlighting for %-formatting inside strings; - - added highlighting for error conditions (wrong symbols in source file, - mixing spaces and tabs, wrong number values, - wrong %-formatting inside strings); - - added highlighting for magic comments: source code encoding - and #! (executable) strings; - - added highlighting for new exceptions and builtins introduced - in python 2.3; diff --git a/LICENSE b/LICENSE index 348583e..bcaa459 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,7 @@ The MIT License (MIT) Copyright (c) 2002-2014 Dmitry Vasiliev +Copyright (c) 2017- the python-syntax authors Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/README.md b/README.md new file mode 100644 index 0000000..8c35ec2 --- /dev/null +++ b/README.md @@ -0,0 +1,84 @@ +Python syntax highlighting for Vim +========================================= + +This is an enhanced version of the original Vim 6.1 Python syntax highlighting +`python.vim` by Neil Schemenauer. + +Features +-------- + +* Enhanced highlighting for: + * Strings + * Special symbols inside strings + * Numeric constants +* Added support for: + * Python 3 + * Numbers with underscores + * String %-formatting and f-strings + * Magic comments: source code encoding and shebangs + * New exceptions and builtins + * Doctests + * `@decorator` syntax + * Class variables such as `self` and `cls` + * Operators +* Highlighting of the following errors: + * Invalid symbols in source file + * Invalid numeric constants + * Invalid %-formatting inside strings + * Invalid variable names + * Invalid operators + * Mixing spaces and tabs + * Trailing spaces (Enabled with `g:python_highlight_space_errors`) +* Commands for easy switching between versions + +Folding is done by the plugin [SimpylFold](https://github.com/tmhedberg/SimpylFold). + +How to install +-------------- + +Use one of the following plugin managers: + +* [dein](https://github.com/Shougo/dein.vim) +* [vim-plug](https://github.com/junegunn/vim-plug) +* [vundle](https://github.com/VundleVim/Vundle.vim) +* [pathogen](https://github.com/tpope/vim-pathogen) + +Configuration +------------- + +### Option variables + +Set variable to `1` to enable or `0` to disable. + +For example to enable all syntax highlighting features you can add the +following command to your `~/.config/nvim/init.vim` or `~/.vimrc`: +```vim +let g:python_highlight_all = 1 +``` +| Variable | Description | Default | +| --------------------------------------------- | -------------------------------------------------------------- | ------- | +| `g:python_version_2` | Python 2 mode | `0` | +| `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_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` | +| `g:python_highlight_string_formatting` | Highlight `%` string formatting | `0` | +| `g:python_highlight_string_format` | Highlight syntax of `str.format` syntax | `0` | +| `g:python_highlight_string_templates` | Highlight syntax of `string.Template` | `0` | +| `g:python_highlight_indent_errors` | Highlight indentation errors | `0` | +| `g:python_highlight_space_errors` | Highlight trailing spaces | `0` | +| `g:python_highlight_doctests` | Highlight doc-tests | `0` | +| `g:python_highlight_class_vars` | Highlight class variables `self` and `cls` | `0` | +| `g:python_highlight_operators` | Highlight all operators | `0` | +| `g:python_highlight_all` | Enable all highlight options above, except for previously set. | `0` | +| `g:python_highlight_file_headers_as_comments` | Highlight shebang and coding headers as comments | `0` | +| `g:python_slow_sync` | Disable for slow machines | `1` | + +### Commands + +| Command | Description | +| --------------- | ------------------ | +| `Python2Syntax` | Switch to Python 2 | +| `Python3Syntax` | Switch to Python 3 | diff --git a/README.rst b/README.rst deleted file mode 100644 index f9cd20d..0000000 --- a/README.rst +++ /dev/null @@ -1,147 +0,0 @@ -Python syntax highlighting script for Vim -========================================= - -.. contents:: - -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 -`_. - -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 - `__ - -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``. - -How to install --------------- - -The easiest installation method is to place `syntax/python.vim -`_ script -into your ``~/.vim/syntax/`` directory. - -You can also use `Pathogen `_ or `Vundle -`_ plugin managers in which case you can -install the whole `python.vim repository -`_ 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 `_ -- 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 `_ diff --git a/TODO.txt b/TODO.txt deleted file mode 100644 index 605c45a..0000000 --- a/TODO.txt +++ /dev/null @@ -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) diff --git a/doc/python-syntax.txt b/doc/python-syntax.txt new file mode 100644 index 0000000..a1ccf16 --- /dev/null +++ b/doc/python-syntax.txt @@ -0,0 +1,114 @@ +*python-syntax.txt* Python syntax highlighting + +============================================================================== +Introduction *python-syntax* *ft-python-syntax* *python.vim* + +This is an enhanced version of the original Vim 6.1 Python syntax highlighting +`python.vim` by Neil Schemenauer. + +Features +-------- + +* Enhanced highlighting for: + * Strings + * Special symbols inside strings + * Numeric constants +* Added support for: + * Python 3 + * Numbers with underscores + * String %-formatting and f-strings + * Magic comments: source code encoding and shebangs + * New exceptions and builtins + * Doctests + * `@decorator` syntax + * Class variables such as `self` and `cls` + * Operators +* Highlighting of the following errors: + * Invalid symbols in source file + * Invalid numeric constants + * Invalid %-formatting inside strings + * Invalid variable names + * Invalid operators + * Mixing spaces and tabs + * Trailing spaces (Enabled with `g:python_highlight_space_errors`) +* Commands for easy switching between versions + +Folding is done by the plugin SimpylFold +(https://github.com/tmhedberg/SimpylFold). + +============================================================================== +Configuration *python-syntax-configuration* + +Option variables +---------------- + +Set variable to `1` to enable or `0` to disable. + +For example to enable all syntax highlighting features you can add the +following command to your `~/.config/nvim/init.vim` or `~/.vimrc`: > + + let g:python_highlight_all = 1 +< + +`g:python_version_2` (default `0`) + Python 2 mode + +`b:python_version_2` (default `0`) + Python 2 mode (buffer local) + +`g:python_highlight_builtins` (default `0`) + Highlight builtin functions and objects + +`g:python_highlight_builtin_objs` (default `0`) + Highlight builtin objects only + +`g:python_highlight_builtin_funcs` (default `0`) + Highlight builtin functions only + +`g:python_highlight_builtin_funcs_kwarg` (default `1`) + Highlight builtin functions when used as kwarg + +`g:python_highlight_exceptions` (default `0`) + Highlight standard exceptions + +`g:python_highlight_string_formatting` (default `0`) + Highlight `%` string formatting + +`g:python_highlight_string_format` (default `0`) + Highlight syntax of `str.format` syntax + +`g:python_highlight_string_templates` (default `0`) + Highlight syntax of `string.Template` + +`g:python_highlight_indent_errors` (default `0`) + Highlight indentation errors + +`g:python_highlight_space_errors` (default `0`) + Highlight trailing spaces + +`g:python_highlight_doctests` (default `0`) + Highlight doc-tests + +`g:python_highlight_class_vars` (default `0`) + Highlight class variables `self` and `cls` + +`g:python_highlight_operators` (default `0`) + Highlight all operators + +`g:python_highlight_all` (default `0`) + Enable all highlight options above, except for previously set. + +`g:python_highlight_file_headers_as_comments` (default `0`) + Highlight shebang and coding headers as comments + +`g:python_slow_sync` (default `1`) + Disable for slow machines + +Commands +-------- + +`Python2Syntax` + Switch to Python 2 + +`Python3Syntax` + Switch to Python 3 diff --git a/folding-ideas/python.vim.1.13 b/folding-ideas/python.vim.1.13 deleted file mode 100644 index e5ea668..0000000 --- a/folding-ideas/python.vim.1.13 +++ /dev/null @@ -1,237 +0,0 @@ -" Vim syntax file -" Language: Python -" Maintainer: Neil Schemenauer -" Updated: $Date: 2003/01/12 14:17:34 $ -" Updated by: Dmitry Vasiliev -" Filenames: *.py -" $Revision: 1.13 $ -" -" Options: -" For folded functions and classes: -" -" let python_folding = 1 -" -" For highlighted builtin functions: -" -" let python_highlight_builtins = 1 -" -" For highlighted standard exceptions: -" -" let python_highlight_exceptions = 1 -" -" For highlighted string formatting: -" -" let python_highlight_string_formatting = 1 -" -" If you want all possible Python highlighting: -" -" let python_highlight_all = 1 -" -" TODO: Check more errors? - -" For version 5.x: Clear all syntax items -" For version 6.x: Quit when a syntax file was already loaded -if version < 600 - syntax clear -elseif exists("b:current_syntax") - finish -endif - -if exists("python_highlight_all") - let python_folding = 1 - let python_highlight_builtins = 1 - let python_highlight_exceptions = 1 - let python_highlight_string_formatting = 1 -endif - -" Keywords -syn keyword pythonStatement break continue del -syn keyword pythonStatement exec return -syn keyword pythonStatement pass print raise -syn keyword pythonStatement global assert -syn keyword pythonStatement lambda yield -if exists("python_folding") && has("folding") - syn match pythonStatement "\<\(def\|class\)\>" display nextgroup=pythonFunction skipwhite -else - syn keyword pythonStatement def class nextgroup=pythonFunction skipwhite -endif -syn match pythonFunction "\h\w*" display contained -syn keyword pythonRepeat for while -syn keyword pythonConditional if elif else -syn keyword pythonImport import from as -syn keyword pythonException try except finally -syn keyword pythonOperator and in is not or - -" Comments -syn match pythonComment "#.*$" display contains=pythonTodo -syn keyword pythonTodo TODO FIXME XXX contained - -" Erroneous characters that cannont be in a python program -syn match pythonError "[@$?]" display -" Mixing spaces and tabs is bad -syn match pythonIndentError "^\s*\(\t \| \t\)\s*" display - -" Strings -syn region pythonString start=+'+ skip=+\\\\\|\\'\|\\$+ excludenl end=+'+ end=+$+ contains=pythonEscape,pythonEscapeError -syn region pythonString start=+"+ skip=+\\\\\|\\"\|\\$+ excludenl end=+"+ end=+$+ contains=pythonEscape,pythonEscapeError -syn region pythonString start=+"""+ end=+"""+ contains=pythonEscape,pythonEscapeError -syn region pythonString start=+'''+ end=+'''+ contains=pythonEscape,pythonEscapeError - -syn match pythonEscape +\\[abfnrtv'"\\]+ display contained -syn match pythonEscapeError +\\[^abfnrtv'"\\]+ display contained -syn match pythonEscape "\\\o\o\=\o\=" display contained -syn match pythonEscapeError "\\\o\{,2}[89]" display contained -syn match pythonEscape "\\x\x\{2}" display contained -syn match pythonEscapeError "\\x\x\=\X" display contained -syn match pythonEscape "\\$" - -" Unicode strings -syn region pythonUniString start=+[uU]'+ skip=+\\\\\|\\'\|\\$+ excludenl end=+'+ end=+$+ contains=pythonEscape,pythonUniEscape,pythonEscapeError,pythonUniEscapeError -syn region pythonUniString start=+[uU]"+ skip=+\\\\\|\\"\|\\$+ excludenl end=+"+ end=+$+ contains=pythonEscape,pythonUniEscape,pythonEscapeError,pythonUniEscapeError -syn region pythonUniString start=+[uU]"""+ end=+"""+ contains=pythonEscape,pythonUniEscape,pythonEscapeError,pythonUniEscapeError -syn region pythonUniString start=+[uU]'''+ end=+'''+ contains=pythonEscape,pythonUniEscape,pythonEscapeError,pythonUniEscapeError - -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 - -" Raw strings -syn region pythonRawString start=+[rR]'+ skip=+\\\\\|\\'\|\\$+ excludenl end=+'+ end=+$+ contains=pythonRawEscape -syn region pythonRawString start=+[rR]"+ skip=+\\\\\|\\"\|\\$+ excludenl end=+"+ end=+$+ contains=pythonRawEscape -syn region pythonRawString start=+[rR]"""+ end=+"""+ -syn region pythonRawString start=+[rR]'''+ end=+'''+ - -syn match pythonRawEscape +\\['"]+ display transparent contained - -" Unicode raw strings -syn region pythonUniRawString start=+[uU][rR]'+ skip=+\\\\\|\\'\|\\$+ excludenl end=+'+ end=+$+ contains=pythonRawEscape,pythonUniRawEscape,pythonUniRawEscapeError -syn region pythonUniRawString start=+[uU][rR]"+ skip=+\\\\\|\\"\|\\$+ excludenl end=+"+ end=+$+ contains=pythonRawEscape,pythonUniRawEscape,pythonUniRawEscapeError -syn region pythonUniRawString start=+[uU][rR]"""+ end=+"""+ contains=pythonUniRawEscape,pythonUniRawEscapeError -syn region pythonUniRawString start=+[uU][rR]'''+ end=+'''+ contains=pythonUniRawEscape,pythonUniRawEscapeError - -syn match pythonUniRawEscape "\([^\\]\(\\\\\)*\)\@<=\\u\x\{4}" display contained -syn match pythonUniRawEscapeError "\([^\\]\(\\\\\)*\)\@<=\\u\x\{,3}\X" display contained - -if exists("python_highlight_string_formatting") - " String formatting - syn match pythonStrFormat "%\(([^)]\+)\)\=[-#0 +]\=\d*\(\.\d\+\)\=[hlL]\=[diouxXeEfFgGcrs%]" contained containedin=pythonString,pythonUniString,pythonRawString - syn match pythonStrFormat "%[-#0 +]\=\(\*\|\d\+\)\=\(\.\(\*\|\d\+\)\)\=[hlL]\=[diouxXeEfFgGcrs%]" contained containedin=pythonString,pythonUniString,pythonRawString -endif - -" Numbers (ints, longs, floats, complex) -syn match pythonNumber "\<0[xX]\x\+[lL]\=\>" display -syn match pythonNumber "\<\d\+[lLjJ]\=\>" display -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 -syn match pythonOctalError "\<0\o*[89]\d*[lLjJ]\=\>" display - -if exists("python_highlight_builtins") - " Builtin functions, types and objects, not really part of the syntax - syn keyword pythonBuiltinObj True False Ellipsis None NotImplemented - syn keyword pythonBuiltinFunc bool __import__ abs - syn keyword pythonBuiltinFunc apply buffer callable chr classmethod cmp - syn keyword pythonBuiltinFunc coerce compile complex delattr dict dir divmod - syn keyword pythonBuiltinFunc eval execfile file filter float getattr globals - syn keyword pythonBuiltinFunc hasattr hash hex id input int intern isinstance - syn keyword pythonBuiltinFunc issubclass iter len list locals long map max - syn keyword pythonBuiltinFunc min object oct open ord pow property range - syn keyword pythonBuiltinFunc raw_input reduce reload repr round setattr - syn keyword pythonBuiltinFunc slice staticmethod str super tuple type unichr - syn keyword pythonBuiltinFunc unicode vars xrange zip -endif - -if exists("python_highlight_exceptions") - " Builtin exceptions and warnings - syn keyword pythonExClass ArithmeticError AssertionError AttributeError - syn keyword pythonExClass DeprecationWarning EOFError EnvironmentError - syn keyword pythonExClass Exception FloatingPointError IOError - syn keyword pythonExClass ImportError IndentiationError IndexError - syn keyword pythonExClass KeyError KeyboardInterrupt LookupError - syn keyword pythonExClass MemoryError NameError NotImplementedError - syn keyword pythonExClass OSError OverflowError OverflowWarning - syn keyword pythonExClass ReferenceError RuntimeError RuntimeWarning - syn keyword pythonExClass StandardError StopIteration SyntaxError - syn keyword pythonExClass SyntaxWarning SystemError SystemExit TabError - syn keyword pythonExClass TypeError UnboundLocalError UnicodeError - syn keyword pythonExClass UserWarning ValueError Warning WindowsError - syn keyword pythonExClass ZeroDivisionError -endif - -syn sync clear -if exists("python_folding") && has("folding") - syn sync fromstart - - "syn match pythonFold "^\(\s*\)\(class\|def\)\s.*\(\(\n\s*\)*\n\1\s\+\S.*\)\+" transparent fold - syn region pythonFold start="^\z(\s*\)\(class\|def\)\s" skip="^\z1\s\+\S" end="^\s*\S"me=s-1 transparent fold - syn region pythonFold start="{" end="}" transparent fold - syn region pythonFold start="\[" end="\]" transparent fold -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. If - " you have a fast machine you can try uncommenting the "sync minlines" - " and commenting out the rest. - syn sync match pythonSync grouphere NONE "):$" - syn sync maxlines=200 - "syn sync minlines=2000 -endif - -if version >= 508 || !exists("did_python_syn_inits") - if version <= 508 - let did_python_syn_inits = 1 - command -nargs=+ HiLink hi link - else - command -nargs=+ HiLink hi def link - endif - - HiLink pythonStatement Statement - HiLink pythonImport Statement - HiLink pythonFunction Function - HiLink pythonConditional Conditional - HiLink pythonRepeat Repeat - HiLink pythonException Exception - HiLink pythonOperator Operator - - HiLink pythonComment Comment - HiLink pythonTodo Todo - - HiLink pythonError Error - HiLink pythonIndentError Error - - HiLink pythonString String - HiLink pythonUniString String - HiLink pythonRawString String - HiLink pythonUniRawString String - - HiLink pythonEscape Special - HiLink pythonEscapeError Error - HiLink pythonUniEscape Special - HiLink pythonUniEscapeError Error - HiLink pythonUniRawEscape Special - HiLink pythonUniRawEscapeError Error - - if exists("python_highlight_string_formatting") - HiLink pythonStrFormat Special - endif - - HiLink pythonNumber Number - HiLink pythonFloat Float - HiLink pythonOctalError Error - - if exists("python_highlight_builtins") - HiLink pythonBuiltinObj Structure - HiLink pythonBuiltinFunc Function - endif - - if exists("python_highlight_exceptions") - HiLink pythonExClass Structure - endif - - delcommand HiLink -endif - -let b:current_syntax = "python" diff --git a/folding-ideas/python.vim.1.14 b/folding-ideas/python.vim.1.14 deleted file mode 100644 index 9027838..0000000 --- a/folding-ideas/python.vim.1.14 +++ /dev/null @@ -1,236 +0,0 @@ -" Vim syntax file -" Language: Python -" Maintainer: Neil Schemenauer -" Updated: $Date: 2003/01/12 15:35:02 $ -" Updated by: Dmitry Vasiliev -" Filenames: *.py -" $Revision: 1.14 $ -" -" Options: -" For folded functions and classes: -" -" let python_folding = 1 -" -" For highlighted builtin functions: -" -" let python_highlight_builtins = 1 -" -" For highlighted standard exceptions: -" -" let python_highlight_exceptions = 1 -" -" For highlighted string formatting: -" -" let python_highlight_string_formatting = 1 -" -" If you want all possible Python highlighting: -" -" let python_highlight_all = 1 -" -" TODO: Check more errors? - -" For version 5.x: Clear all syntax items -" For version 6.x: Quit when a syntax file was already loaded -if version < 600 - syntax clear -elseif exists("b:current_syntax") - finish -endif - -if exists("python_highlight_all") - let python_folding = 1 - let python_highlight_builtins = 1 - let python_highlight_exceptions = 1 - let python_highlight_string_formatting = 1 -endif - -" Keywords -syn keyword pythonStatement break continue del -syn keyword pythonStatement exec return -syn keyword pythonStatement pass print raise -syn keyword pythonStatement global assert -syn keyword pythonStatement lambda yield -if exists("python_folding") && has("folding") - syn match pythonStatement "\<\(def\|class\)\>" display nextgroup=pythonFunction skipwhite -else - syn keyword pythonStatement def class nextgroup=pythonFunction skipwhite -endif -syn match pythonFunction "\h\w*" display contained -syn keyword pythonRepeat for while -syn keyword pythonConditional if elif else -syn keyword pythonImport import from as -syn keyword pythonException try except finally -syn keyword pythonOperator and in is not or - -" Comments -syn match pythonComment "#.*$" display contains=pythonTodo -syn keyword pythonTodo TODO FIXME XXX contained - -" Erroneous characters that cannont be in a python program -syn match pythonError "[@$?]" display -" Mixing spaces and tabs is bad -syn match pythonError "^\s*\(\t \| \t\)\s*" display - -" Strings -syn region pythonString start=+'+ skip=+\\\\\|\\'\|\\$+ excludenl end=+'+ end=+$+ contains=pythonEscape,pythonEscapeError -syn region pythonString start=+"+ skip=+\\\\\|\\"\|\\$+ excludenl end=+"+ end=+$+ contains=pythonEscape,pythonEscapeError -syn region pythonString start=+"""+ end=+"""+ contains=pythonEscape,pythonEscapeError -syn region pythonString start=+'''+ end=+'''+ contains=pythonEscape,pythonEscapeError - -syn match pythonEscape +\\[abfnrtv'"\\]+ display contained -syn match pythonEscapeError +\\[^abfnrtv'"\\]+ display contained -syn match pythonEscape "\\\o\o\=\o\=" display contained -syn match pythonEscapeError "\\\o\{,2}[89]" display contained -syn match pythonEscape "\\x\x\{2}" display contained -syn match pythonEscapeError "\\x\x\=\X" display contained -syn match pythonEscape "\\$" - -" Unicode strings -syn region pythonUniString start=+[uU]'+ skip=+\\\\\|\\'\|\\$+ excludenl end=+'+ end=+$+ contains=pythonEscape,pythonUniEscape,pythonEscapeError,pythonUniEscapeError -syn region pythonUniString start=+[uU]"+ skip=+\\\\\|\\"\|\\$+ excludenl end=+"+ end=+$+ contains=pythonEscape,pythonUniEscape,pythonEscapeError,pythonUniEscapeError -syn region pythonUniString start=+[uU]"""+ end=+"""+ contains=pythonEscape,pythonUniEscape,pythonEscapeError,pythonUniEscapeError -syn region pythonUniString start=+[uU]'''+ end=+'''+ contains=pythonEscape,pythonUniEscape,pythonEscapeError,pythonUniEscapeError - -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 - -" Raw strings -syn region pythonRawString start=+[rR]'+ skip=+\\\\\|\\'\|\\$+ excludenl end=+'+ end=+$+ contains=pythonRawEscape -syn region pythonRawString start=+[rR]"+ skip=+\\\\\|\\"\|\\$+ excludenl end=+"+ end=+$+ contains=pythonRawEscape -syn region pythonRawString start=+[rR]"""+ end=+"""+ -syn region pythonRawString start=+[rR]'''+ end=+'''+ - -syn match pythonRawEscape +\\['"]+ display transparent contained - -" Unicode raw strings -syn region pythonUniRawString start=+[uU][rR]'+ skip=+\\\\\|\\'\|\\$+ excludenl end=+'+ end=+$+ contains=pythonRawEscape,pythonUniRawEscape,pythonUniRawEscapeError -syn region pythonUniRawString start=+[uU][rR]"+ skip=+\\\\\|\\"\|\\$+ excludenl end=+"+ end=+$+ contains=pythonRawEscape,pythonUniRawEscape,pythonUniRawEscapeError -syn region pythonUniRawString start=+[uU][rR]"""+ end=+"""+ contains=pythonUniRawEscape,pythonUniRawEscapeError -syn region pythonUniRawString start=+[uU][rR]'''+ end=+'''+ contains=pythonUniRawEscape,pythonUniRawEscapeError - -syn match pythonUniRawEscape "\([^\\]\(\\\\\)*\)\@<=\\u\x\{4}" display contained -syn match pythonUniRawEscapeError "\([^\\]\(\\\\\)*\)\@<=\\u\x\{,3}\X" display contained - -if exists("python_highlight_string_formatting") - " String formatting - syn match pythonStrFormat "%\(([^)]\+)\)\=[-#0 +]\=\d*\(\.\d\+\)\=[hlL]\=[diouxXeEfFgGcrs%]" contained containedin=pythonString,pythonUniString,pythonRawString - syn match pythonStrFormat "%[-#0 +]\=\(\*\|\d\+\)\=\(\.\(\*\|\d\+\)\)\=[hlL]\=[diouxXeEfFgGcrs%]" contained containedin=pythonString,pythonUniString,pythonRawString -endif - -" Numbers (ints, longs, floats, complex) -syn match pythonNumber "\<0[xX]\x\+[lL]\=\>" display -syn match pythonNumber "\<\d\+[lLjJ]\=\>" display -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 -syn match pythonOctalError "\<0\o*[89]\d*[lLjJ]\=\>" display - -if exists("python_highlight_builtins") - " Builtin functions, types and objects, not really part of the syntax - syn keyword pythonBuiltinObj True False Ellipsis None NotImplemented - syn keyword pythonBuiltinFunc bool __import__ abs - syn keyword pythonBuiltinFunc apply buffer callable chr classmethod cmp - syn keyword pythonBuiltinFunc coerce compile complex delattr dict dir divmod - syn keyword pythonBuiltinFunc eval execfile file filter float getattr globals - syn keyword pythonBuiltinFunc hasattr hash hex id input int intern isinstance - syn keyword pythonBuiltinFunc issubclass iter len list locals long map max - syn keyword pythonBuiltinFunc min object oct open ord pow property range - syn keyword pythonBuiltinFunc raw_input reduce reload repr round setattr - syn keyword pythonBuiltinFunc slice staticmethod str super tuple type unichr - syn keyword pythonBuiltinFunc unicode vars xrange zip -endif - -if exists("python_highlight_exceptions") - " Builtin exceptions and warnings - syn keyword pythonExClass ArithmeticError AssertionError AttributeError - syn keyword pythonExClass DeprecationWarning EOFError EnvironmentError - syn keyword pythonExClass Exception FloatingPointError IOError - syn keyword pythonExClass ImportError IndentiationError IndexError - syn keyword pythonExClass KeyError KeyboardInterrupt LookupError - syn keyword pythonExClass MemoryError NameError NotImplementedError - syn keyword pythonExClass OSError OverflowError OverflowWarning - syn keyword pythonExClass ReferenceError RuntimeError RuntimeWarning - syn keyword pythonExClass StandardError StopIteration SyntaxError - syn keyword pythonExClass SyntaxWarning SystemError SystemExit TabError - syn keyword pythonExClass TypeError UnboundLocalError UnicodeError - syn keyword pythonExClass UserWarning ValueError Warning WindowsError - syn keyword pythonExClass ZeroDivisionError -endif - -syn sync clear -if exists("python_folding") && has("folding") - syn sync fromstart - - "syn match pythonFold "^\(\s*\)\(class\|def\)\s.*\(\(\n\s*\)*\n\1\s\+\S.*\)\+" transparent fold - syn region pythonFold start="^\z(\s*\)\(class\|def\)\s" skip="\(\s*\n\)\+\z1\s\+\(\S\|\%$\)" end="\(\s*\n\)\+\s*\(\S\|\%$\)"me=s-1 transparent fold - syn region pythonFold start="{" end="}" transparent fold - syn region pythonFold start="\[" end="\]" transparent fold -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. If - " you have a fast machine you can try uncommenting the "sync minlines" - " and commenting out the rest. - syn sync match pythonSync grouphere NONE "):$" - syn sync maxlines=200 - "syn sync minlines=2000 -endif - -if version >= 508 || !exists("did_python_syn_inits") - if version <= 508 - let did_python_syn_inits = 1 - command -nargs=+ HiLink hi link - else - command -nargs=+ HiLink hi def link - endif - - HiLink pythonStatement Statement - HiLink pythonImport Statement - HiLink pythonFunction Function - HiLink pythonConditional Conditional - HiLink pythonRepeat Repeat - HiLink pythonException Exception - HiLink pythonOperator Operator - - HiLink pythonComment Comment - HiLink pythonTodo Todo - - HiLink pythonError Error - - HiLink pythonString String - HiLink pythonUniString String - HiLink pythonRawString String - HiLink pythonUniRawString String - - HiLink pythonEscape Special - HiLink pythonEscapeError Error - HiLink pythonUniEscape Special - HiLink pythonUniEscapeError Error - HiLink pythonUniRawEscape Special - HiLink pythonUniRawEscapeError Error - - if exists("python_highlight_string_formatting") - HiLink pythonStrFormat Special - endif - - HiLink pythonNumber Number - HiLink pythonFloat Float - HiLink pythonOctalError Error - - if exists("python_highlight_builtins") - HiLink pythonBuiltinObj Structure - HiLink pythonBuiltinFunc Function - endif - - if exists("python_highlight_exceptions") - HiLink pythonExClass Structure - endif - - delcommand HiLink -endif - -let b:current_syntax = "python" diff --git a/syntax.txt b/syntax.txt deleted file mode 100644 index 294b11a..0000000 --- a/syntax.txt +++ /dev/null @@ -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: diff --git a/syntax/python.vim b/syntax/python.vim index e963628..3d23f88 100644 --- a/syntax/python.vim +++ b/syntax/python.vim @@ -1,100 +1,8 @@ -" Vim syntax file -" Language: Python -" Current Maintainer: Dmitry Vasiliev -" Previous Maintainer: Neil Schemenauer -" URL: https://github.com/hdima/python-syntax -" Last Change: 2015-11-01 -" Filenames: *.py -" Version: 3.6.0 -" -" Based on python.vim (from Vim 6.1 distribution) -" by Neil Schemenauer -" -" 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 -" `__ -" -" Contributors -" ============ -" -" List of the contributors in alphabetical order: -" -" 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 -" -" Options -" ======= -" -" :let OPTION_NAME = 1 Enable option -" :let OPTION_NAME = 0 Disable option -" -" -" Option to select Python version -" ------------------------------- -" -" 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. -" -" 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 -" - " 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 +if v:version < 600 syntax clear -elseif exists("b:current_syntax") +elseif exists('b:current_syntax') finish endif @@ -118,115 +26,123 @@ endfunction " Is it Python 2 syntax? function! s:Python2Syntax() - if exists("b:python_version_2") + if exists('b:python_version_2') return b:python_version_2 endif - return s:Enabled("g:python_version_2") + return s:Enabled('g:python_version_2') endfunction " " Default options " -call s:EnableByDefault("g:python_slow_sync") +call s:EnableByDefault('g:python_slow_sync') +call s:EnableByDefault('g:python_highlight_builtin_funcs_kwarg') -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 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') 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") + 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') + call s:EnableByDefault('g:python_highlight_class_vars') + call s:EnableByDefault('g:python_highlight_operators') 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 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 +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 " 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 pythonRaiseFromStatement '\' +syn match pythonImport '\v(^|;)\s*\zsfrom>' -syn match pythonStatement "\" display -syn match pythonImport "\" display if s:Python2Syntax() - if !s:Enabled("g:python_print_as_function") + if !s:Enabled('g:python_print_as_function') syn keyword pythonStatement print endif + syn keyword pythonStatement exec syn keyword pythonImport as - syn match pythonFunction "[a-zA-Z_][a-zA-Z0-9_]*" display contained + syn match pythonFunction '[a-zA-Z_][a-zA-Z0-9_]*' display contained else - syn keyword pythonStatement as nonlocal None - syn match pythonStatement "\" 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 "\" nextgroup=pythonFunction skipwhite - syn match pythonStatement "\" display - syn match pythonStatement "\" display + syn keyword pythonStatement as nonlocal + 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 '\' + syn match pythonStatement '\' + syn cluster pythonExpression contains=pythonStatement,pythonRepeat,pythonConditional,pythonOperator,pythonNumber,pythonHexNumber,pythonOctNumber,pythonBinNumber,pythonFloat,pythonString,pythonBytes,pythonBoolean,pythonBuiltinObj,pythonBuiltinFunc endif + +" +" Operators +" +syn keyword pythonOperator and in is not or +if s:Enabled('g:python_highlight_operators') + syn match pythonOperator '\V=\|-\|+\|*\|@\|/\|%\|&\||\|^\|~\|<\|>\|!=' +endif +syn match pythonError '[$?]\|\([-+@%&|^~]\)\1\{1,}\|\([=*/<>]\)\2\{2,}\|\([+@/%&|^~<>]\)\3\@![-+*@/%&|^~<>]\|\*\*[*@/%&|^<>]\|=[*@/%&|^<>]\|-[+*@/%&|^~<]\|[]\+=\{2,}\|!\{2,}=\+' display + " " Decorators (new in Python 2.4) " -syn match pythonDecorator "@" display nextgroup=pythonDottedName skipwhite +syn match pythonDecorator '^\s*\zs@\ze\h' display nextgroup=pythonDottedName skipwhite if s:Python2Syntax() - syn match pythonDottedName "[a-zA-Z_][a-zA-Z0-9_]*\%(\.[a-zA-Z_][a-zA-Z0-9_]*\)*" display contained + syn match pythonDottedName '[a-zA-Z_][a-zA-Z0-9_]*\%(\.[a-zA-Z_][a-zA-Z0-9_]*\)*' display contained else - syn match pythonDottedName "\%([^[:cntrl:][:space:][:punct:][:digit:]]\|_\)\%([^[:cntrl:][:punct:][:space:]]\|_\)*\%(\.\%([^[:cntrl:][:space:][:punct:][:digit:]]\|_\)\%([^[:cntrl:][:punct:][:space:]]\|_\)*\)*" display contained + syn match pythonDottedName '\%([^[:cntrl:][:space:][:punct:][:digit:]]\|_\)\%([^[:cntrl:][:punct:][:space:]]\|_\)*\%(\.\%([^[:cntrl:][:space:][:punct:][:digit:]]\|_\)\%([^[:cntrl:][:punct:][:space:]]\|_\)*\)*' display contained endif -syn match pythonDot "\." display containedin=pythonDottedName +syn match pythonDot '\.' display containedin=pythonDottedName " " Comments " -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-_.]\+.*$" +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 +syn keyword pythonTodo TODO FIXME XXX contained " " Errors " -syn match pythonError "\<\d\+\D\+\>" display -syn match pythonError "[$?]" display -syn match pythonError "[&|]\{2,}" display -syn match pythonError "[=]\{3,}" display +syn match pythonError '\<\d\+[^0-9[:space:]]\+\>' 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 +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 +if s:Enabled('g:python_highlight_space_errors') + syn match pythonSpaceError '\s\+$' display endif " @@ -237,117 +153,130 @@ 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 + syn region pythonString start=+[bB]\="""+ skip=+\\"+ end=+"""+ keepend contains=pythonBytesEscape,pythonBytesEscapeError,pythonUniEscape,pythonUniEscapeError,pythonDocTest2,pythonSpaceError,@Spell + syn region pythonString start=+[bB]\='''+ skip=+\\'+ 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 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]'''+ skip=+\\'+ end=+'''+ keepend contains=pythonBytesError,pythonBytesContent,pythonDocTest,pythonSpaceError,@Spell + syn region pythonBytes start=+[bB]"""+ skip=+\\"+ end=+"""+ keepend contains=pythonBytesError,pythonBytesContent,pythonDocTest2,pythonSpaceError,@Spell - syn match pythonBytesError ".\+" display contained - syn match pythonBytesContent "[\u0000-\u00ff]\+" display contained contains=pythonBytesEscape,pythonBytesEscapeError + syn match pythonBytesError '.\+' display contained + syn match pythonBytesContent '[\u0000-\u00ff]\+' display contained contains=pythonBytesEscape,pythonBytesEscapeError 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 +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 + syn region pythonUniString start=+[uU]'''+ skip=+\\'+ end=+'''+ keepend contains=pythonBytesEscape,pythonBytesEscapeError,pythonUniEscape,pythonUniEscapeError,pythonDocTest,pythonSpaceError,@Spell + syn region pythonUniString start=+[uU]"""+ skip=+\\"+ end=+"""+ keepend contains=pythonBytesEscape,pythonBytesEscapeError,pythonUniEscape,pythonUniEscapeError,pythonDocTest2,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 + syn region pythonString start=+'''+ skip=+\\'+ end=+'''+ keepend contains=pythonBytesEscape,pythonBytesEscapeError,pythonUniEscape,pythonUniEscapeError,pythonDocTest,pythonSpaceError,@Spell + syn region pythonString start=+"""+ skip=+\\"+ end=+"""+ keepend contains=pythonBytesEscape,pythonBytesEscapeError,pythonUniEscape,pythonUniEscapeError,pythonDocTest2,pythonSpaceError,@Spell + + syn region pythonFString start=+[fF]'+ skip=+\\\\\|\\'\|\\$+ excludenl end=+'+ end=+$+ keepend contains=pythonBytesEscape,pythonBytesEscapeError,pythonUniEscape,pythonUniEscapeError,@Spell + syn region pythonFString start=+[fF]"+ skip=+\\\\\|\\"\|\\$+ excludenl end=+"+ end=+$+ keepend contains=pythonBytesEscape,pythonBytesEscapeError,pythonUniEscape,pythonUniEscapeError,@Spell + syn region pythonFString start=+[fF]'''+ skip=+\\'+ end=+'''+ keepend contains=pythonBytesEscape,pythonBytesEscapeError,pythonUniEscape,pythonUniEscapeError,pythonDocTest,pythonSpaceError,@Spell + syn region pythonFString start=+[fF]"""+ skip=+\\"+ end=+"""+ keepend contains=pythonBytesEscape,pythonBytesEscapeError,pythonUniEscape,pythonUniEscapeError,pythonDocTest2,pythonSpaceError,@Spell 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 region pythonUniRawString start=+[uU][rR]'''+ skip=+\\'+ end=+'''+ keepend contains=pythonUniRawEscape,pythonUniRawEscapeError,pythonDocTest,pythonSpaceError,@Spell + syn region pythonUniRawString start=+[uU][rR]"""+ skip=+\\"+ end=+"""+ keepend contains=pythonUniRawEscape,pythonUniRawEscapeError,pythonDocTest2,pythonSpaceError,@Spell - syn match pythonUniRawEscape "\([^\\]\(\\\\\)*\)\@<=\\u\x\{4}" display contained - syn match pythonUniRawEscapeError "\([^\\]\(\\\\\)*\)\@<=\\u\x\{,3}\X" display contained + syn match pythonUniRawEscape '\%([^\\]\%(\\\\\)*\)\@<=\\u\x\{4}' display contained + syn match pythonUniRawEscapeError '\%([^\\]\%(\\\\\)*\)\@<=\\u\x\{,3}\X' display contained 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 + syn region pythonRawString start=+[bB]\=[rR]'''+ skip=+\\'+ end=+'''+ keepend contains=pythonDocTest,pythonSpaceError,@Spell + syn region pythonRawString start=+[bB]\=[rR]"""+ skip=+\\"+ end=+"""+ keepend contains=pythonDocTest2,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 + syn region pythonRawString start=+[rR]'''+ skip=+\\'+ end=+'''+ keepend contains=pythonDocTest,pythonSpaceError,@Spell + syn region pythonRawString start=+[rR]"""+ skip=+\\"+ end=+"""+ keepend contains=pythonDocTest2,pythonSpaceError,@Spell + + syn region pythonRawFString start=+\%([fF][rR]\|[rR][fF]\)'+ skip=+\\\\\|\\'\|\\$+ excludenl end=+'+ end=+$+ keepend contains=pythonRawEscape,@Spell + syn region pythonRawFString start=+\%([fF][rR]\|[rR][fF]\)"+ skip=+\\\\\|\\"\|\\$+ excludenl end=+"+ end=+$+ keepend contains=pythonRawEscape,@Spell + syn region pythonRawFString start=+\%([fF][rR]\|[rR][fF]\)'''+ skip=+\\'+ end=+'''+ keepend contains=pythonDocTest,pythonSpaceError,@Spell + syn region pythonRawFString start=+\%([fF][rR]\|[rR][fF]\)"""+ skip=+\\"+ end=+"""+ keepend contains=pythonDocTest,pythonSpaceError,@Spell + + syn region pythonRawBytes start=+\%([bB][rR]\|[rR][bB]\)'+ skip=+\\\\\|\\'\|\\$+ excludenl end=+'+ end=+$+ keepend contains=pythonRawEscape,@Spell + syn region pythonRawBytes start=+\%([bB][rR]\|[rR][bB]\)"+ skip=+\\\\\|\\"\|\\$+ excludenl end=+"+ end=+$+ keepend contains=pythonRawEscape,@Spell + syn region pythonRawBytes start=+\%([bB][rR]\|[rR][bB]\)'''+ skip=+\\'+ end=+'''+ keepend contains=pythonDocTest,pythonSpaceError,@Spell + syn region pythonRawBytes start=+\%([bB][rR]\|[rR][bB]\)"""+ skip=+\\"+ end=+"""+ keepend contains=pythonDocTest2,pythonSpaceError,@Spell endif -syn match pythonRawEscape +\\['"]+ display transparent contained +syn match pythonRawEscape +\\['"]+ display contained -if s:Enabled("g:python_highlight_string_formatting") +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 + syn match pythonStrFormatting '%\%(([^)]\+)\)\=[-#0 +]*\d*\%(\.\d\+\)\=[diouxXeEfFgGcrs%]' contained containedin=pythonString,pythonUniString,pythonUniRawString,pythonRawString,pythonBytesContent,pythonRawBytes + syn match pythonStrFormatting '%[-#0 +]*\%(\*\|\d\+\)\=\%(\.\%(\*\|\d\+\)\)\=[diouxXeEfFgGcrs%]' contained containedin=pythonString,pythonUniString,pythonUniRawString,pythonRawString,pythonBytesContent,pythonRawBytes 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 match pythonStrFormatting '%\%(([^)]\+)\)\=[-#0 +]*\d*\%(\.\d\+\)\=[diouxXeEfFgGcrsa%]' contained containedin=pythonString,pythonRawString + syn match pythonStrFormatting '%[-#0 +]*\%(\*\|\d\+\)\=\%(\.\%(\*\|\d\+\)\)\=[diouxXeEfFgGcrsa%]' contained containedin=pythonString,pythonRawString + syn match pythonStrFormatting '%\%(([^)]\+)\)\=[-#0 +]*\d*\%(\.\d\+\)\=[diouxXeEfFgGcbsar%]' contained containedin=pythonBytesContent,pythonRawBytes + syn match pythonStrFormatting '%[-#0 +]*\%(\*\|\d\+\)\=\%(\.\%(\*\|\d\+\)\)\=[diouxXeEfFgGcbsar%]' contained containedin=pythonBytesContent,pythonRawBytes endif endif -if s:Enabled("g:python_highlight_string_format") +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 + 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 + syn match pythonStrFormat "{\%(\%([^[:cntrl:][:space:][:punct:][:digit:]]\|_\)\%([^[:cntrl:][:punct:][:space:]]\|_\)*\|\d\+\)\=\%(\.\%([^[:cntrl:][:space:][:punct:][:digit:]]\|_\)\%([^[:cntrl:][:punct:][:space:]]\|_\)*\|\[\%(\d\+\|[^!:\}]\+\)\]\)*\%(![rsa]\)\=\%(:\%({\%(\%([^[:cntrl:][:space:][:punct:][:digit:]]\|_\)\%([^[:cntrl:][:punct:][:space:]]\|_\)*\|\d\+\)}\|\%([^}]\=[<>=^]\)\=[ +-]\=#\=0\=\d*,\=\%(\.\d\+\)\=[bcdeEfFgGnosxX%]\=\)\=\)\=}" contained containedin=pythonString,pythonRawString + syn region pythonStrInterpRegion start="{"he=e+1,rs=e+1 end="\%(![rsa]\)\=\%(:\%({\%(\%([^[:cntrl:][:space:][:punct:][:digit:]]\|_\)\%([^[:cntrl:][:punct:][:space:]]\|_\)*\|\d\+\)}\|\%([^}]\=[<>=^]\)\=[ +-]\=#\=0\=\d*,\=\%(\.\d\+\)\=[bcdeEfFgGnosxX%]\=\)\=\)\=}"hs=s-1,re=s-1 extend contained containedin=pythonFString,pythonRawFString contains=pythonStrInterpRegion,@pythonExpression + syn match pythonStrFormat "{{\|}}" contained containedin=pythonString,pythonRawString,pythonFString,pythonRawFString endif endif -if s:Enabled("g:python_highlight_string_templates") +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 + 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 + 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 endif -if s:Enabled("g:python_highlight_doctests") +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 + syn region pythonDocTest start='^\s*>>>' skip=+\\'+ end=+'''+he=s-1 end='^\s*$' contained + syn region pythonDocTest2 start='^\s*>>>' skip=+\\"+ end=+"""+he=s-1 end='^\s*$' contained endif " @@ -355,140 +284,128 @@ endif " 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 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 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 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 - syn match pythonOctError "\<0[oO]\=\o*[8-9]\d*[lL]\=\>" display - syn match pythonBinError "\<0[bB][01]*[2-9]\d*[lL]\=\>" display + 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 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 + syn match pythonOctError '\<0[oO]\=\o*\D\+\d*\>' display + " pythonHexError comes after pythonOctError so that 0xffffl is pythonHexError + syn match pythonHexError '\<0[xX]\x*[g-zG-Z]\x*\>' display + syn match pythonBinError '\<0[bB][01]*\D\+\d*\>' display + + syn match pythonHexNumber '\<0[xX][_0-9a-fA-F]*\x\>' display + syn match pythonOctNumber '\<0[oO][_0-7]*\o\>' display + syn match pythonBinNumber '\<0[bB][_01]*[01]\>' display + + syn match pythonNumberError '\<\d[_0-9]*\D\>' display + syn match pythonNumberError '\<0[_0-9]\+\>' display + syn match pythonNumberError '\<0_x\S*\>' display + syn match pythonNumberError '\<0[bBxXoO][_0-9a-fA-F]*_\>' display + syn match pythonNumberError '\<\d[_0-9]*_\>' display + syn match pythonNumber '\<\d\>' display + syn match pythonNumber '\<[1-9][_0-9]*\d\>' display + syn match pythonNumber '\<\d[jJ]\>' display + syn match pythonNumber '\<[1-9][_0-9]*\d[jJ]\>' display + + syn match pythonOctError '\<0[oO]\=\o*[8-9]\d*\>' display + syn match pythonBinError '\<0[bB][01]*[2-9]\d*\>' display + + 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 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__ +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 pythonBuiltinObj __debug__ __doc__ __file__ __name__ __package__ + syn keyword pythonBuiltinObj __loader__ __spec__ __path__ __cached__ endif " " Builtin functions " -if s:Enabled("g:python_highlight_builtin_funcs") +if s:Enabled('g:python_highlight_builtin_funcs') + let s:funcs_re = '__import__|abs|all|any|bin|breakpoint|callable|chr|classmethod|compile|complex|delattr|dir|divmod|enumerate|eval|filter|format|getattr|globals|hasattr|hash|help|hex|id|input|isinstance|issubclass|iter|len|locals|map|max|memoryview|min|next|oct|open|ord|pow|property|range|repr|reversed|round|setattr|slice|sorted|staticmethod|sum|super|type|vars|zip' + 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 + let s:funcs_re .= '|apply|basestring|buffer|cmp|coerce|execfile|file|intern|long|raw_input|reduce|reload|unichr|unicode|xrange' + if s:Enabled('g:python_print_as_function') + let s:funcs_re .= '|print' endif else - syn keyword pythonBuiltinFunc ascii exec memoryview print + let s:funcs_re .= '|ascii|exec|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 + + " (Exclude if preceded by a dot, possibly on the line before, except if that + " dot is in a comment or Ellipsis. Would fail if the previous line contained + " '#' in a string, though. (Thus, directly check for the current line, too.) + " Exclude if immediately followed by an equal sign, as this would typically + " correspond to a keyword argument.) + let s:funcs_re = + \ 'syn match pythonBuiltinFunc ''\v(^[^#]*[^.#]\s*\.(\s|\n)*|\.\s*)@160' + + if !s:Enabled('g:python_highlight_builtin_funcs_kwarg') + let s:funcs_re .= '\=@!' + endif + + execute s:funcs_re . '''' + unlet s:funcs_re endif " " Builtin exceptions and warnings " -if s:Enabled("g:python_highlight_exceptions") +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|PendingDeprecationWarning|SyntaxWarning|RuntimeWarning|FutureWarning|ImportWarning|UnicodeWarning' + if s:Python2Syntax() - syn keyword pythonExClass StandardError + let s:exs_re .= '|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 + let s:exs_re .= '|BlockingIOError|ChildProcessError|ConnectionError|BrokenPipeError|ConnectionAbortedError|ConnectionRefusedError|ConnectionResetError|FileExistsError|FileNotFoundError|InterruptedError|IsADirectoryError|NotADirectoryError|PermissionError|ProcessLookupError|TimeoutError|StopAsyncIteration|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 + + execute 'syn match pythonExClass ''\v\.@''' + unlet s:exs_re endif -if s:Enabled("g:python_slow_sync") +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 match pythonSync grouphere NONE '):$' syn sync maxlines=200 endif -if version >= 508 || !exists("did_python_syn_inits") - if version <= 508 +if v:version >= 508 || !exists('did_python_syn_inits') + if v:version <= 508 let did_python_syn_inits = 1 command -nargs=+ HiLink hi link else @@ -496,6 +413,7 @@ if version >= 508 || !exists("did_python_syn_inits") endif HiLink pythonStatement Statement + HiLink pythonRaiseFromStatement Statement HiLink pythonImport Include HiLink pythonFunction Function HiLink pythonConditional Conditional @@ -508,7 +426,7 @@ if version >= 508 || !exists("did_python_syn_inits") HiLink pythonDot Normal HiLink pythonComment Comment - if !s:Enabled("g:python_highlight_file_headers_as_comments") + if !s:Enabled('g:python_highlight_file_headers_as_comments') HiLink pythonCoding Special HiLink pythonRun Special endif @@ -520,6 +438,7 @@ if version >= 508 || !exists("did_python_syn_inits") HiLink pythonString String HiLink pythonRawString String + HiLink pythonRawEscape Special HiLink pythonUniEscape Special HiLink pythonUniEscapeError Error @@ -536,6 +455,9 @@ if version >= 508 || !exists("did_python_syn_inits") HiLink pythonBytesError Error HiLink pythonBytesEscape Special HiLink pythonBytesEscapeError Error + HiLink pythonFString String + HiLink pythonRawFString String + HiLink pythonStrInterpRegion Special endif HiLink pythonStrFormatting Special @@ -556,13 +478,15 @@ if version >= 508 || !exists("did_python_syn_inits") HiLink pythonBinError Error HiLink pythonBoolean Boolean + HiLink pythonNone Constant HiLink pythonBuiltinObj Structure HiLink pythonBuiltinFunc Function HiLink pythonExClass Structure + HiLink pythonClassVar Identifier delcommand HiLink endif -let b:current_syntax = "python" +let b:current_syntax = 'python' diff --git a/test.py b/test.py deleted file mode 100644 index df81a9a..0000000 --- a/test.py +++ /dev/null @@ -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 -""" diff --git a/tests/test.py b/tests/test.py new file mode 100644 index 0000000..08d5a69 --- /dev/null +++ b/tests/test.py @@ -0,0 +1,277 @@ +#! /usr/bin/env python +# -*- coding: utf-8 -*- +# Above the run-comment and file encoding comment. + +# Comments. + +# TODO FIXME XXX + +# 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 + +raise Exception from ex + +yield from + +def functionname +class Classname +def функция +class Класс + +# Keywords: Python 2 + +exec +print + +# Keywords: Python 3 + +await +async def Test +async with +async for + +# Builtin objects. + +True False Ellipsis None NotImplemented + +# Bultin types + +bool bytearray dict float frozenset int list object set str tuple + +# Builtin functions + +__import__() +abs() +all() +any() +bin() +bool() +bytearray() +callable() +chr() +classmethod() +compile() +complex() +delattr() +dict() +dir() +divmod() +enumerate() +eval() +filter() +float() +format() +frozenset() +getattr() +globals() +hasattr() +hash() +help() +hex() +id() +input() +int() +isinstance() +issubclass() +iter() +len() +list() +locals() +map() +max() +memoryview() +min() +next() +object() +oct() +open() +ord() +pow() +property() +range() +repr() +reversed() +round() +set() +setattr() +slice() +sorted() +staticmethod() +str() +sum() +super() +tuple() +type() +vars() +zip() + +# Builtin functions: Python 2 + +apply() +basestring() +buffer() +cmp() +coerce() +execfile() +file() +intern() +long() +raw_input() +reduce() +reload() +unichr() +unicode() +xrange() + +print() + +# Builtin functions: Python 3 + +ascii() +bytes() +exec() +print() + +# 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 + +# Operators + +and or in is not + +- + * ** **- **+ **~ @ / // % +& | ^ ~ << >> +< <= == != >= > + += =- =+ =~ +-= += *= **= @= /= //= %= +&= |= ^= ~= <<= >>= + +-> + +# Erroneous operators + +$ ? +=== +-- ++ *** @@ /// %% +&& || ^^ ~~ <<< >>> +<== !== !!= >== +%- +- -+ + +# Numbers + +0 1 2 9 10 0x1f .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 + +077 100L 0xfffffffL 0L 08 0xk 0x 0b102 0o78 0o123LaB +0_ 0_1 0_x1f 0x1f_ 0_b77 0b77_ .2_ 1_j + +# Strings + +" test " ' test ' +"test\ +test" +'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" + +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 }}}}' +fr'this {that}' + +# Doctests. + +""" + Test: + >>> a = 5 + >>> a + 5 + + Test +""" + +''' + Test: + >>> a = 5 + >>> a + 5 + + Test +''' + +# Erroneous variable names + +6xav + + +# Indentation errors. + + break + +# Trailing space errors. + + + break +""" + + test +"""