aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTobias Hunger <tobias.hunger@gmail.com>2024-02-09 14:46:57 +0100
committerGitHub <noreply@github.com>2024-02-09 13:46:57 +0000
commit0f3183dda8df688a77223b9762475dee5b27271f (patch)
treefede30d0f59f5fa4c7ef65e16d8c495d47e0ad28
parentUpdate parsers: ruby (diff)
downloadnvim-treesitter-0f3183dda8df688a77223b9762475dee5b27271f.tar
nvim-treesitter-0f3183dda8df688a77223b9762475dee5b27271f.tar.gz
nvim-treesitter-0f3183dda8df688a77223b9762475dee5b27271f.tar.bz2
nvim-treesitter-0f3183dda8df688a77223b9762475dee5b27271f.tar.lz
nvim-treesitter-0f3183dda8df688a77223b9762475dee5b27271f.tar.xz
nvim-treesitter-0f3183dda8df688a77223b9762475dee5b27271f.tar.zst
nvim-treesitter-0f3183dda8df688a77223b9762475dee5b27271f.zip
feat(slint)!: change to the official parser (#6027)
This change replaces the slint parser written and maintained by @jrmoulton with the official one hosted in the slint-ui organization on github. A huge thank you to @jrmoulton for all his work on the tree-sitter parser! --------- Co-authored-by: jrmoulton <jaredmoulton3@gmail.com>
-rw-r--r--README.md2
-rw-r--r--lockfile.json2
-rw-r--r--lua/nvim-treesitter/parsers.lua5
-rw-r--r--queries/rust/injections.scm20
-rw-r--r--queries/slint/folds.scm11
-rw-r--r--queries/slint/highlights.scm330
-rw-r--r--queries/slint/indents.scm30
-rw-r--r--queries/slint/injections.scm2
-rw-r--r--queries/slint/locals.scm117
9 files changed, 382 insertions, 137 deletions
diff --git a/README.md b/README.md
index 290b73a0d..1163e6d1a 100644
--- a/README.md
+++ b/README.md
@@ -370,7 +370,7 @@ We are looking for maintainers to add more parsers and to write query files for
- [ ] [scheme](https://github.com/6cdh/tree-sitter-scheme)
- [x] [scss](https://github.com/serenadeai/tree-sitter-scss) (maintained by @elianiva)
- [x] [slang](https://github.com/theHamsta/tree-sitter-slang) (experimental, maintained by @theHamsta)
-- [x] [slint](https://github.com/jrmoulton/tree-sitter-slint) (experimental, maintained by @jrmoulton)
+- [x] [slint](https://github.com/slint-ui/slint) (maintained by @hunger)
- [x] [smali](https://git.sr.ht/~yotam/tree-sitter-smali) (maintained by @amaanq)
- [x] [smithy](https://github.com/indoorvivants/tree-sitter-smithy) (maintained by @amaanq, @keynmol)
- [ ] [snakemake](https://github.com/osthomas/tree-sitter-snakemake) (experimental)
diff --git a/lockfile.json b/lockfile.json
index 6cb978c57..315f81b81 100644
--- a/lockfile.json
+++ b/lockfile.json
@@ -591,7 +591,7 @@
"revision": "ac07aa2c875ef6ada2ec468d8a4d0c7c5efd96d7"
},
"slint": {
- "revision": "00c8a2d3645766f68c0d0460086c0a994e5b0d85"
+ "revision": "15618215b79b9db08f824a5c97a12d073dcc1c00"
},
"smali": {
"revision": "72e334b2630f5852825ba5ff9dfd872447175eb5"
diff --git a/lua/nvim-treesitter/parsers.lua b/lua/nvim-treesitter/parsers.lua
index 45bf2b784..b1907d255 100644
--- a/lua/nvim-treesitter/parsers.lua
+++ b/lua/nvim-treesitter/parsers.lua
@@ -1734,11 +1734,10 @@ list.slang = {
list.slint = {
install_info = {
- url = "https://github.com/jrmoulton/tree-sitter-slint",
+ url = "https://github.com/slint-ui/tree-sitter-slint",
files = { "src/parser.c" },
},
- maintainers = { "@jrmoulton" },
- experimental = true,
+ maintainers = { "@hunger" },
}
list.smali = {
diff --git a/queries/rust/injections.scm b/queries/rust/injections.scm
index 1537568c1..d561d4ec9 100644
--- a/queries/rust/injections.scm
+++ b/queries/rust/injections.scm
@@ -1,8 +1,28 @@
(macro_invocation
+ macro:
+ [
+ (scoped_identifier
+ name: (_) @_macro_name)
+ (identifier) @_macro_name
+ ]
(token_tree) @injection.content
+ (#not-eq? @_macro_name "slint")
(#set! injection.language "rust")
(#set! injection.include-children))
+(macro_invocation
+ macro:
+ [
+ (scoped_identifier
+ name: (_) @_macro_name)
+ (identifier) @_macro_name
+ ]
+ (token_tree) @injection.content
+ (#eq? @_macro_name "slint")
+ (#offset! @injection.content 0 1 0 -1)
+ (#set! injection.language "slint")
+ (#set! injection.include-children))
+
(macro_definition
(macro_rule
left: (token_tree_pattern) @injection.content
diff --git a/queries/slint/folds.scm b/queries/slint/folds.scm
new file mode 100644
index 000000000..4c5b1307a
--- /dev/null
+++ b/queries/slint/folds.scm
@@ -0,0 +1,11 @@
+[
+ (anon_struct_block)
+ (block)
+ (callback_event)
+ (component)
+ (enum_block)
+ (function_definition)
+ (global_definition)
+ (imperative_block)
+ (struct_block)
+] @fold
diff --git a/queries/slint/highlights.scm b/queries/slint/highlights.scm
index 673fc643d..2e6d5997e 100644
--- a/queries/slint/highlights.scm
+++ b/queries/slint/highlights.scm
@@ -1,121 +1,113 @@
-(identifier) @variable
+(comment) @comment @spell
-(type_identifier) @type
+; Different types:
+(string_value) @string @spell
-(comment) @comment @spell
+(escape_sequence) @string.escape
-(int_literal) @number
+(color_value) @constant
-(float_literal) @number.float
+[
+ (children_identifier)
+ (easing_kind_identifier)
+] @constant.builtin
-(string_literal) @string
+(bool_value) @boolean
-(function_identifier) @function
+[
+ (int_value)
+ (physical_length_value)
+] @number
[
- (image_macro)
- (children_macro)
- (radial_grad_macro)
- (linear_grad_macro)
-] @function.macro
+ (angle_value)
+ (duration_value)
+ (float_value)
+ (length_value)
+ (percent_value)
+ (relative_font_size_value)
+] @number.float
-(call_expression
- function: (identifier) @function.call)
+(purity) @type.qualifier
-(call_expression
- function:
- (field_expression
- field: (identifier) @function.call))
+(function_visibility) @type.qualifier
-(vis) @keyword.import
+(property_visibility) @type.qualifier
-(units) @type
+(builtin_type_identifier) @type.builtin
-(array_literal
- (identifier) @type)
+(reference_identifier) @variable.builtin
-(transition_statement
- state: (identifier) @variable.member)
+(type
+ [
+ (type_list)
+ (user_type_identifier)
+ (anon_struct_block)
+ ]) @type
-(state_expression
- state: (identifier) @variable.member)
+(user_type_identifier) @type
-(struct_block_definition
- (identifier) @variable.member)
+; Functions and callbacks
+(argument) @variable.parameter
-; (state_identifier) @variable.member
-[
- "in"
- "for"
-] @keyword.repeat
+(function_call
+ name: (_) @function.call)
-"@" @keyword
+; definitions
+(callback
+ name: (_) @function)
-[
- "import"
- "from"
-] @keyword.import
+(callback_alias
+ name: (_) @function)
-[
- "if"
- "else"
-] @keyword.conditional
+(callback_event
+ name: (simple_identifier) @function.call)
-[
- "root"
- "parent"
- "duration"
- "easing"
-] @variable.builtin
+(component
+ id: (_) @variable)
-[
- "true"
- "false"
-] @boolean
+(enum_definition
+ name: (_) @type)
+
+(function_definition
+ name: (_) @function)
+
+(struct_definition
+ name: (_) @type)
+
+(typed_identifier
+ type: (_) @type)
+
+; Operators
+(binary_expression
+ op: (_) @operator)
+
+(unary_expression
+ op: (_) @operator)
[
- "struct"
- "property"
- "callback"
- "in"
- "animate"
- "states"
- "when"
- "out"
- "transitions"
- "global"
-] @keyword
+ (comparison_operator)
+ (mult_prec_operator)
+ (add_prec_operator)
+ (unary_prec_operator)
+ (assignment_prec_operator)
+] @operator
[
- "black"
- "transparent"
- "blue"
- "ease"
- "ease_in"
- "ease-in"
- "ease_in_out"
- "ease-in-out"
- "ease_out"
- "ease-out"
- "end"
- "green"
- "red"
- "red"
- "start"
- "yellow"
- "white"
- "gray"
-] @constant.builtin
+ ":="
+ "=>"
+ "->"
+ "<=>"
+] @operator
; Punctuation
[
- ","
- "."
";"
+ "."
+ ","
":"
] @punctuation.delimiter
-; Brackets
[
"("
")"
@@ -125,53 +117,145 @@
"}"
] @punctuation.bracket
-(define_property
+(property
[
"<"
">"
] @punctuation.bracket)
-[
- "angle"
- "bool"
- "brush"
- "color"
- "float"
- "image"
- "int"
- "length"
- "percent"
- "physical-length"
- "physical_length"
- "string"
-] @type.builtin
+; Properties, Variables and Constants:
+(component
+ id: (simple_identifier) @constant)
+
+(property
+ name: (simple_identifier) @property)
+
+(binding_alias
+ name: (simple_identifier) @property)
+
+(binding
+ name: (simple_identifier) @property)
+
+(struct_block
+ (simple_identifier) @variable.member)
+
+(anon_struct_block
+ (simple_identifier) @variable.member)
+
+(property_assignment
+ property: (simple_identifier) @property)
+
+(states_definition
+ name: (simple_identifier) @variable)
+
+(callback
+ name: (simple_identifier) @variable)
+
+(typed_identifier
+ name: (_) @variable)
+
+(simple_indexed_identifier
+ name: (simple_identifier) @variable
+ index_var: (simple_identifier) @variable)
+(expression
+ (simple_identifier) @variable)
+
+(member_access
+ member:
+ (expression
+ (simple_identifier) @property))
+
+(states_definition
+ name: (simple_identifier) @constant)
+
+; Attributes:
[
- ":="
- "<=>"
- "!"
- "-"
- "+"
- "*"
- "/"
- "&&"
- "||"
- ">"
- "<"
- ">="
- "<="
- "="
- ":"
- "+="
- "-="
- "*="
- "/="
- "?"
- "=>"
-] @operator
+ (linear_gradient_identifier)
+ (radial_gradient_identifier)
+ (radial_gradient_kind)
+] @attribute
+
+(image_call
+ "@image-url" @attribute)
+
+(tr
+ "@tr" @attribute)
+
+; Keywords:
+(animate_option_identifier) @keyword
+
+(export) @keyword
+
+(if_statement
+ "if" @keyword.conditional)
+
+(if_expr
+ [
+ "if"
+ "else"
+ ] @keyword.conditional)
(ternary_expression
[
- ":"
"?"
+ ":"
] @keyword.conditional.ternary)
+
+(animate_statement
+ "animate" @keyword)
+
+(callback
+ "callback" @keyword)
+
+(component_definition
+ [
+ "component"
+ "inherits"
+ ] @keyword)
+
+(enum_definition
+ "enum" @keyword)
+
+(for_loop
+ [
+ "for"
+ "in"
+ ] @keyword.repeat)
+
+(function_definition
+ "function" @keyword.function)
+
+(global_definition
+ "global" @keyword)
+
+(imperative_block
+ "return" @keyword.return)
+
+(import_statement
+ [
+ "import"
+ "from"
+ ] @keyword.import)
+
+(import_type
+ "as" @keyword.import)
+
+(property
+ "property" @keyword)
+
+(states_definition
+ [
+ "states"
+ "when"
+ ] @keyword)
+
+(struct_definition
+ "struct" @keyword)
+
+(transitions_definition
+ [
+ "transitions"
+ "in"
+ "out"
+ ] @keyword)
diff --git a/queries/slint/indents.scm b/queries/slint/indents.scm
index 587a8ecf3..d6bdeacde 100644
--- a/queries/slint/indents.scm
+++ b/queries/slint/indents.scm
@@ -1,14 +1,26 @@
[
- (comp_body)
- (state_statement)
- (transition_statement)
- (handler_body)
- (consequence_body)
- (global_single)
+ (arguments)
+ (block)
+ (enum_block)
+ (global_block)
+ (imperative_block)
+ (struct_block)
+ (typed_identifier)
] @indent.begin
-"}" @indent.end
+([
+ (block)
+ (enum_block)
+ (global_block)
+ (imperative_block)
+ (struct_block)
+]
+ "}" @indent.end)
-(comment) @indent.auto
+([
+ (arguments)
+ (typed_identifier)
+]
+ ")" @indent.end)
-(string_literal) @indent.auto
+(string_value) @indent.auto
diff --git a/queries/slint/injections.scm b/queries/slint/injections.scm
new file mode 100644
index 000000000..2f0e58eb6
--- /dev/null
+++ b/queries/slint/injections.scm
@@ -0,0 +1,2 @@
+((comment) @injection.content
+ (#set! injection.language "comment"))
diff --git a/queries/slint/locals.scm b/queries/slint/locals.scm
new file mode 100644
index 000000000..2d256b7ac
--- /dev/null
+++ b/queries/slint/locals.scm
@@ -0,0 +1,117 @@
+[
+ (anon_struct_block)
+ (block)
+ (callback_event)
+ (component)
+ (enum_block)
+ (function_definition)
+ (global_definition)
+ (imperative_block)
+ (struct_block)
+] @local.scope
+
+(anon_struct_block
+ (_) @local.definition.field)
+
+(argument) @local.definition.var
+
+(callback
+ name: (_) @local.definition.member)
+
+(component_definition
+ name: (_) @local.definition.type)
+
+(enum_definition
+ name: (_) @local.definition.type)
+
+(enum_block
+ (_) @local.definition.field)
+
+(function_definition
+ name: (_) @local.definition.function)
+
+(global_definition
+ name: (_) @local.definition.type)
+
+(import_type
+ import_name: (_)
+ !local_name) @local.definition.import
+
+(import_type
+ import_name: (_)
+ local_name: (_) @local.definition.import)
+
+(property
+ name: (_) @local.definition.field)
+
+(struct_block
+ (_) @local.definition.field)
+
+(struct_definition
+ name: (_) @local.definition.type)
+
+(typed_identifier
+ name: (_) @local.definition.var)
+
+(argument
+ (_) @local.reference)
+
+(binary_expression
+ left: (_) @local.reference)
+
+(binary_expression
+ right: (_) @local.reference)
+
+(callback_event
+ name: (_) @local.reference)
+
+(component
+ type: (_) @local.reference
+ (#set! reference.kind "type"))
+
+(component_definition
+ base_type: (_) @local.reference
+ (#set! reference.kind "type"))
+
+(function_call
+ name: (_) @local.reference)
+
+(index_op
+ index: (_) @local.reference)
+
+(index_op
+ left: (_) @local.reference)
+
+(member_access
+ base: (_) @local.reference)
+
+(member_access
+ member: (_) @local.reference)
+
+(parens_op
+ left: (_) @local.reference)
+
+(property
+ type: (_) @local.reference
+ (#set! reference.kind "type"))
+
+(property_assignment
+ property: (_) @local.reference
+ (#set! reference.kind "field"))
+
+(property_assignment
+ value: (_) @local.reference)
+
+(struct_block
+ (_) @local.reference
+ (#set! reference.kind "type"))
+
+(tr
+ percent: (_) @local.reference)
+
+(typed_identifier
+ type: (_) @local.reference
+ (#set! reference.kind "type"))
+
+(unary_expression
+ left: (_) @local.reference)