2022-08-02 01:14:07 +04:00
|
|
|
; Imports
|
|
|
|
|
2022-07-26 05:17:51 +04:00
|
|
|
(dotted_name
|
|
|
|
(identifier)* @namespace)
|
2022-11-01 21:01:01 +04:00
|
|
|
|
2022-08-02 01:14:07 +04:00
|
|
|
(aliased_import
|
|
|
|
alias: (identifier) @namespace)
|
2022-07-26 05:17:51 +04:00
|
|
|
|
2021-04-09 12:42:49 +04:00
|
|
|
; Builtin functions
|
|
|
|
|
|
|
|
((call
|
|
|
|
function: (identifier) @function.builtin)
|
|
|
|
(#match?
|
|
|
|
@function.builtin
|
2022-05-13 10:21:38 +04:00
|
|
|
"^(abs|all|any|ascii|bin|bool|breakpoint|bytearray|bytes|callable|chr|classmethod|compile|complex|delattr|dict|dir|divmod|enumerate|eval|exec|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|print|property|range|repr|reversed|round|set|setattr|slice|sorted|staticmethod|str|sum|super|tuple|type|vars|zip|__import__)$"))
|
2021-04-09 12:42:49 +04:00
|
|
|
|
|
|
|
; Function calls
|
|
|
|
|
2022-07-26 05:17:51 +04:00
|
|
|
[
|
|
|
|
"def"
|
|
|
|
"lambda"
|
|
|
|
] @keyword.function
|
|
|
|
|
2022-05-13 10:21:38 +04:00
|
|
|
(call
|
|
|
|
function: (attribute attribute: (identifier) @constructor)
|
|
|
|
(#match? @constructor "^[A-Z]"))
|
|
|
|
(call
|
|
|
|
function: (identifier) @constructor
|
|
|
|
(#match? @constructor "^[A-Z]"))
|
2021-04-09 12:42:49 +04:00
|
|
|
|
|
|
|
(call
|
|
|
|
function: (attribute attribute: (identifier) @function.method))
|
2022-05-13 10:21:38 +04:00
|
|
|
|
2021-04-09 12:42:49 +04:00
|
|
|
(call
|
|
|
|
function: (identifier) @function)
|
|
|
|
|
|
|
|
; Function definitions
|
|
|
|
|
2022-05-13 10:21:38 +04:00
|
|
|
(function_definition
|
|
|
|
name: (identifier) @constructor
|
|
|
|
(#match? @constructor "^(__new__|__init__)$"))
|
|
|
|
|
2021-04-09 12:42:49 +04:00
|
|
|
(function_definition
|
|
|
|
name: (identifier) @function)
|
|
|
|
|
2022-05-13 10:21:38 +04:00
|
|
|
; Decorators
|
|
|
|
|
|
|
|
(decorator) @function
|
|
|
|
(decorator (identifier) @function)
|
2022-05-14 18:03:53 +04:00
|
|
|
(decorator (attribute attribute: (identifier) @function))
|
|
|
|
(decorator (call
|
|
|
|
function: (attribute attribute: (identifier) @function)))
|
2022-05-13 10:21:38 +04:00
|
|
|
|
|
|
|
; Parameters
|
|
|
|
|
|
|
|
((identifier) @variable.builtin
|
|
|
|
(#match? @variable.builtin "^(self|cls)$"))
|
|
|
|
|
|
|
|
(parameters (identifier) @variable.parameter)
|
|
|
|
(parameters (typed_parameter (identifier) @variable.parameter))
|
2022-05-14 06:39:36 +04:00
|
|
|
(parameters (default_parameter name: (identifier) @variable.parameter))
|
|
|
|
(parameters (typed_default_parameter name: (identifier) @variable.parameter))
|
2022-05-13 10:21:38 +04:00
|
|
|
|
2022-07-26 05:17:51 +04:00
|
|
|
(parameters
|
|
|
|
(list_splat_pattern ; *args
|
|
|
|
(identifier) @variable.parameter))
|
|
|
|
(parameters
|
|
|
|
(dictionary_splat_pattern ; **kwargs
|
|
|
|
(identifier) @variable.parameter))
|
2022-11-01 21:01:01 +04:00
|
|
|
|
2022-08-02 01:14:07 +04:00
|
|
|
(lambda_parameters
|
|
|
|
(identifier) @variable.parameter)
|
2022-07-26 05:17:51 +04:00
|
|
|
|
2022-05-13 10:21:38 +04:00
|
|
|
; Types
|
|
|
|
|
|
|
|
((identifier) @type.builtin
|
|
|
|
(#match?
|
|
|
|
@type.builtin
|
|
|
|
"^(bool|bytes|dict|float|frozenset|int|list|set|str|tuple)$"))
|
|
|
|
|
|
|
|
; In type hints make everything types to catch non-conforming identifiers
|
|
|
|
; (e.g., datetime.datetime) and None
|
|
|
|
(type [(identifier) (none)] @type)
|
|
|
|
; Handle [] . and | nesting 4 levels deep
|
|
|
|
(type
|
|
|
|
(_ [(identifier) (none)]? @type
|
|
|
|
(_ [(identifier) (none)]? @type
|
|
|
|
(_ [(identifier) (none)]? @type
|
|
|
|
(_ [(identifier) (none)]? @type)))))
|
|
|
|
|
|
|
|
(class_definition name: (identifier) @type)
|
|
|
|
(class_definition superclasses: (argument_list (identifier) @type))
|
|
|
|
|
|
|
|
; Variables
|
|
|
|
|
|
|
|
((identifier) @constant
|
2023-04-14 04:34:40 +04:00
|
|
|
(#match? @constant "^_*[A-Z][A-Z\\d_]*$"))
|
2022-05-13 10:21:38 +04:00
|
|
|
|
|
|
|
((identifier) @type
|
2022-11-01 21:01:01 +04:00
|
|
|
(#match? @type "^[A-Z]"))
|
2022-05-13 10:21:38 +04:00
|
|
|
|
2021-11-03 07:00:52 +04:00
|
|
|
(attribute attribute: (identifier) @variable.other.member)
|
2022-05-13 10:21:38 +04:00
|
|
|
(identifier) @variable
|
2021-04-09 12:42:49 +04:00
|
|
|
|
|
|
|
; Literals
|
2022-07-26 05:17:51 +04:00
|
|
|
(none) @constant.builtin
|
2021-04-09 12:42:49 +04:00
|
|
|
[
|
|
|
|
(true)
|
|
|
|
(false)
|
2022-07-26 05:17:51 +04:00
|
|
|
] @constant.builtin.boolean
|
2021-04-09 12:42:49 +04:00
|
|
|
|
2021-11-03 07:00:52 +04:00
|
|
|
(integer) @constant.numeric.integer
|
|
|
|
(float) @constant.numeric.float
|
2021-04-09 12:42:49 +04:00
|
|
|
(comment) @comment
|
|
|
|
(string) @string
|
2021-11-03 07:00:52 +04:00
|
|
|
(escape_sequence) @constant.character.escape
|
2021-04-09 12:42:49 +04:00
|
|
|
|
2022-07-26 05:17:51 +04:00
|
|
|
["," "." ":" ";" (ellipsis)] @punctuation.delimiter
|
2021-04-09 12:42:49 +04:00
|
|
|
(interpolation
|
|
|
|
"{" @punctuation.special
|
|
|
|
"}" @punctuation.special) @embedded
|
2022-07-26 17:31:14 +04:00
|
|
|
["(" ")" "[" "]" "{" "}"] @punctuation.bracket
|
2021-04-09 12:42:49 +04:00
|
|
|
|
|
|
|
[
|
|
|
|
"-"
|
|
|
|
"-="
|
|
|
|
"!="
|
|
|
|
"*"
|
|
|
|
"**"
|
|
|
|
"**="
|
|
|
|
"*="
|
|
|
|
"/"
|
|
|
|
"//"
|
|
|
|
"//="
|
|
|
|
"/="
|
|
|
|
"&"
|
2023-12-04 12:26:11 +04:00
|
|
|
"&="
|
2021-04-09 12:42:49 +04:00
|
|
|
"%"
|
|
|
|
"%="
|
|
|
|
"^"
|
2023-12-04 12:26:11 +04:00
|
|
|
"^="
|
2021-04-09 12:42:49 +04:00
|
|
|
"+"
|
|
|
|
"->"
|
|
|
|
"+="
|
|
|
|
"<"
|
|
|
|
"<<"
|
2023-12-04 12:26:11 +04:00
|
|
|
"<<="
|
2021-04-09 12:42:49 +04:00
|
|
|
"<="
|
|
|
|
"<>"
|
|
|
|
"="
|
|
|
|
":="
|
|
|
|
"=="
|
|
|
|
">"
|
|
|
|
">="
|
|
|
|
">>"
|
2023-12-04 12:26:11 +04:00
|
|
|
">>="
|
2021-04-09 12:42:49 +04:00
|
|
|
"|"
|
2023-12-04 12:26:11 +04:00
|
|
|
"|="
|
2021-04-09 12:42:49 +04:00
|
|
|
"~"
|
2023-12-04 12:26:11 +04:00
|
|
|
"@="
|
2021-04-09 12:42:49 +04:00
|
|
|
] @operator
|
|
|
|
|
|
|
|
[
|
|
|
|
"as"
|
|
|
|
"assert"
|
|
|
|
"await"
|
2022-07-26 05:17:51 +04:00
|
|
|
"from"
|
|
|
|
"pass"
|
|
|
|
|
|
|
|
"with"
|
|
|
|
] @keyword.control
|
|
|
|
|
|
|
|
[
|
|
|
|
"if"
|
2021-04-09 12:42:49 +04:00
|
|
|
"elif"
|
|
|
|
"else"
|
2022-11-01 21:01:01 +04:00
|
|
|
"match"
|
|
|
|
"case"
|
2022-07-26 05:17:51 +04:00
|
|
|
] @keyword.control.conditional
|
|
|
|
|
|
|
|
[
|
|
|
|
"while"
|
2021-04-09 12:42:49 +04:00
|
|
|
"for"
|
2022-07-26 05:17:51 +04:00
|
|
|
"break"
|
|
|
|
"continue"
|
|
|
|
] @keyword.control.repeat
|
|
|
|
|
|
|
|
[
|
2021-04-09 12:42:49 +04:00
|
|
|
"return"
|
|
|
|
"yield"
|
2022-07-26 05:17:51 +04:00
|
|
|
] @keyword.control.return
|
|
|
|
(yield "from" @keyword.control.return)
|
|
|
|
|
|
|
|
[
|
|
|
|
"raise"
|
|
|
|
"try"
|
|
|
|
"except"
|
|
|
|
"finally"
|
|
|
|
] @keyword.control.except
|
|
|
|
(raise_statement "from" @keyword.control.except)
|
|
|
|
"import" @keyword.control.import
|
2022-05-10 07:50:00 +04:00
|
|
|
|
|
|
|
(for_statement "in" @keyword.control)
|
|
|
|
(for_in_clause "in" @keyword.control)
|
|
|
|
|
|
|
|
[
|
|
|
|
"async"
|
|
|
|
"class"
|
|
|
|
"exec"
|
|
|
|
"global"
|
|
|
|
"nonlocal"
|
|
|
|
"print"
|
2024-04-05 04:22:41 +04:00
|
|
|
"type"
|
2021-04-09 12:42:49 +04:00
|
|
|
] @keyword
|
2022-07-26 05:17:51 +04:00
|
|
|
[
|
|
|
|
"and"
|
|
|
|
"or"
|
2024-05-03 14:39:02 +04:00
|
|
|
"not in"
|
2022-07-26 05:17:51 +04:00
|
|
|
"in"
|
|
|
|
"not"
|
|
|
|
"del"
|
2024-05-03 14:39:02 +04:00
|
|
|
"is not"
|
2022-07-26 05:17:51 +04:00
|
|
|
"is"
|
|
|
|
] @keyword.operator
|
|
|
|
|
|
|
|
((identifier) @type.builtin
|
|
|
|
(#match? @type.builtin
|
|
|
|
"^(BaseException|Exception|ArithmeticError|BufferError|LookupError|AssertionError|AttributeError|EOFError|FloatingPointError|GeneratorExit|ImportError|ModuleNotFoundError|IndexError|KeyError|KeyboardInterrupt|MemoryError|NameError|NotImplementedError|OSError|OverflowError|RecursionError|ReferenceError|RuntimeError|StopIteration|StopAsyncIteration|SyntaxError|IndentationError|TabError|SystemError|SystemExit|TypeError|UnboundLocalError|UnicodeError|UnicodeEncodeError|UnicodeDecodeError|UnicodeTranslateError|ValueError|ZeroDivisionError|EnvironmentError|IOError|WindowsError|BlockingIOError|ChildProcessError|ConnectionError|BrokenPipeError|ConnectionAbortedError|ConnectionRefusedError|ConnectionResetError|FileExistsError|FileNotFoundError|InterruptedError|IsADirectoryError|NotADirectoryError|PermissionError|ProcessLookupError|TimeoutError|Warning|UserWarning|DeprecationWarning|PendingDeprecationWarning|SyntaxWarning|RuntimeWarning|FutureWarning|ImportWarning|UnicodeWarning|BytesWarning|ResourceWarning)$"))
|
2022-05-10 07:50:00 +04:00
|
|
|
|
2022-07-26 05:17:51 +04:00
|
|
|
(ERROR) @error
|