2021-12-18 08:40:34 +04:00
|
|
|
; CREDITS @stumash (stuart.mashaal@gmail.com)
|
|
|
|
|
|
|
|
;; variables
|
|
|
|
|
|
|
|
|
|
|
|
((identifier) @variable.builtin
|
|
|
|
(#match? @variable.builtin "^this$"))
|
|
|
|
|
|
|
|
(interpolation) @none
|
|
|
|
|
|
|
|
; Assume other uppercase names constants.
|
|
|
|
; NOTE: In order to distinguish constants we highlight
|
|
|
|
; all the identifiers that are uppercased. But this solution
|
|
|
|
; is not suitable for all occurrences e.g. it will highlight
|
|
|
|
; an uppercased method as a constant if used with no params.
|
|
|
|
; Introducing highlighting for those specific cases, is probably
|
|
|
|
; best way to resolve the issue.
|
|
|
|
((identifier) @constant (#match? @constant "^[A-Z]"))
|
|
|
|
|
|
|
|
;; types
|
|
|
|
|
|
|
|
(type_identifier) @type
|
|
|
|
|
|
|
|
(class_definition
|
|
|
|
name: (identifier) @type)
|
|
|
|
|
|
|
|
(object_definition
|
|
|
|
name: (identifier) @type)
|
|
|
|
|
|
|
|
(trait_definition
|
|
|
|
name: (identifier) @type)
|
|
|
|
|
|
|
|
(type_definition
|
|
|
|
name: (type_identifier) @type)
|
|
|
|
|
2023-01-16 19:48:17 +04:00
|
|
|
(full_enum_case
|
|
|
|
name: (identifier) @type)
|
|
|
|
|
|
|
|
(simple_enum_case
|
|
|
|
name: (identifier) @type)
|
|
|
|
|
|
|
|
;; val/var definitions/declarations
|
|
|
|
|
|
|
|
(val_definition
|
|
|
|
pattern: (identifier) @variable)
|
|
|
|
|
|
|
|
(var_definition
|
|
|
|
pattern: (identifier) @variable)
|
|
|
|
|
|
|
|
(val_declaration
|
|
|
|
name: (identifier) @variable)
|
|
|
|
|
|
|
|
(var_declaration
|
|
|
|
name: (identifier) @variable)
|
|
|
|
|
2021-12-18 08:40:34 +04:00
|
|
|
; method definition
|
|
|
|
|
|
|
|
(class_definition
|
|
|
|
body: (template_body
|
|
|
|
(function_definition
|
|
|
|
name: (identifier) @function.method)))
|
|
|
|
(object_definition
|
|
|
|
body: (template_body
|
|
|
|
(function_definition
|
|
|
|
name: (identifier) @function.method)))
|
|
|
|
(trait_definition
|
|
|
|
body: (template_body
|
|
|
|
(function_definition
|
|
|
|
name: (identifier) @function.method)))
|
|
|
|
|
2023-01-16 19:48:17 +04:00
|
|
|
; imports/exports
|
2021-12-18 08:40:34 +04:00
|
|
|
|
|
|
|
(import_declaration
|
|
|
|
path: (identifier) @namespace)
|
|
|
|
((stable_identifier (identifier) @namespace))
|
|
|
|
|
|
|
|
((import_declaration
|
|
|
|
path: (identifier) @type) (#match? @type "^[A-Z]"))
|
|
|
|
((stable_identifier (identifier) @type) (#match? @type "^[A-Z]"))
|
|
|
|
|
2023-01-16 19:48:17 +04:00
|
|
|
(export_declaration
|
|
|
|
path: (identifier) @namespace)
|
|
|
|
((stable_identifier (identifier) @namespace))
|
|
|
|
|
|
|
|
((export_declaration
|
|
|
|
path: (identifier) @type) (#match? @type "^[A-Z]"))
|
|
|
|
((stable_identifier (identifier) @type) (#match? @type "^[A-Z]"))
|
|
|
|
|
|
|
|
((namespace_selectors (identifier) @type) (#match? @type "^[A-Z]"))
|
2021-12-18 08:40:34 +04:00
|
|
|
|
|
|
|
; method invocation
|
|
|
|
|
|
|
|
|
|
|
|
(call_expression
|
|
|
|
function: (identifier) @function)
|
|
|
|
|
2023-01-16 19:48:17 +04:00
|
|
|
(call_expression
|
|
|
|
function: (operator_identifier) @function)
|
|
|
|
|
2021-12-18 08:40:34 +04:00
|
|
|
(call_expression
|
|
|
|
function: (field_expression
|
|
|
|
field: (identifier) @function.method))
|
|
|
|
|
2023-01-16 19:48:17 +04:00
|
|
|
(call_expression
|
|
|
|
function: (field_expression
|
|
|
|
field: (operator_identifier) @function.method))
|
|
|
|
|
2021-12-18 08:40:34 +04:00
|
|
|
((call_expression
|
|
|
|
function: (identifier) @variable.other.member)
|
|
|
|
(#match? @variable.other.member "^[A-Z]"))
|
|
|
|
|
|
|
|
(generic_function
|
|
|
|
function: (identifier) @function)
|
|
|
|
|
2023-01-19 21:26:12 +04:00
|
|
|
(interpolated_string_expression
|
|
|
|
interpolator: (identifier) @function)
|
|
|
|
|
2021-12-18 08:40:34 +04:00
|
|
|
(
|
|
|
|
(identifier) @function.builtin
|
|
|
|
(#match? @function.builtin "^super$")
|
|
|
|
)
|
|
|
|
|
|
|
|
; function definitions
|
|
|
|
|
|
|
|
(function_definition
|
|
|
|
name: (identifier) @function)
|
|
|
|
|
2023-01-16 19:48:17 +04:00
|
|
|
(function_definition
|
|
|
|
name: (operator_identifier) @function)
|
|
|
|
|
2021-12-18 08:40:34 +04:00
|
|
|
(parameter
|
|
|
|
name: (identifier) @variable.parameter)
|
|
|
|
|
2023-01-16 19:48:17 +04:00
|
|
|
(binding
|
|
|
|
name: (identifier) @variable.parameter)
|
|
|
|
|
2021-12-18 08:40:34 +04:00
|
|
|
; expressions
|
|
|
|
|
|
|
|
|
|
|
|
(field_expression field: (identifier) @variable.other.member)
|
|
|
|
(field_expression value: (identifier) @type
|
|
|
|
(#match? @type "^[A-Z]"))
|
|
|
|
|
|
|
|
(infix_expression operator: (identifier) @operator)
|
|
|
|
(infix_expression operator: (operator_identifier) @operator)
|
|
|
|
(infix_type operator: (operator_identifier) @operator)
|
|
|
|
(infix_type operator: (operator_identifier) @operator)
|
|
|
|
|
|
|
|
; literals
|
|
|
|
(boolean_literal) @constant.builtin.boolean
|
|
|
|
(integer_literal) @constant.numeric.integer
|
|
|
|
(floating_point_literal) @constant.numeric.float
|
|
|
|
|
|
|
|
|
|
|
|
(symbol_literal) @string.special.symbol
|
2023-01-16 19:48:17 +04:00
|
|
|
|
2021-12-18 08:40:34 +04:00
|
|
|
[
|
|
|
|
(string)
|
|
|
|
(character_literal)
|
|
|
|
(interpolated_string_expression)
|
|
|
|
] @string
|
|
|
|
|
|
|
|
(interpolation "$" @punctuation.special)
|
|
|
|
|
2023-01-16 19:48:17 +04:00
|
|
|
; annotations
|
|
|
|
|
|
|
|
(annotation) @attribute
|
|
|
|
|
2021-12-18 08:40:34 +04:00
|
|
|
;; keywords
|
|
|
|
|
2023-01-16 19:48:17 +04:00
|
|
|
;; storage in TextMate scope lingo means field or type
|
2021-12-18 08:40:34 +04:00
|
|
|
[
|
2023-01-16 19:48:17 +04:00
|
|
|
(opaque_modifier)
|
|
|
|
(infix_modifier)
|
|
|
|
(transparent_modifier)
|
|
|
|
(open_modifier)
|
2021-12-18 08:40:34 +04:00
|
|
|
"abstract"
|
|
|
|
"final"
|
|
|
|
"implicit"
|
|
|
|
"lazy"
|
|
|
|
"override"
|
|
|
|
"private"
|
|
|
|
"protected"
|
|
|
|
"sealed"
|
2023-01-16 19:48:17 +04:00
|
|
|
] @keyword.storage.modifier
|
|
|
|
|
|
|
|
[
|
|
|
|
"class"
|
|
|
|
"enum"
|
|
|
|
"extension"
|
|
|
|
"given"
|
|
|
|
"object"
|
|
|
|
"package"
|
2021-12-18 08:40:34 +04:00
|
|
|
"trait"
|
|
|
|
"type"
|
|
|
|
"val"
|
|
|
|
"var"
|
2023-01-16 19:48:17 +04:00
|
|
|
] @keyword.storage.type
|
|
|
|
|
|
|
|
[
|
|
|
|
"as"
|
|
|
|
"derives"
|
|
|
|
"end"
|
|
|
|
"extends"
|
|
|
|
;; `forSome` existential types not implemented yet
|
|
|
|
;; `macro` not implemented yet
|
|
|
|
;; `throws`
|
|
|
|
"using"
|
2021-12-18 08:40:34 +04:00
|
|
|
"with"
|
|
|
|
] @keyword
|
|
|
|
|
|
|
|
(null_literal) @constant.builtin
|
|
|
|
(wildcard) @keyword
|
|
|
|
|
|
|
|
;; special keywords
|
|
|
|
|
|
|
|
"new" @keyword.operator
|
|
|
|
|
|
|
|
[
|
2023-01-16 19:48:17 +04:00
|
|
|
"case"
|
|
|
|
"catch"
|
|
|
|
"else"
|
|
|
|
"finally"
|
|
|
|
"if"
|
|
|
|
"match"
|
|
|
|
"then"
|
|
|
|
"throw"
|
|
|
|
"try"
|
2021-12-18 08:40:34 +04:00
|
|
|
] @keyword.control.conditional
|
|
|
|
|
|
|
|
[
|
2023-01-16 19:48:17 +04:00
|
|
|
"("
|
|
|
|
")"
|
|
|
|
"["
|
|
|
|
"]"
|
|
|
|
"{"
|
|
|
|
"}"
|
2021-12-18 08:40:34 +04:00
|
|
|
] @punctuation.bracket
|
|
|
|
|
|
|
|
[
|
2023-01-16 19:48:17 +04:00
|
|
|
"."
|
|
|
|
","
|
2021-12-18 08:40:34 +04:00
|
|
|
] @punctuation.delimiter
|
|
|
|
|
|
|
|
[
|
2023-01-16 19:48:17 +04:00
|
|
|
"do"
|
|
|
|
"for"
|
|
|
|
"while"
|
|
|
|
"yield"
|
2021-12-18 08:40:34 +04:00
|
|
|
] @keyword.control.repeat
|
|
|
|
|
|
|
|
"def" @keyword.function
|
|
|
|
|
|
|
|
[
|
|
|
|
"=>"
|
|
|
|
"<-"
|
|
|
|
"@"
|
|
|
|
] @keyword.operator
|
|
|
|
|
|
|
|
"import" @keyword.control.import
|
|
|
|
|
2023-01-16 19:48:17 +04:00
|
|
|
"export" @keyword.control.import
|
|
|
|
|
2021-12-18 08:40:34 +04:00
|
|
|
"return" @keyword.control.return
|
|
|
|
|
|
|
|
(comment) @comment
|
|
|
|
|
|
|
|
;; `case` is a conditional keyword in case_block
|
|
|
|
|
|
|
|
(case_block
|
|
|
|
(case_clause ("case") @keyword.control.conditional))
|
|
|
|
|
2023-01-16 19:48:17 +04:00
|
|
|
(identifier) @variable
|
|
|
|
|
|
|
|
(operator_identifier) @operator
|