diff options
| author | Christian Clason <c.clason@uni-graz.at> | 2023-06-12 09:54:30 -0600 |
|---|---|---|
| committer | Christian Clason <c.clason@uni-graz.at> | 2025-05-12 18:43:40 +0200 |
| commit | 692b051b09935653befdb8f7ba8afdb640adf17b (patch) | |
| tree | 167162b6b129ae04f68c5735078521a72917c742 /runtime/queries/starlark | |
| parent | feat(c-family): inherit injections (diff) | |
| download | nvim-treesitter-692b051b09935653befdb8f7ba8afdb640adf17b.tar nvim-treesitter-692b051b09935653befdb8f7ba8afdb640adf17b.tar.gz nvim-treesitter-692b051b09935653befdb8f7ba8afdb640adf17b.tar.bz2 nvim-treesitter-692b051b09935653befdb8f7ba8afdb640adf17b.tar.lz nvim-treesitter-692b051b09935653befdb8f7ba8afdb640adf17b.tar.xz nvim-treesitter-692b051b09935653befdb8f7ba8afdb640adf17b.tar.zst nvim-treesitter-692b051b09935653befdb8f7ba8afdb640adf17b.zip | |
feat!: drop modules, general refactor and cleanup
Diffstat (limited to 'runtime/queries/starlark')
| -rw-r--r-- | runtime/queries/starlark/folds.scm | 17 | ||||
| -rw-r--r-- | runtime/queries/starlark/highlights.scm | 337 | ||||
| -rw-r--r-- | runtime/queries/starlark/indents.scm | 56 | ||||
| -rw-r--r-- | runtime/queries/starlark/injections.scm | 1 | ||||
| -rw-r--r-- | runtime/queries/starlark/locals.scm | 96 |
5 files changed, 507 insertions, 0 deletions
diff --git a/runtime/queries/starlark/folds.scm b/runtime/queries/starlark/folds.scm new file mode 100644 index 000000000..0c9d2a260 --- /dev/null +++ b/runtime/queries/starlark/folds.scm @@ -0,0 +1,17 @@ +[ + (function_definition) + (for_statement) + (if_statement) + (while_statement) + (with_statement) + (match_statement) + (parameters) + (argument_list) + (parenthesized_expression) + (list_comprehension) + (dictionary_comprehension) + (tuple) + (list) + (dictionary) + (string) +] @fold diff --git a/runtime/queries/starlark/highlights.scm b/runtime/queries/starlark/highlights.scm new file mode 100644 index 000000000..fe3dce89b --- /dev/null +++ b/runtime/queries/starlark/highlights.scm @@ -0,0 +1,337 @@ +; 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")) + +((attribute + attribute: (identifier) @variable.member) + (#lua-match? @variable.member "^[%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")) + +; 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" + "fail" "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" "struct" "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")) + +((identifier) @type.builtin + (#any-of? @type.builtin + ; https://docs.python.org/3/library/exceptions.html + "ArithmeticError" "BufferError" "LookupError" "AssertionError" "AttributeError" "EOFError" + "FloatingPointError" "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" "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")) + +; Normal parameters +(parameters + (identifier) @variable.parameter) + +; Lambda parameters +(lambda_parameters + (identifier) @variable.parameter) + +(lambda_parameters + (tuple_pattern + (identifier) @variable.parameter)) + +; Default parameters +(keyword_argument + name: (identifier) @variable.parameter) + +; Naming parameters on call-site +(default_parameter + name: (identifier) @variable.parameter) + +(typed_parameter + (identifier) @variable.parameter) + +(typed_default_parameter + (identifier) @variable.parameter) + +; Variadic parameters *args, **kwargs +(parameters + (list_splat_pattern + ; *args + (identifier) @variable.parameter)) + +(parameters + (dictionary_splat_pattern + ; **kwargs + (identifier) @variable.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) @number.float + +(comment) @comment @spell + +((module + . + (comment) @keyword.directive @nospell) + (#lua-match? @keyword.directive "^#!/")) + +(string) @string + +[ + (escape_sequence) + (escape_interpolation) +] @string.escape + +; doc-strings +(module + . + (expression_statement + (string) @string.documentation @spell)) + +(function_definition + body: (block + . + (expression_statement + (string) @string.documentation @spell))) + +; Tokens +[ + "-" + "-=" + ":=" + "!=" + "*" + "**" + "**=" + "*=" + "/" + "//" + "//=" + "/=" + "&" + "&=" + "%" + "%=" + "^" + "^=" + "+" + "+=" + "<" + "<<" + "<<=" + "<=" + "<>" + "=" + "==" + ">" + ">=" + ">>" + ">>=" + "@" + "@=" + "|" + "|=" + "~" + "->" +] @operator + +; Keywords +[ + "and" + "in" + "not" + "or" + "del" +] @keyword.operator + +[ + "def" + "lambda" +] @keyword.function + +[ + "async" + "exec" + "pass" + "print" + "with" + "as" +] @keyword + +"async" @keyword.coroutine + +"return" @keyword.return + +((call + function: (identifier) @keyword.import + arguments: (argument_list + (string) @string)) + (#eq? @keyword.import "load")) + +[ + "if" + "elif" + "else" + "match" + "case" +] @keyword.conditional + +[ + "for" + "while" + "break" + "continue" +] @keyword.repeat + +[ + "(" + ")" + "[" + "]" + "{" + "}" +] @punctuation.bracket + +(interpolation + "{" @punctuation.special + "}" @punctuation.special) + +(type_conversion) @function.macro + +[ + "," + "." + ":" + ";" + (ellipsis) +] @punctuation.delimiter + +; Starlark-specific +; Assertion calls +(assert_keyword) @keyword + +(assert_builtin) @function.builtin + +; Struct definitions +((call + function: (identifier) @_func + arguments: (argument_list + (keyword_argument + name: (identifier) @variable.member))) + (#eq? @_func "struct")) + +; Function calls +(call + function: (identifier) @function.call) + +(call + function: (attribute + attribute: (identifier) @function.method.call)) + +((call + function: (identifier) @constructor) + (#lua-match? @constructor "^[A-Z]")) + +((call + function: (attribute + attribute: (identifier) @constructor)) + (#lua-match? @constructor "^[A-Z]")) diff --git a/runtime/queries/starlark/indents.scm b/runtime/queries/starlark/indents.scm new file mode 100644 index 000000000..1aeb9f60e --- /dev/null +++ b/runtime/queries/starlark/indents.scm @@ -0,0 +1,56 @@ +[ + (list) + (dictionary) + (set) + (for_statement) + (if_statement) + (while_statement) + (with_statement) + (parenthesized_expression) + (dictionary_comprehension) + (list_comprehension) + (set_comprehension) + (tuple_pattern) + (list_pattern) + (binary_operator) + (lambda) + (function_definition) +] @indent.begin + +(if_statement + condition: (parenthesized_expression) @indent.align + (#set! indent.open_delimiter "(") + (#set! indent.close_delimiter ")")) + +((ERROR + "(" + . + (_)) @indent.align + (#set! indent.open_delimiter "(") + (#set! indent.close_delimiter ")")) + +((argument_list) @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 ")")) + +((tuple) @indent.align + (#set! indent.open_delimiter "(") + (#set! indent.close_delimiter ")")) + +[ + ")" + "]" + "}" + (elif_clause) + (else_clause) +] @indent.branch + +(string) @indent.auto diff --git a/runtime/queries/starlark/injections.scm b/runtime/queries/starlark/injections.scm new file mode 100644 index 000000000..2b60646e2 --- /dev/null +++ b/runtime/queries/starlark/injections.scm @@ -0,0 +1 @@ +; inherits python diff --git a/runtime/queries/starlark/locals.scm b/runtime/queries/starlark/locals.scm new file mode 100644 index 000000000..82ec0b5d2 --- /dev/null +++ b/runtime/queries/starlark/locals.scm @@ -0,0 +1,96 @@ +; Program structure +(module) @local.scope + +; Function with parameters, defines parameters +(parameters + (identifier) @local.definition.parameter) + +(default_parameter + (identifier) @local.definition.parameter) + +(typed_parameter + (identifier) @local.definition.parameter) + +(typed_default_parameter + (identifier) @local.definition.parameter) + +; *args parameter +(parameters + (list_splat_pattern + (identifier) @local.definition.parameter)) + +; **kwargs parameter +(parameters + (dictionary_splat_pattern + (identifier) @local.definition.parameter)) + +; Function defines function and scope +((function_definition + name: (identifier) @local.definition.function) @local.scope + (#set! definition.function.scope "parent")) + +; Loops +; not a scope! +(for_statement + left: (pattern_list + (identifier) @local.definition.var)) + +(for_statement + left: (tuple_pattern + (identifier) @local.definition.var)) + +(for_statement + left: (identifier) @local.definition.var) + +; for in list comprehension +(for_in_clause + left: (identifier) @local.definition.var) + +(for_in_clause + left: (tuple_pattern + (identifier) @local.definition.var)) + +(for_in_clause + left: (pattern_list + (identifier) @local.definition.var)) + +(dictionary_comprehension) @local.scope + +(list_comprehension) @local.scope + +(set_comprehension) @local.scope + +; Assignments +(assignment + left: (identifier) @local.definition.var) + +(assignment + left: (pattern_list + (identifier) @local.definition.var)) + +(assignment + left: (tuple_pattern + (identifier) @local.definition.var)) + +(assignment + left: (attribute + (identifier) + (identifier) @local.definition.field)) + +; Walrus operator x := 1 +(named_expression + (identifier) @local.definition.var) + +(as_pattern + alias: (as_pattern_target) @local.definition.var) + +; REFERENCES +(identifier) @local.reference + +; Starlark-specific +; Loads +((call + function: (identifier) @_fn + arguments: (argument_list + (string) @local.definition.import)) + (#eq? @_fn "load")) |
