mirror of
https://github.com/nvim-treesitter/nvim-treesitter.git
synced 2026-07-12 08:20:05 -04:00
highlight(swift): add upstream queries
This commit is contained in:
parent
cca7d1d671
commit
f3e554ed7b
2 changed files with 148 additions and 0 deletions
130
queries/swift/highlights.scm
Normal file
130
queries/swift/highlights.scm
Normal file
|
|
@ -0,0 +1,130 @@
|
||||||
|
; Identifiers
|
||||||
|
(attribute) @variable
|
||||||
|
(simple_identifier) @variable
|
||||||
|
(type_identifier) @type
|
||||||
|
(self_expression) @variable.builtin
|
||||||
|
|
||||||
|
; Declarations
|
||||||
|
"func" @keyword.function
|
||||||
|
[
|
||||||
|
(visibility_modifier)
|
||||||
|
(member_modifier)
|
||||||
|
(function_modifier)
|
||||||
|
(property_modifier)
|
||||||
|
(parameter_modifier)
|
||||||
|
(inheritance_modifier)
|
||||||
|
] @keyword
|
||||||
|
|
||||||
|
(function_declaration (simple_identifier) @method)
|
||||||
|
(function_declaration ["init" @constructor])
|
||||||
|
(throws) @keyword
|
||||||
|
(async) @keyword
|
||||||
|
(where_keyword) @keyword
|
||||||
|
(parameter external_name: (simple_identifier) @parameter)
|
||||||
|
(parameter name: (simple_identifier) @parameter)
|
||||||
|
(type_parameter (type_identifier) @parameter)
|
||||||
|
(inheritance_constraint (identifier (simple_identifier) @parameter))
|
||||||
|
(equality_constraint (identifier (simple_identifier) @parameter))
|
||||||
|
|
||||||
|
["typealias" "struct" "class" "enum" "protocol" "extension"] @keyword
|
||||||
|
|
||||||
|
(class_body (property_declaration (value_binding_pattern (non_binding_pattern (simple_identifier) @property))))
|
||||||
|
(protocol_property_declaration (value_binding_pattern (non_binding_pattern (simple_identifier) @property)))
|
||||||
|
|
||||||
|
(import_declaration ["import" @include])
|
||||||
|
|
||||||
|
(enum_entry ["case" @keyword])
|
||||||
|
|
||||||
|
; Function calls
|
||||||
|
(call_expression (simple_identifier) @function) ; foo()
|
||||||
|
(call_expression ; foo.bar.baz(): highlight the baz()
|
||||||
|
(navigation_expression
|
||||||
|
(navigation_suffix (simple_identifier) @function)))
|
||||||
|
((navigation_expression
|
||||||
|
(simple_identifier) @type) ; SomeType.method(): highlight SomeType as a type
|
||||||
|
(#lua-match? @type "^[A-Z]"))
|
||||||
|
|
||||||
|
(directive) @function.macro
|
||||||
|
(diagnostic) @function.macro
|
||||||
|
|
||||||
|
; Statements
|
||||||
|
(for_statement ["for" @repeat])
|
||||||
|
(for_statement ["in" @repeat])
|
||||||
|
(for_statement item: (simple_identifier) @variable)
|
||||||
|
(else) @keyword
|
||||||
|
(as_operator) @keyword
|
||||||
|
|
||||||
|
["while" "repeat" "continue" "break"] @repeat
|
||||||
|
|
||||||
|
["let" "var"] @keyword
|
||||||
|
(non_binding_pattern (simple_identifier) @variable)
|
||||||
|
|
||||||
|
(guard_statement ["guard" @conditional])
|
||||||
|
(if_statement ["if" @conditional])
|
||||||
|
(switch_statement ["switch" @conditional])
|
||||||
|
(switch_entry ["case" @keyword])
|
||||||
|
(switch_entry ["fallthrough" @keyword])
|
||||||
|
(switch_entry (default_keyword) @keyword)
|
||||||
|
"return" @keyword.return
|
||||||
|
|
||||||
|
["do" (throw_keyword) (catch_keyword)] @keyword
|
||||||
|
|
||||||
|
(statement_label) @label
|
||||||
|
|
||||||
|
; Comments
|
||||||
|
(comment) @comment
|
||||||
|
(multiline_comment) @comment
|
||||||
|
|
||||||
|
; String literals
|
||||||
|
(line_str_text) @string
|
||||||
|
(str_escaped_char) @string
|
||||||
|
(multi_line_str_text) @string
|
||||||
|
(raw_str_part) @string
|
||||||
|
(raw_str_end_part) @string
|
||||||
|
(raw_str_interpolation_start) @punctuation.special
|
||||||
|
["\"" "\"\"\""] @string
|
||||||
|
|
||||||
|
; Lambda literals
|
||||||
|
(lambda_literal ["in" @keyword.operator])
|
||||||
|
|
||||||
|
; Basic literals
|
||||||
|
[
|
||||||
|
(integer_literal)
|
||||||
|
(hex_literal)
|
||||||
|
(oct_literal)
|
||||||
|
(bin_literal)
|
||||||
|
] @number
|
||||||
|
(real_literal) @float
|
||||||
|
(boolean_literal) @boolean
|
||||||
|
"nil" @variable.builtin
|
||||||
|
|
||||||
|
; Operators
|
||||||
|
(custom_operator) @operator
|
||||||
|
[
|
||||||
|
"try"
|
||||||
|
"try?"
|
||||||
|
"try!"
|
||||||
|
"!"
|
||||||
|
"+"
|
||||||
|
"-"
|
||||||
|
"*"
|
||||||
|
"/"
|
||||||
|
"%"
|
||||||
|
"="
|
||||||
|
"+="
|
||||||
|
"-="
|
||||||
|
"*="
|
||||||
|
"/="
|
||||||
|
"<"
|
||||||
|
">"
|
||||||
|
"<="
|
||||||
|
">="
|
||||||
|
"++"
|
||||||
|
"--"
|
||||||
|
"&"
|
||||||
|
"~"
|
||||||
|
"%="
|
||||||
|
"!="
|
||||||
|
"!=="
|
||||||
|
"==="
|
||||||
|
] @operator
|
||||||
18
queries/swift/locals.scm
Normal file
18
queries/swift/locals.scm
Normal file
|
|
@ -0,0 +1,18 @@
|
||||||
|
(import_declaration (identifier) @definition.import)
|
||||||
|
(function_declaration name: (simple_identifier) @definition.function)
|
||||||
|
|
||||||
|
; Scopes
|
||||||
|
[
|
||||||
|
(statements)
|
||||||
|
(for_statement)
|
||||||
|
(while_statement)
|
||||||
|
(repeat_while_statement)
|
||||||
|
(do_statement)
|
||||||
|
(if_statement)
|
||||||
|
(guard_statement)
|
||||||
|
(switch_statement)
|
||||||
|
(property_declaration)
|
||||||
|
(function_declaration)
|
||||||
|
(class_declaration)
|
||||||
|
(protocol_declaration)
|
||||||
|
] @scope
|
||||||
Loading…
Add table
Add a link
Reference in a new issue