aboutsummaryrefslogtreecommitdiffstats
path: root/queries/slint
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 /queries/slint
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>
Diffstat (limited to 'queries/slint')
-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
5 files changed, 358 insertions, 132 deletions
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)