@@ -0,0 +1,203 @@
1+; CREDITS @stumash (stuart.mashaal@gmail.com)
2+
3+;; variables
4+
5+
6+((identifier) @variable.builtin
7+ (#match? @variable.builtin "^this$"))
8+
9+(interpolation) @none
10+
11+; Assume other uppercase names constants.
12+; NOTE: In order to distinguish constants we highlight
13+; all the identifiers that are uppercased. But this solution
14+; is not suitable for all occurrences e.g. it will highlight
15+; an uppercased method as a constant if used with no params.
16+; Introducing highlighting for those specific cases, is probably
17+; best way to resolve the issue.
18+((identifier) @constant (#match? @constant "^[A-Z]"))
19+
20+;; types
21+
22+(type_identifier) @type
23+
24+(class_definition
25+ name: (identifier) @type)
26+
27+(object_definition
28+ name: (identifier) @type)
29+
30+(trait_definition
31+ name: (identifier) @type)
32+
33+(type_definition
34+ name: (type_identifier) @type)
35+
36+; method definition
37+
38+(class_definition
39+ body: (template_body
40+ (function_definition
41+ name: (identifier) @function.method)))
42+(object_definition
43+ body: (template_body
44+ (function_definition
45+ name: (identifier) @function.method)))
46+(trait_definition
47+ body: (template_body
48+ (function_definition
49+ name: (identifier) @function.method)))
50+
51+; imports
52+
53+(import_declaration
54+ path: (identifier) @namespace)
55+((stable_identifier (identifier) @namespace))
56+
57+((import_declaration
58+ path: (identifier) @type) (#match? @type "^[A-Z]"))
59+((stable_identifier (identifier) @type) (#match? @type "^[A-Z]"))
60+
61+((import_selectors (identifier) @type) (#match? @type "^[A-Z]"))
62+
63+; method invocation
64+
65+
66+(call_expression
67+ function: (identifier) @function)
68+
69+(call_expression
70+ function: (field_expression
71+ field: (identifier) @function.method))
72+
73+((call_expression
74+ function: (identifier) @variable.other.member)
75+ (#match? @variable.other.member "^[A-Z]"))
76+
77+(generic_function
78+ function: (identifier) @function)
79+
80+(
81+ (identifier) @function.builtin
82+ (#match? @function.builtin "^super$")
83+)
84+
85+; function definitions
86+
87+(function_definition
88+ name: (identifier) @function)
89+
90+(parameter
91+ name: (identifier) @variable.parameter)
92+
93+; expressions
94+
95+
96+(field_expression field: (identifier) @variable.other.member)
97+(field_expression value: (identifier) @type
98+ (#match? @type "^[A-Z]"))
99+
100+(infix_expression operator: (identifier) @operator)
101+(infix_expression operator: (operator_identifier) @operator)
102+(infix_type operator: (operator_identifier) @operator)
103+(infix_type operator: (operator_identifier) @operator)
104+
105+; literals
106+(boolean_literal) @constant.builtin.boolean
107+(integer_literal) @constant.numeric.integer
108+(floating_point_literal) @constant.numeric.float
109+
110+
111+(symbol_literal) @string.special.symbol
112+
113+[
114+(string)
115+(character_literal)
116+(interpolated_string_expression)
117+] @string
118+
119+(interpolation "$" @punctuation.special)
120+
121+;; keywords
122+
123+[
124+ "abstract"
125+ "case"
126+ "class"
127+ "extends"
128+ "final"
129+ "finally"
130+;; `forSome` existential types not implemented yet
131+ "implicit"
132+ "lazy"
133+;; `macro` not implemented yet
134+ "object"
135+ "override"
136+ "package"
137+ "private"
138+ "protected"
139+ "sealed"
140+ "trait"
141+ "type"
142+ "val"
143+ "var"
144+ "with"
145+] @keyword
146+
147+(null_literal) @constant.builtin
148+(wildcard) @keyword
149+
150+;; special keywords
151+
152+"new" @keyword.operator
153+
154+[
155+ "else"
156+ "if"
157+ "match"
158+ "try"
159+ "catch"
160+ "throw"
161+] @keyword.control.conditional
162+
163+[
164+ "("
165+ ")"
166+ "["
167+ "]"
168+ "{"
169+ "}"
170+] @punctuation.bracket
171+
172+[
173+ "."
174+ ","
175+] @punctuation.delimiter
176+
177+[
178+ "do"
179+ "for"
180+ "while"
181+ "yield"
182+] @keyword.control.repeat
183+
184+"def" @keyword.function
185+
186+[
187+ "=>"
188+ "<-"
189+ "@"
190+] @keyword.operator
191+
192+"import" @keyword.control.import
193+
194+"return" @keyword.control.return
195+
196+(comment) @comment
197+
198+;; `case` is a conditional keyword in case_block
199+
200+(case_block
201+ (case_clause ("case") @keyword.control.conditional))
202+
203+(identifier) @variable