nvim-treesitter/runtime/queries/swift/highlights.scm

337 lines
4.8 KiB
Scheme
Raw Normal View History

2024-01-06 15:05:50 +09:00
[
"."
";"
":"
","
] @punctuation.delimiter
2024-01-06 15:05:50 +09:00
[
"("
")"
"["
"]"
"{"
"}"
] @punctuation.bracket
2022-01-16 11:04:18 +01:00
; Identifiers
(type_identifier) @type
2024-01-06 15:05:50 +09:00
[
(self_expression)
(super_expression)
] @variable.builtin
2022-01-16 11:04:18 +01:00
; Declarations
[
"func"
"deinit"
] @keyword.function
2022-10-28 17:20:26 +03:00
2022-01-16 11:04:18 +01:00
[
(visibility_modifier)
(member_modifier)
(function_modifier)
(property_modifier)
(parameter_modifier)
(inheritance_modifier)
2023-08-12 12:14:53 +02:00
(mutation_modifier)
] @keyword.modifier
2022-01-16 11:04:18 +01:00
(simple_identifier) @variable
2024-01-06 15:05:50 +09:00
(function_declaration
(simple_identifier) @function.method)
(protocol_function_declaration
name: (simple_identifier) @function.method)
2024-03-24 01:10:18 +01:00
(init_declaration
2024-01-06 15:05:50 +09:00
"init" @constructor)
(parameter
external_name: (simple_identifier) @variable.parameter)
(parameter
name: (simple_identifier) @variable.parameter)
(type_parameter
(type_identifier) @variable.parameter)
(inheritance_constraint
(identifier
(simple_identifier) @variable.parameter))
(equality_constraint
(identifier
(simple_identifier) @variable.parameter))
[
"protocol"
"extension"
"indirect"
"nonisolated"
"override"
"convenience"
"required"
"some"
2024-03-24 01:10:18 +01:00
"any"
"weak"
"unowned"
"didSet"
"willSet"
"subscript"
"let"
"var"
(throws)
(where_keyword)
(getter_specifier)
(setter_specifier)
(modify_specifier)
(else)
(as_operator)
] @keyword
2022-01-16 11:04:18 +01:00
2024-04-23 12:23:15 -07:00
[
"enum"
"struct"
"class"
"typealias"
] @keyword.type
[
"async"
"await"
] @keyword.coroutine
2024-06-10 10:05:10 -07:00
(shebang_line) @keyword.directive
2024-01-06 15:05:50 +09:00
(class_body
(property_declaration
(pattern
(simple_identifier) @variable.member)))
2024-01-06 15:05:50 +09:00
(protocol_property_declaration
(pattern
(simple_identifier) @variable.member))
2024-01-06 15:05:50 +09:00
2023-08-12 12:14:53 +02:00
(navigation_expression
2024-01-06 15:05:50 +09:00
(navigation_suffix
(simple_identifier) @variable.member))
2024-01-06 15:05:50 +09:00
2023-08-12 12:14:53 +02:00
(value_argument
name: (value_argument_label
(simple_identifier) @variable.member))
2022-01-16 11:04:18 +01:00
2024-01-06 15:05:50 +09:00
(import_declaration
"import" @keyword.import)
2022-01-16 11:04:18 +01:00
2024-01-06 15:05:50 +09:00
(enum_entry
"case" @keyword)
2022-01-16 11:04:18 +01:00
2024-03-24 01:10:18 +01:00
(modifiers
(attribute
"@" @attribute
2024-03-24 01:10:18 +01:00
(user_type
(type_identifier) @attribute)))
2024-03-24 01:10:18 +01:00
2022-01-16 11:04:18 +01:00
; Function calls
2024-01-06 15:05:50 +09:00
(call_expression
(simple_identifier) @function.call) ; foo()
(call_expression
; foo.bar.baz(): highlight the baz()
2022-01-16 11:04:18 +01:00
(navigation_expression
2024-01-06 15:05:50 +09:00
(navigation_suffix
(simple_identifier) @function.call)))
2023-08-12 12:14:53 +02:00
(call_expression
2024-01-06 15:05:50 +09:00
(prefix_expression
(simple_identifier) @function.call)) ; .foo()
2022-01-16 11:04:18 +01:00
((navigation_expression
2024-01-06 15:05:50 +09:00
(simple_identifier) @type) ; SomeType.method(): highlight SomeType as a type
(#lua-match? @type "^[A-Z]"))
2022-01-16 11:04:18 +01:00
(directive) @keyword.directive
2024-01-06 15:05:50 +09:00
; See https://docs.swift.org/swift-book/documentation/the-swift-programming-language/lexicalstructure/#Keywords-and-Punctuation
[
(diagnostic)
(availability_condition)
(playground_literal)
(key_path_string_expression)
(selector_expression)
(external_macro_definition)
] @function.macro
(special_literal) @constant.macro
2022-01-16 11:04:18 +01:00
; Statements
2024-01-06 15:05:50 +09:00
(for_statement
"for" @keyword.repeat)
(for_statement
"in" @keyword.repeat)
[
"while"
"repeat"
"continue"
"break"
] @keyword.repeat
(guard_statement
"guard" @keyword.conditional)
(if_statement
"if" @keyword.conditional)
2022-01-16 11:04:18 +01:00
2024-01-06 15:05:50 +09:00
(switch_statement
"switch" @keyword.conditional)
(switch_entry
"case" @keyword)
(switch_entry
"fallthrough" @keyword)
(switch_entry
(default_keyword) @keyword)
2022-01-16 11:04:18 +01:00
"return" @keyword.return
2024-01-06 15:05:50 +09:00
(ternary_expression
2024-01-06 15:05:50 +09:00
[
"?"
":"
] @keyword.conditional.ternary)
2022-01-16 11:04:18 +01:00
2024-01-06 15:05:50 +09:00
[
(try_operator)
2024-01-06 15:05:50 +09:00
"do"
(throw_keyword)
(catch_keyword)
] @keyword.exception
2022-01-16 11:04:18 +01:00
(statement_label) @label
; Comments
2022-09-26 10:19:02 +01:00
[
2024-01-06 15:05:50 +09:00
(comment)
(multiline_comment)
2022-09-26 10:19:02 +01:00
] @comment @spell
2022-01-16 11:04:18 +01:00
((comment) @comment.documentation
(#lua-match? @comment.documentation "^///[^/]"))
((comment) @comment.documentation
(#lua-match? @comment.documentation "^///$"))
((multiline_comment) @comment.documentation
(#lua-match? @comment.documentation "^/[*][*][^*].*[*]/$"))
2022-01-16 11:04:18 +01:00
; String literals
(line_str_text) @string
2024-01-06 15:05:50 +09:00
(str_escaped_char) @string.escape
2024-01-06 15:05:50 +09:00
2022-01-16 11:04:18 +01:00
(multi_line_str_text) @string
2024-01-06 15:05:50 +09:00
2022-01-16 11:04:18 +01:00
(raw_str_part) @string
2024-01-06 15:05:50 +09:00
2022-01-16 11:04:18 +01:00
(raw_str_end_part) @string
2024-01-06 15:05:50 +09:00
(line_string_literal
[
"\\("
")"
] @punctuation.special)
(multi_line_string_literal
[
"\\("
")"
] @punctuation.special)
(raw_str_interpolation
[
(raw_str_interpolation_start)
")"
] @punctuation.special)
2024-01-06 15:05:50 +09:00
[
"\""
"\"\"\""
] @string
2022-01-16 11:04:18 +01:00
; Lambda literals
2024-01-06 15:05:50 +09:00
(lambda_literal
"in" @keyword.operator)
2022-01-16 11:04:18 +01:00
; Basic literals
[
2024-01-06 15:05:50 +09:00
(integer_literal)
(hex_literal)
(oct_literal)
(bin_literal)
2022-01-16 11:04:18 +01:00
] @number
2024-01-06 15:05:50 +09:00
feat!: align standard captures with upstream Problem: Sharing highlight queries with upstream tree-sitter and Helix is difficult. Solution: Where reasonable, use capture names in tree-sitter's standard list or Helix's Atom-style hierarchy. Specifically: * tree-sitter "standard capture names" (https://github.com/tree-sitter/tree-sitter/blob/3f44b896852eb7daaa6df4fb778c9bb52c70c815/highlight/src/lib.rs#L20-L72): - `@parameter` -> `@variable.parameter` - `@field` -> `@variable.member` - `@namespace` -> `@module` - `@float` -> `@number.float` - `@symbol` -> `@string.special.symbol` - `@string.regex` -> `@string.regexp` - `@text.*` -> `@markup.*` (`strong`, `italic`, `link`, `strikethrough`; with exceptions; see below) - `@text.title` -> `@markup.heading` - `@text.literal` -> `@markup.raw` - `@text.reference` -> `@markup.link` - `@text.uri` -> `@markup.link.url` (in markup links) - `@string.special` -> `@markup.link.label` (non-url links) - `@punctuation.special` -> `@markup.list` (markdown lists only; move subitems from `@text.todo`) * Helix captures (https://docs.helix-editor.com/master/themes.html#syntax-highlighting): - `@method` -> `@function.method` - `@method.call` -> `@function.method.call` - `@text.{todo,warning,note,danger}` -> `@comment.{error,warning,hint,info,todo}` - `@text.diff.{add,delete,}` -> `@diff.{plus,minus,delta}` - `@text.uri` -> `@string.special.url` (outside markup) - `@preproc` -> `@keyword.directive` - `@define` -> `@keyword.directive`(`.define`?) - `@storageclass` -> `@keyword.storage` - `@conditional` -> `@keyword.conditional` - `@debug` -> `@keyword.debug` - `@exception` -> `@keyword.exception` - `@include` -> `@keyword.import` - `@repeat` -> `@keyword.repeat` * cleanup - remove some redundant `@conceal` (but still allow it for conceal-only patterns) - remove obsolete `@error` (syntax linting is out of scope for this repo) - sort, cleanup capture list in `CONTRIBUTING.md`
2023-12-24 10:00:20 +01:00
(real_literal) @number.float
2024-01-06 15:05:50 +09:00
2022-01-16 11:04:18 +01:00
(boolean_literal) @boolean
2024-01-06 15:05:50 +09:00
2022-10-28 17:20:26 +03:00
"nil" @constant.builtin
2022-01-16 11:04:18 +01:00
(wildcard_pattern) @character.special
; Regex literals
feat!: align standard captures with upstream Problem: Sharing highlight queries with upstream tree-sitter and Helix is difficult. Solution: Where reasonable, use capture names in tree-sitter's standard list or Helix's Atom-style hierarchy. Specifically: * tree-sitter "standard capture names" (https://github.com/tree-sitter/tree-sitter/blob/3f44b896852eb7daaa6df4fb778c9bb52c70c815/highlight/src/lib.rs#L20-L72): - `@parameter` -> `@variable.parameter` - `@field` -> `@variable.member` - `@namespace` -> `@module` - `@float` -> `@number.float` - `@symbol` -> `@string.special.symbol` - `@string.regex` -> `@string.regexp` - `@text.*` -> `@markup.*` (`strong`, `italic`, `link`, `strikethrough`; with exceptions; see below) - `@text.title` -> `@markup.heading` - `@text.literal` -> `@markup.raw` - `@text.reference` -> `@markup.link` - `@text.uri` -> `@markup.link.url` (in markup links) - `@string.special` -> `@markup.link.label` (non-url links) - `@punctuation.special` -> `@markup.list` (markdown lists only; move subitems from `@text.todo`) * Helix captures (https://docs.helix-editor.com/master/themes.html#syntax-highlighting): - `@method` -> `@function.method` - `@method.call` -> `@function.method.call` - `@text.{todo,warning,note,danger}` -> `@comment.{error,warning,hint,info,todo}` - `@text.diff.{add,delete,}` -> `@diff.{plus,minus,delta}` - `@text.uri` -> `@string.special.url` (outside markup) - `@preproc` -> `@keyword.directive` - `@define` -> `@keyword.directive`(`.define`?) - `@storageclass` -> `@keyword.storage` - `@conditional` -> `@keyword.conditional` - `@debug` -> `@keyword.debug` - `@exception` -> `@keyword.exception` - `@include` -> `@keyword.import` - `@repeat` -> `@keyword.repeat` * cleanup - remove some redundant `@conceal` (but still allow it for conceal-only patterns) - remove obsolete `@error` (syntax linting is out of scope for this repo) - sort, cleanup capture list in `CONTRIBUTING.md`
2023-12-24 10:00:20 +01:00
(regex_literal) @string.regexp
2022-01-16 11:04:18 +01:00
; Operators
(custom_operator) @operator
2024-01-06 15:05:50 +09:00
2022-01-16 11:04:18 +01:00
[
2024-01-06 15:05:50 +09:00
"+"
"-"
"*"
"/"
"%"
"="
"+="
"-="
"*="
"/="
"<"
">"
"<<"
">>"
2024-01-06 15:05:50 +09:00
"<="
">="
"++"
"--"
"^"
2024-01-06 15:05:50 +09:00
"&"
2024-03-24 01:10:18 +01:00
"&&"
"|"
"||"
2024-01-06 15:05:50 +09:00
"~"
"%="
"!="
"!=="
"=="
"==="
"?"
2024-01-06 15:05:50 +09:00
"??"
"->"
"..<"
"..."
2023-08-12 12:14:53 +02:00
(bang)
2022-01-16 11:04:18 +01:00
] @operator
(type_arguments
[
"<"
">"
] @punctuation.bracket)