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>
This commit is contained in:
Tobias Hunger 2024-02-09 14:46:57 +01:00 committed by GitHub
parent f0d43eff13
commit 0f3183dda8
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
9 changed files with 401 additions and 156 deletions

View file

@ -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)

View file

@ -591,7 +591,7 @@
"revision": "ac07aa2c875ef6ada2ec468d8a4d0c7c5efd96d7"
},
"slint": {
"revision": "00c8a2d3645766f68c0d0460086c0a994e5b0d85"
"revision": "15618215b79b9db08f824a5c97a12d073dcc1c00"
},
"smali": {
"revision": "72e334b2630f5852825ba5ff9dfd872447175eb5"

View file

@ -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 = {

View file

@ -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

11
queries/slint/folds.scm Normal file
View file

@ -0,0 +1,11 @@
[
(anon_struct_block)
(block)
(callback_event)
(component)
(enum_block)
(function_definition)
(global_definition)
(imperative_block)
(struct_block)
] @fold

View file

@ -1,121 +1,113 @@
(identifier) @variable
(type_identifier) @type
(comment) @comment @spell
(int_literal) @number
; Different types:
(string_value) @string @spell
(float_literal) @number.float
(escape_sequence) @string.escape
(string_literal) @string
(function_identifier) @function
(color_value) @constant
[
(image_macro)
(children_macro)
(radial_grad_macro)
(linear_grad_macro)
] @function.macro
(call_expression
function: (identifier) @function.call)
(call_expression
function:
(field_expression
field: (identifier) @function.call))
(vis) @keyword.import
(units) @type
(array_literal
(identifier) @type)
(transition_statement
state: (identifier) @variable.member)
(state_expression
state: (identifier) @variable.member)
(struct_block_definition
(identifier) @variable.member)
; (state_identifier) @variable.member
[
"in"
"for"
] @keyword.repeat
"@" @keyword
[
"import"
"from"
] @keyword.import
[
"if"
"else"
] @keyword.conditional
[
"root"
"parent"
"duration"
"easing"
] @variable.builtin
[
"true"
"false"
] @boolean
[
"struct"
"property"
"callback"
"in"
"animate"
"states"
"when"
"out"
"transitions"
"global"
] @keyword
[
"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"
(children_identifier)
(easing_kind_identifier)
] @constant.builtin
(bool_value) @boolean
[
(int_value)
(physical_length_value)
] @number
[
(angle_value)
(duration_value)
(float_value)
(length_value)
(percent_value)
(relative_font_size_value)
] @number.float
(purity) @type.qualifier
(function_visibility) @type.qualifier
(property_visibility) @type.qualifier
(builtin_type_identifier) @type.builtin
(reference_identifier) @variable.builtin
(type
[
(type_list)
(user_type_identifier)
(anon_struct_block)
]) @type
(user_type_identifier) @type
; Functions and callbacks
(argument) @variable.parameter
(function_call
name: (_) @function.call)
; definitions
(callback
name: (_) @function)
(callback_alias
name: (_) @function)
(callback_event
name: (simple_identifier) @function.call)
(component
id: (_) @variable)
(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)
[
(comparison_operator)
(mult_prec_operator)
(add_prec_operator)
(unary_prec_operator)
(assignment_prec_operator)
] @operator
[
":="
"=>"
"->"
"<=>"
] @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)

View file

@ -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

View file

@ -0,0 +1,2 @@
((comment) @injection.content
(#set! injection.language "comment"))

117
queries/slint/locals.scm Normal file
View file

@ -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)