Unnamed repository; edit this file 'description' to name the repository.
Diffstat (limited to 'runtime/queries/python/highlights.scm')
-rw-r--r--runtime/queries/python/highlights.scm382
1 files changed, 148 insertions, 234 deletions
diff --git a/runtime/queries/python/highlights.scm b/runtime/queries/python/highlights.scm
index ad45d495..70b91efb 100644
--- a/runtime/queries/python/highlights.scm
+++ b/runtime/queries/python/highlights.scm
@@ -1,16 +1,125 @@
-; -------
-; Punctuation
-; -------
+; Imports
+
+(dotted_name
+ (identifier)* @namespace)
+
+(aliased_import
+ alias: (identifier) @namespace)
+
+; Builtin functions
+
+((call
+ function: (identifier) @function.builtin)
+ (#match?
+ @function.builtin
+ "^(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__)$"))
+
+; Function calls
+
+[
+ "def"
+ "lambda"
+] @keyword.function
+
+(call
+ function: (attribute attribute: (identifier) @constructor)
+ (#match? @constructor "^[A-Z]"))
+(call
+ function: (identifier) @constructor
+ (#match? @constructor "^[A-Z]"))
+
+(call
+ function: (attribute attribute: (identifier) @function.method))
+
+(call
+ function: (identifier) @function)
+
+; Function definitions
+
+(function_definition
+ name: (identifier) @constructor
+ (#match? @constructor "^(__new__|__init__)$"))
+
+(function_definition
+ name: (identifier) @function)
+
+; Decorators
+
+(decorator) @function
+(decorator (identifier) @function)
+(decorator (attribute attribute: (identifier) @function))
+(decorator (call
+ function: (attribute attribute: (identifier) @function)))
+
+; Parameters
+
+((identifier) @variable.builtin
+ (#match? @variable.builtin "^(self|cls)$"))
+
+(parameters (identifier) @variable.parameter)
+(parameters (typed_parameter (identifier) @variable.parameter))
+(parameters (default_parameter name: (identifier) @variable.parameter))
+(parameters (typed_default_parameter name: (identifier) @variable.parameter))
+
+(parameters
+ (list_splat_pattern ; *args
+ (identifier) @variable.parameter))
+(parameters
+ (dictionary_splat_pattern ; **kwargs
+ (identifier) @variable.parameter))
+
+(lambda_parameters
+ (identifier) @variable.parameter)
+
+; 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
+ (#match? @constant "^[A-Z_]{2,}$"))
+
+((identifier) @type
+ (#match? @type "^[A-Z]"))
+
+(attribute attribute: (identifier) @variable.other.member)
+(identifier) @variable
+
+; Literals
+(none) @constant.builtin
+[
+ (true)
+ (false)
+] @constant.builtin.boolean
+
+(integer) @constant.numeric.integer
+(float) @constant.numeric.float
+(comment) @comment
+(string) @string
+(escape_sequence) @constant.character.escape
["," "." ":" ";" (ellipsis)] @punctuation.delimiter
-["(" ")" "[" "]" "{" "}"] @punctuation.bracket
(interpolation
"{" @punctuation.special
- "}" @punctuation.special)
-
-; -------
-; Operators
-; -------
+ "}" @punctuation.special) @embedded
+["(" ")" "[" "]" "{" "}"] @punctuation.bracket
[
"-"
@@ -25,17 +134,14 @@
"//="
"/="
"&"
- "&="
"%"
"%="
"^"
- "^="
"+"
"->"
"+="
"<"
"<<"
- "<<="
"<="
"<>"
"="
@@ -44,71 +150,10 @@
">"
">="
">>"
- ">>="
"|"
- "|="
"~"
- "@="
] @operator
-; -------
-; Variables
-; -------
-
-(identifier) @variable
-
-; - Member
-(attribute attribute: (identifier) @variable.other.member)
-
-; - Parameter
-(parameters (identifier) @variable.parameter)
-(parameters (typed_parameter (identifier) @variable.parameter))
-(parameters (default_parameter name: (identifier) @variable.parameter))
-(parameters (typed_default_parameter name: (identifier) @variable.parameter))
-(parameters
- (list_splat_pattern ; *args
- (identifier) @variable.parameter))
-(parameters
- (dictionary_splat_pattern ; **kwargs
- (identifier) @variable.parameter))
-
-(lambda_parameters
- (identifier) @variable.parameter)
-
-(keyword_argument
- name: (identifier) @variable.parameter)
-
-; - Builtin
-((identifier) @variable.builtin
- (#any-of? @variable.builtin "self" "cls"))
-
-; -------
-; Keywords
-; -------
-
-[
- "async"
- "class"
- "exec"
- "global"
- "nonlocal"
- "print"
- "type"
-] @keyword
-
-; Operators
-[
- "and"
- "or"
- "not in"
- "in" ; Has to be before loop keywords because "in" is overloaded
- "not"
- "del"
- "is not"
- "is"
-] @keyword.operator
-
-; Control
[
"as"
"assert"
@@ -119,7 +164,6 @@
"with"
] @keyword.control
-; Conditionals
[
"if"
"elif"
@@ -128,25 +172,6 @@
"case"
] @keyword.control.conditional
-; Exceptions
-[
- "raise"
- "try"
- "except"
- "finally"
-] @keyword.control.exception
-(raise_statement "from" @keyword.control.exception)
-
-; Functions
-[
- "def"
- "lambda"
-] @keyword.function
-
-; Import
-"import" @keyword.control.import
-
-; Loops
[
"while"
"for"
@@ -154,155 +179,44 @@
"continue"
] @keyword.control.repeat
-(for_statement "in" @keyword.control.repeat)
-(for_in_clause "in" @keyword.control.repeat)
-
-; Return
[
"return"
"yield"
] @keyword.control.return
(yield "from" @keyword.control.return)
-; -------
-; Imports
-; -------
-
-(dotted_name
- (identifier)* @namespace)
-
-(aliased_import
- alias: (identifier) @namespace)
-
-; - Builtins
-(none) @constant.builtin ; Has to be before types
-
-; -------
-; Types
-; -------
-
-((identifier) @type
- (#match? @type "^[A-Z]")) ; Has to be before constructor due to this being a more general match
-
-; 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)))))
-
-; Classes
-(class_definition name: (identifier) @type)
-(class_definition superclasses: (argument_list (identifier) @type))
-
-; -------
-; Functions
-; -------
-
-(function_definition
- name: (identifier) @function)
-
-(call
- function: (identifier) @function)
-
-; Decorators
-(decorator) @function
-(decorator (identifier) @function)
-(decorator (attribute attribute: (identifier) @function))
-(decorator (call
- function: (attribute attribute: (identifier) @function)))
-
-; Methods
-(call
- function: (attribute attribute: (identifier) @function.method))
-
-; Builtin functions
-((call
- function: (identifier) @function.builtin)
- (#any-of?
- @function.builtin
- "abs" "all" "any" "ascii" "bin" "breakpoint" "bytearray" "callable" "chr"
- "classmethod" "compile" "complex" "delattr" "dir" "divmod" "enumerate"
- "eval" "exec" "filter" "format" "getattr" "globals" "hasattr" "hash" "help"
- "hex" "id" "input" "isinstance" "issubclass" "iter" "len" "locals" "map"
- "max" "memoryview" "min" "next" "object" "oct" "open" "ord" "pow" "print"
- "property" "range" "repr" "reversed" "round" "setattr" "slice" "sorted"
- "staticmethod" "sum" "super" "type" "vars" "zip" "__import__"))
-
-; Constructors
-(call
- function: (attribute attribute: (identifier) @constructor)
- (#any-of?
- @constructor
- "__new__" "__init__"))
-
-((call
- function: (identifier) @constructor)
- (#any-of?
- @constructor
- "__new__" "__init__"))
-
-(function_definition
- name: (identifier) @constructor
- (#any-of? @constructor "__new__" "__init__"))
-
-(call
- function: (attribute attribute: (identifier) @constructor)
- (#match? @constructor "^[A-Z]"))
-(call
- function: (identifier) @constructor
- (#match? @constructor "^[A-Z]"))
-
-; Builtin types
-((identifier) @type.builtin ; Has to be after functions due to broad matching
- (#any-of?
- @type.builtin
- "bool" "bytes" "dict" "float" "frozenset" "int" "list" "set" "str" "tuple"))
-
-; Builtin error types
-((identifier) @type.builtin ; Has to be after constructors due to broad matching of constructor
- (#any-of? @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"))
-
-; -------
-; Constants
-; -------
-
-((identifier) @constant
- (#match? @constant "^_*[A-Z][A-Z\\d_]*$"))
+[
+ "raise"
+ "try"
+ "except"
+ "finally"
+] @keyword.control.except
+(raise_statement "from" @keyword.control.except)
+"import" @keyword.control.import
-(escape_sequence) @constant.character.escape
+(for_statement "in" @keyword.control)
+(for_in_clause "in" @keyword.control)
[
- (true)
- (false)
-] @constant.builtin.boolean
-
+ "and"
+ "async"
+ "class"
+ "exec"
+ "global"
+ "nonlocal"
+ "print"
+] @keyword
+[
+ "and"
+ "or"
+ "in"
+ "not"
+ "del"
+ "is"
+] @keyword.operator
-; - Numbers
-(integer) @constant.numeric.integer
-(float) @constant.numeric.float
+((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)$"))
-; -------
-; Other literals
-; -------
-
-(comment) @comment
-(string) @string
+(ERROR) @error