mirror of
https://github.com/nvim-treesitter/nvim-treesitter.git
synced 2026-07-02 03:26:52 -04:00
feat!: drop modules, general refactor and cleanup
This commit is contained in:
parent
c13e28f894
commit
2c8f2f2fad
829 changed files with 4905 additions and 8010 deletions
28
runtime/queries/python/folds.scm
Normal file
28
runtime/queries/python/folds.scm
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
[
|
||||
(function_definition)
|
||||
(class_definition)
|
||||
|
||||
(while_statement)
|
||||
(for_statement)
|
||||
(if_statement)
|
||||
(with_statement)
|
||||
(try_statement)
|
||||
(match_statement)
|
||||
|
||||
(import_from_statement)
|
||||
(parameters)
|
||||
(argument_list)
|
||||
|
||||
(parenthesized_expression)
|
||||
(generator_expression)
|
||||
(list_comprehension)
|
||||
(set_comprehension)
|
||||
(dictionary_comprehension)
|
||||
|
||||
(tuple)
|
||||
(list)
|
||||
(set)
|
||||
(dictionary)
|
||||
|
||||
(string)
|
||||
] @fold
|
||||
351
runtime/queries/python/highlights.scm
Normal file
351
runtime/queries/python/highlights.scm
Normal file
|
|
@ -0,0 +1,351 @@
|
|||
;; From tree-sitter-python licensed under MIT License
|
||||
; Copyright (c) 2016 Max Brunsfeld
|
||||
|
||||
; Variables
|
||||
(identifier) @variable
|
||||
|
||||
; Reset highlighting in f-string interpolations
|
||||
(interpolation) @none
|
||||
|
||||
;; Identifier naming conventions
|
||||
((identifier) @type
|
||||
(#lua-match? @type "^[A-Z].*[a-z]"))
|
||||
((identifier) @constant
|
||||
(#lua-match? @constant "^[A-Z][A-Z_0-9]*$"))
|
||||
|
||||
((identifier) @constant.builtin
|
||||
(#lua-match? @constant.builtin "^__[a-zA-Z0-9_]*__$"))
|
||||
|
||||
((identifier) @constant.builtin
|
||||
(#any-of? @constant.builtin
|
||||
;; https://docs.python.org/3/library/constants.html
|
||||
"NotImplemented"
|
||||
"Ellipsis"
|
||||
"quit"
|
||||
"exit"
|
||||
"copyright"
|
||||
"credits"
|
||||
"license"))
|
||||
|
||||
"_" @constant.builtin ; match wildcard
|
||||
|
||||
((attribute
|
||||
attribute: (identifier) @field)
|
||||
(#lua-match? @field "^[%l_].*$"))
|
||||
|
||||
((assignment
|
||||
left: (identifier) @type.definition
|
||||
(type (identifier) @_annotation))
|
||||
(#eq? @_annotation "TypeAlias"))
|
||||
|
||||
((assignment
|
||||
left: (identifier) @type.definition
|
||||
right: (call
|
||||
function: (identifier) @_func))
|
||||
(#any-of? @_func "TypeVar" "NewType"))
|
||||
|
||||
; Function calls
|
||||
|
||||
(call
|
||||
function: (identifier) @function.call)
|
||||
|
||||
(call
|
||||
function: (attribute
|
||||
attribute: (identifier) @method.call))
|
||||
|
||||
((call
|
||||
function: (identifier) @constructor)
|
||||
(#lua-match? @constructor "^%u"))
|
||||
|
||||
((call
|
||||
function: (attribute
|
||||
attribute: (identifier) @constructor))
|
||||
(#lua-match? @constructor "^%u"))
|
||||
|
||||
;; Decorators
|
||||
|
||||
((decorator "@" @attribute)
|
||||
(#set! "priority" 101))
|
||||
|
||||
(decorator
|
||||
(identifier) @attribute)
|
||||
(decorator
|
||||
(attribute
|
||||
attribute: (identifier) @attribute))
|
||||
(decorator
|
||||
(call (identifier) @attribute))
|
||||
(decorator
|
||||
(call (attribute
|
||||
attribute: (identifier) @attribute)))
|
||||
|
||||
((decorator
|
||||
(identifier) @attribute.builtin)
|
||||
(#any-of? @attribute.builtin "classmethod" "property"))
|
||||
|
||||
;; Builtin functions
|
||||
|
||||
((call
|
||||
function: (identifier) @function.builtin)
|
||||
(#any-of? @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 definitions
|
||||
|
||||
(function_definition
|
||||
name: (identifier) @function)
|
||||
|
||||
(type (identifier) @type)
|
||||
(type
|
||||
(subscript
|
||||
(identifier) @type)) ; type subscript: Tuple[int]
|
||||
|
||||
((call
|
||||
function: (identifier) @_isinstance
|
||||
arguments: (argument_list
|
||||
(_)
|
||||
(identifier) @type))
|
||||
(#eq? @_isinstance "isinstance"))
|
||||
|
||||
;; Normal parameters
|
||||
(parameters
|
||||
(identifier) @parameter)
|
||||
;; Lambda parameters
|
||||
(lambda_parameters
|
||||
(identifier) @parameter)
|
||||
(lambda_parameters
|
||||
(tuple_pattern
|
||||
(identifier) @parameter))
|
||||
; Default parameters
|
||||
(keyword_argument
|
||||
name: (identifier) @parameter)
|
||||
; Naming parameters on call-site
|
||||
(default_parameter
|
||||
name: (identifier) @parameter)
|
||||
(typed_parameter
|
||||
(identifier) @parameter)
|
||||
(typed_default_parameter
|
||||
(identifier) @parameter)
|
||||
; Variadic parameters *args, **kwargs
|
||||
(parameters
|
||||
(list_splat_pattern ; *args
|
||||
(identifier) @parameter))
|
||||
(parameters
|
||||
(dictionary_splat_pattern ; **kwargs
|
||||
(identifier) @parameter))
|
||||
|
||||
|
||||
;; Literals
|
||||
|
||||
(none) @constant.builtin
|
||||
[(true) (false)] @boolean
|
||||
((identifier) @variable.builtin
|
||||
(#eq? @variable.builtin "self"))
|
||||
((identifier) @variable.builtin
|
||||
(#eq? @variable.builtin "cls"))
|
||||
|
||||
(integer) @number
|
||||
(float) @float
|
||||
|
||||
(comment) @comment @spell
|
||||
|
||||
((module . (comment) @preproc)
|
||||
(#lua-match? @preproc "^#!/"))
|
||||
|
||||
(string) @string
|
||||
[
|
||||
(escape_sequence)
|
||||
(escape_interpolation)
|
||||
] @string.escape
|
||||
|
||||
; doc-strings
|
||||
|
||||
(module . (expression_statement (string) @string.documentation @spell))
|
||||
|
||||
(class_definition
|
||||
body:
|
||||
(block
|
||||
. (expression_statement (string) @string.documentation @spell)))
|
||||
|
||||
(function_definition
|
||||
body:
|
||||
(block
|
||||
. (expression_statement (string) @string.documentation @spell)))
|
||||
|
||||
; Tokens
|
||||
|
||||
[
|
||||
"-"
|
||||
"-="
|
||||
":="
|
||||
"!="
|
||||
"*"
|
||||
"**"
|
||||
"**="
|
||||
"*="
|
||||
"/"
|
||||
"//"
|
||||
"//="
|
||||
"/="
|
||||
"&"
|
||||
"&="
|
||||
"%"
|
||||
"%="
|
||||
"^"
|
||||
"^="
|
||||
"+"
|
||||
"+="
|
||||
"<"
|
||||
"<<"
|
||||
"<<="
|
||||
"<="
|
||||
"<>"
|
||||
"="
|
||||
"=="
|
||||
">"
|
||||
">="
|
||||
">>"
|
||||
">>="
|
||||
"@"
|
||||
"@="
|
||||
"|"
|
||||
"|="
|
||||
"~"
|
||||
"->"
|
||||
] @operator
|
||||
|
||||
; Keywords
|
||||
[
|
||||
"and"
|
||||
"in"
|
||||
"is"
|
||||
"not"
|
||||
"or"
|
||||
"is not"
|
||||
"not in"
|
||||
|
||||
"del"
|
||||
] @keyword.operator
|
||||
|
||||
[
|
||||
"def"
|
||||
"lambda"
|
||||
] @keyword.function
|
||||
|
||||
[
|
||||
"assert"
|
||||
"class"
|
||||
"exec"
|
||||
"global"
|
||||
"nonlocal"
|
||||
"pass"
|
||||
"print"
|
||||
"with"
|
||||
"as"
|
||||
"type"
|
||||
] @keyword
|
||||
|
||||
[
|
||||
"async"
|
||||
"await"
|
||||
] @keyword.coroutine
|
||||
|
||||
[
|
||||
"return"
|
||||
"yield"
|
||||
] @keyword.return
|
||||
(yield "from" @keyword.return)
|
||||
|
||||
(future_import_statement
|
||||
"from" @include
|
||||
"__future__" @constant.builtin)
|
||||
(import_from_statement "from" @include)
|
||||
"import" @include
|
||||
|
||||
(aliased_import "as" @include)
|
||||
|
||||
["if" "elif" "else" "match" "case"] @conditional
|
||||
|
||||
["for" "while" "break" "continue"] @repeat
|
||||
|
||||
[
|
||||
"try"
|
||||
"except"
|
||||
"except*"
|
||||
"raise"
|
||||
"finally"
|
||||
] @exception
|
||||
|
||||
(raise_statement "from" @exception)
|
||||
|
||||
(try_statement
|
||||
(else_clause
|
||||
"else" @exception))
|
||||
|
||||
["(" ")" "[" "]" "{" "}"] @punctuation.bracket
|
||||
|
||||
(interpolation
|
||||
"{" @punctuation.special
|
||||
"}" @punctuation.special)
|
||||
|
||||
(type_conversion) @function.macro
|
||||
|
||||
["," "." ":" ";" (ellipsis)] @punctuation.delimiter
|
||||
|
||||
;; Class definitions
|
||||
|
||||
(class_definition name: (identifier) @type)
|
||||
|
||||
(class_definition
|
||||
body: (block
|
||||
(function_definition
|
||||
name: (identifier) @method)))
|
||||
|
||||
(class_definition
|
||||
superclasses: (argument_list
|
||||
(identifier) @type))
|
||||
|
||||
((class_definition
|
||||
body: (block
|
||||
(expression_statement
|
||||
(assignment
|
||||
left: (identifier) @field))))
|
||||
(#lua-match? @field "^%l.*$"))
|
||||
((class_definition
|
||||
body: (block
|
||||
(expression_statement
|
||||
(assignment
|
||||
left: (_
|
||||
(identifier) @field)))))
|
||||
(#lua-match? @field "^%l.*$"))
|
||||
|
||||
((class_definition
|
||||
(block
|
||||
(function_definition
|
||||
name: (identifier) @constructor)))
|
||||
(#any-of? @constructor "__new__" "__init__"))
|
||||
|
||||
((identifier) @type.builtin
|
||||
(#any-of? @type.builtin
|
||||
;; https://docs.python.org/3/library/exceptions.html
|
||||
"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"
|
||||
;; https://docs.python.org/3/library/stdtypes.html
|
||||
"bool" "int" "float" "complex" "list" "tuple" "range" "str"
|
||||
"bytes" "bytearray" "memoryview" "set" "frozenset" "dict" "type" "object"))
|
||||
|
||||
;; Error
|
||||
(ERROR) @error
|
||||
132
runtime/queries/python/indents.scm
Normal file
132
runtime/queries/python/indents.scm
Normal file
|
|
@ -0,0 +1,132 @@
|
|||
[
|
||||
(import_from_statement)
|
||||
|
||||
(parenthesized_expression)
|
||||
(generator_expression)
|
||||
(list_comprehension)
|
||||
(set_comprehension)
|
||||
(dictionary_comprehension)
|
||||
|
||||
(tuple_pattern)
|
||||
(list_pattern)
|
||||
(binary_operator)
|
||||
|
||||
(lambda)
|
||||
|
||||
(concatenated_string)
|
||||
] @indent.begin
|
||||
|
||||
((list) @indent.align
|
||||
(#set! indent.open_delimiter "[")
|
||||
(#set! indent.close_delimiter "]")
|
||||
)
|
||||
((dictionary) @indent.align
|
||||
(#set! indent.open_delimiter "{")
|
||||
(#set! indent.close_delimiter "}")
|
||||
)
|
||||
((set) @indent.align
|
||||
(#set! indent.open_delimiter "{")
|
||||
(#set! indent.close_delimiter "}")
|
||||
)
|
||||
|
||||
((for_statement) @indent.begin
|
||||
(#set! indent.immediate 1))
|
||||
((if_statement) @indent.begin
|
||||
(#set! indent.immediate 1))
|
||||
((while_statement) @indent.begin
|
||||
(#set! indent.immediate 1))
|
||||
((try_statement) @indent.begin
|
||||
(#set! indent.immediate 1))
|
||||
(ERROR "try" ":" @indent.begin (#set! indent.immediate 1))
|
||||
((function_definition) @indent.begin
|
||||
(#set! indent.immediate 1))
|
||||
((class_definition) @indent.begin
|
||||
(#set! indent.immediate 1))
|
||||
((with_statement) @indent.begin
|
||||
(#set! indent.immediate 1))
|
||||
((match_statement) @indent.begin
|
||||
(#set! indent.immediate 1))
|
||||
((case_clause) @indent.begin
|
||||
(#set! indent.immediate 1))
|
||||
|
||||
(if_statement
|
||||
condition: (parenthesized_expression) @indent.align
|
||||
(#set! indent.open_delimiter "(")
|
||||
(#set! indent.close_delimiter ")")
|
||||
(#set! indent.avoid_last_matching_next 1)
|
||||
)
|
||||
(while_statement
|
||||
condition: (parenthesized_expression) @indent.align
|
||||
(#set! indent.open_delimiter "(")
|
||||
(#set! indent.close_delimiter ")")
|
||||
(#set! indent.avoid_last_matching_next 1)
|
||||
)
|
||||
|
||||
(ERROR "(" @indent.align (#set! indent.open_delimiter "(") (#set! indent.close_delimiter ")") . (_))
|
||||
((argument_list) @indent.align
|
||||
(#set! indent.open_delimiter "(")
|
||||
(#set! indent.close_delimiter ")"))
|
||||
((parameters) @indent.align
|
||||
(#set! indent.open_delimiter "(")
|
||||
(#set! indent.close_delimiter ")")
|
||||
(#set! indent.avoid_last_matching_next 1))
|
||||
((tuple) @indent.align
|
||||
(#set! indent.open_delimiter "(")
|
||||
(#set! indent.close_delimiter ")"))
|
||||
|
||||
(ERROR "[" @indent.align (#set! indent.open_delimiter "[") (#set! indent.close_delimiter "]") . (_))
|
||||
|
||||
(ERROR "{" @indent.align (#set! indent.open_delimiter "{") (#set! indent.close_delimiter "}") . (_))
|
||||
|
||||
[
|
||||
(break_statement)
|
||||
(continue_statement)
|
||||
] @indent.dedent
|
||||
|
||||
(ERROR
|
||||
(_) @indent.branch ":" .
|
||||
(#lua-match? @indent.branch "^else"))
|
||||
|
||||
(ERROR
|
||||
(_) @indent.branch @indent.dedent ":" .
|
||||
(#lua-match? @indent.branch "^elif"))
|
||||
|
||||
(parenthesized_expression ")" @indent.end)
|
||||
(generator_expression ")" @indent.end)
|
||||
(list_comprehension "]" @indent.end)
|
||||
(set_comprehension "}" @indent.end)
|
||||
(dictionary_comprehension "}" @indent.end)
|
||||
|
||||
(tuple_pattern ")" @indent.end)
|
||||
(list_pattern "]" @indent.end)
|
||||
|
||||
|
||||
(return_statement
|
||||
[
|
||||
(_) @indent.end
|
||||
(_
|
||||
[
|
||||
(_)
|
||||
")"
|
||||
"}"
|
||||
"]"
|
||||
] @indent.end .)
|
||||
(attribute
|
||||
attribute: (_) @indent.end)
|
||||
(call
|
||||
arguments: (_ ")" @indent.end))
|
||||
"return" @indent.end
|
||||
] .)
|
||||
|
||||
[
|
||||
")"
|
||||
"]"
|
||||
"}"
|
||||
(elif_clause)
|
||||
(else_clause)
|
||||
(except_clause)
|
||||
(finally_clause)
|
||||
] @indent.branch
|
||||
|
||||
(string) @indent.auto
|
||||
|
||||
11
runtime/queries/python/injections.scm
Normal file
11
runtime/queries/python/injections.scm
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
(call
|
||||
function: (attribute
|
||||
object: (identifier) @_re)
|
||||
arguments: (argument_list (string
|
||||
(string_content) @injection.content) @_string)
|
||||
(#eq? @_re "re")
|
||||
(#lua-match? @_string "^r.*")
|
||||
(#set! injection.language "regex"))
|
||||
|
||||
((comment) @injection.content
|
||||
(#set! injection.language "comment"))
|
||||
115
runtime/queries/python/locals.scm
Normal file
115
runtime/queries/python/locals.scm
Normal file
|
|
@ -0,0 +1,115 @@
|
|||
;;; Program structure
|
||||
(module) @scope
|
||||
|
||||
(class_definition
|
||||
body: (block
|
||||
(expression_statement
|
||||
(assignment
|
||||
left: (identifier) @definition.field)))) @scope
|
||||
(class_definition
|
||||
body: (block
|
||||
(expression_statement
|
||||
(assignment
|
||||
left: (_
|
||||
(identifier) @definition.field))))) @scope
|
||||
|
||||
; Imports
|
||||
(aliased_import
|
||||
alias: (identifier) @definition.import)
|
||||
(import_statement
|
||||
name: (dotted_name ((identifier) @definition.import)))
|
||||
(import_from_statement
|
||||
name: (dotted_name ((identifier) @definition.import)))
|
||||
|
||||
; Function with parameters, defines parameters
|
||||
(parameters
|
||||
(identifier) @definition.parameter)
|
||||
|
||||
(default_parameter
|
||||
(identifier) @definition.parameter)
|
||||
|
||||
(typed_parameter
|
||||
(identifier) @definition.parameter)
|
||||
|
||||
(typed_default_parameter
|
||||
(identifier) @definition.parameter)
|
||||
|
||||
; *args parameter
|
||||
(parameters
|
||||
(list_splat_pattern
|
||||
(identifier) @definition.parameter))
|
||||
|
||||
; **kwargs parameter
|
||||
(parameters
|
||||
(dictionary_splat_pattern
|
||||
(identifier) @definition.parameter))
|
||||
|
||||
; Function defines function and scope
|
||||
((function_definition
|
||||
name: (identifier) @definition.function) @scope
|
||||
(#set! definition.function.scope "parent"))
|
||||
|
||||
|
||||
((class_definition
|
||||
name: (identifier) @definition.type) @scope
|
||||
(#set! definition.type.scope "parent"))
|
||||
|
||||
(class_definition
|
||||
body: (block
|
||||
(function_definition
|
||||
name: (identifier) @definition.method)))
|
||||
|
||||
;;; Loops
|
||||
; not a scope!
|
||||
(for_statement
|
||||
left: (pattern_list
|
||||
(identifier) @definition.var))
|
||||
(for_statement
|
||||
left: (tuple_pattern
|
||||
(identifier) @definition.var))
|
||||
(for_statement
|
||||
left: (identifier) @definition.var)
|
||||
|
||||
; not a scope!
|
||||
;(while_statement) @scope
|
||||
|
||||
; for in list comprehension
|
||||
(for_in_clause
|
||||
left: (identifier) @definition.var)
|
||||
(for_in_clause
|
||||
left: (tuple_pattern
|
||||
(identifier) @definition.var))
|
||||
(for_in_clause
|
||||
left: (pattern_list
|
||||
(identifier) @definition.var))
|
||||
|
||||
(dictionary_comprehension) @scope
|
||||
(list_comprehension) @scope
|
||||
(set_comprehension) @scope
|
||||
|
||||
;;; Assignments
|
||||
|
||||
(assignment
|
||||
left: (identifier) @definition.var)
|
||||
|
||||
(assignment
|
||||
left: (pattern_list
|
||||
(identifier) @definition.var))
|
||||
(assignment
|
||||
left: (tuple_pattern
|
||||
(identifier) @definition.var))
|
||||
|
||||
(assignment
|
||||
left: (attribute
|
||||
(identifier)
|
||||
(identifier) @definition.field))
|
||||
|
||||
; Walrus operator x := 1
|
||||
(named_expression
|
||||
(identifier) @definition.var)
|
||||
|
||||
(as_pattern
|
||||
alias: (as_pattern_target) @definition.var)
|
||||
|
||||
;;; REFERENCES
|
||||
(identifier) @reference
|
||||
Loading…
Add table
Add a link
Reference in a new issue