Skip to content

Commit fdcad31

Browse files
committed
feat(queries): sync with nvim-treesitter
1 parent 4f1c859 commit fdcad31

File tree

4 files changed

+389
-114
lines changed

4 files changed

+389
-114
lines changed

queries/highlights.scm

Lines changed: 158 additions & 97 deletions
Original file line numberDiff line numberDiff line change
@@ -1,128 +1,155 @@
1-
;; Keywords
2-
1+
; Keywords
32
"return" @keyword.return
43

54
[
6-
"goto"
7-
"in"
8-
"local"
5+
"goto"
6+
"in"
7+
"local"
98
] @keyword
109

11-
(label_statement) @label
12-
1310
(break_statement) @keyword
1411

1512
(do_statement
16-
[
17-
"do"
18-
"end"
19-
] @keyword)
13+
[
14+
"do"
15+
"end"
16+
] @keyword)
2017

2118
(while_statement
22-
[
23-
"while"
24-
"do"
25-
"end"
26-
] @repeat)
19+
[
20+
"while"
21+
"do"
22+
"end"
23+
] @keyword.repeat)
2724

2825
(repeat_statement
29-
[
30-
"repeat"
31-
"until"
32-
] @repeat)
26+
[
27+
"repeat"
28+
"until"
29+
] @keyword.repeat)
3330

3431
(if_statement
35-
[
36-
"if"
37-
"elseif"
38-
"else"
39-
"then"
40-
"end"
41-
] @conditional)
32+
[
33+
"if"
34+
"elseif"
35+
"else"
36+
"then"
37+
"end"
38+
] @keyword.conditional)
4239

4340
(elseif_statement
44-
[
45-
"elseif"
46-
"then"
47-
"end"
48-
] @conditional)
41+
[
42+
"elseif"
43+
"then"
44+
"end"
45+
] @keyword.conditional)
4946

5047
(else_statement
51-
[
52-
"else"
53-
"end"
54-
] @conditional)
48+
[
49+
"else"
50+
"end"
51+
] @keyword.conditional)
5552

5653
(for_statement
57-
[
58-
"for"
59-
"do"
60-
"end"
61-
] @repeat)
54+
[
55+
"for"
56+
"do"
57+
"end"
58+
] @keyword.repeat)
6259

6360
(function_declaration
64-
[
65-
"function"
66-
"end"
67-
] @keyword.function)
61+
[
62+
"function"
63+
"end"
64+
] @keyword.function)
6865

6966
(function_definition
70-
[
71-
"function"
72-
"end"
73-
] @keyword.function)
74-
75-
;; Operators
76-
77-
(binary_expression operator: _ @operator)
78-
79-
(unary_expression operator: _ @operator)
67+
[
68+
"function"
69+
"end"
70+
] @keyword.function)
8071

72+
; Operators
8173
[
82-
"and"
83-
"not"
84-
"or"
74+
"and"
75+
"not"
76+
"or"
8577
] @keyword.operator
8678

87-
;; Punctuations
88-
79+
[
80+
"+"
81+
"-"
82+
"*"
83+
"/"
84+
"%"
85+
"^"
86+
"#"
87+
"=="
88+
"~="
89+
"<="
90+
">="
91+
"<"
92+
">"
93+
"="
94+
"&"
95+
"~"
96+
"|"
97+
"<<"
98+
">>"
99+
"//"
100+
".."
101+
] @operator
102+
103+
; Punctuations
89104
[
90105
";"
91106
":"
107+
"::"
92108
","
93109
"."
94110
] @punctuation.delimiter
95111

96-
;; Brackets
97-
112+
; Brackets
98113
[
99-
"("
100-
")"
101-
"["
102-
"]"
103-
"{"
104-
"}"
114+
"("
115+
")"
116+
"["
117+
"]"
118+
"{"
119+
"}"
105120
] @punctuation.bracket
106121

107-
;; Variables
108-
122+
; Variables
109123
(identifier) @variable
110124

125+
((identifier) @constant.builtin
126+
(#eq? @constant.builtin "_VERSION"))
127+
111128
((identifier) @variable.builtin
112-
(#eq? @variable.builtin "self"))
129+
(#eq? @variable.builtin "self"))
130+
131+
((identifier) @module.builtin
132+
(#any-of? @module.builtin "_G" "debug" "io" "jit" "math" "os" "package" "string" "table" "utf8"))
133+
134+
((identifier) @keyword.coroutine
135+
(#eq? @keyword.coroutine "coroutine"))
113136

114137
(variable_list
115138
(attribute
116139
"<" @punctuation.bracket
117140
(identifier) @attribute
118141
">" @punctuation.bracket))
119142

120-
;; Constants
143+
; Labels
144+
(label_statement
145+
(identifier) @label)
121146

122-
((identifier) @constant
123-
(#match? @constant "^[A-Z][A-Z_0-9]*$"))
147+
(goto_statement
148+
(identifier) @label)
124149

125-
(vararg_expression) @constant
150+
; Constants
151+
((identifier) @constant
152+
(#lua-match? @constant "^[A-Z][A-Z_0-9]*$"))
126153

127154
(nil) @constant.builtin
128155

@@ -131,21 +158,24 @@
131158
(true)
132159
] @boolean
133160

134-
;; Tables
161+
; Tables
162+
(field
163+
name: (identifier) @property)
135164

136-
(field name: (identifier) @field)
137-
138-
(dot_index_expression field: (identifier) @field)
165+
(dot_index_expression
166+
field: (identifier) @variable.member)
139167

140168
(table_constructor
141-
[
142-
"{"
143-
"}"
144-
] @constructor)
169+
[
170+
"{"
171+
"}"
172+
] @constructor)
145173

146-
;; Functions
174+
; Functions
175+
(parameters
176+
(identifier) @variable.parameter)
147177

148-
(parameters (identifier) @parameter)
178+
(vararg_expression) @variable.parameter.builtin
149179

150180
(function_declaration
151181
name: [
@@ -156,16 +186,18 @@
156186

157187
(function_declaration
158188
name: (method_index_expression
159-
method: (identifier) @method))
189+
method: (identifier) @function.method))
160190

161191
(assignment_statement
162-
(variable_list .
192+
(variable_list
193+
.
163194
name: [
164195
(identifier) @function
165196
(dot_index_expression
166197
field: (identifier) @function)
167198
])
168-
(expression_list .
199+
(expression_list
200+
.
169201
value: (function_definition)))
170202

171203
(table_constructor
@@ -179,26 +211,55 @@
179211
(dot_index_expression
180212
field: (identifier) @function.call)
181213
(method_index_expression
182-
method: (identifier) @method.call)
214+
method: (identifier) @function.method.call)
183215
])
184216

185217
(function_call
186218
(identifier) @function.builtin
187219
(#any-of? @function.builtin
188-
;; built-in functions in Lua 5.1
189-
"assert" "collectgarbage" "dofile" "error" "getfenv" "getmetatable" "ipairs"
190-
"load" "loadfile" "loadstring" "module" "next" "pairs" "pcall" "print"
191-
"rawequal" "rawget" "rawset" "require" "select" "setfenv" "setmetatable"
192-
"tonumber" "tostring" "type" "unpack" "xpcall"))
220+
; built-in functions in Lua 5.1
221+
"assert" "collectgarbage" "dofile" "error" "getfenv" "getmetatable" "ipairs" "load" "loadfile"
222+
"loadstring" "module" "next" "pairs" "pcall" "print" "rawequal" "rawget" "rawlen" "rawset"
223+
"require" "select" "setfenv" "setmetatable" "tonumber" "tostring" "type" "unpack" "xpcall"
224+
"__add" "__band" "__bnot" "__bor" "__bxor" "__call" "__concat" "__div" "__eq" "__gc" "__idiv"
225+
"__index" "__le" "__len" "__lt" "__metatable" "__mod" "__mul" "__name" "__newindex" "__pairs"
226+
"__pow" "__shl" "__shr" "__sub" "__tostring" "__unm"))
193227

194-
;; Others
228+
; Others
229+
(comment) @comment @spell
195230

196-
(comment) @comment
231+
((comment) @comment.documentation
232+
(#lua-match? @comment.documentation "^[-][-][-]"))
197233

198-
(hash_bang_line) @preproc
234+
((comment) @comment.documentation
235+
(#lua-match? @comment.documentation "^[-][-](%s?)@"))
236+
237+
(hash_bang_line) @keyword.directive
199238

200239
(number) @number
201240

202241
(string) @string
203242

204243
(escape_sequence) @string.escape
244+
245+
; string.match("123", "%d+")
246+
(function_call
247+
(dot_index_expression
248+
field: (identifier) @_method
249+
(#any-of? @_method "find" "match" "gmatch" "gsub"))
250+
arguments: (arguments
251+
.
252+
(_)
253+
.
254+
(string
255+
content: (string_content) @string.regexp)))
256+
257+
;("123"):match("%d+")
258+
(function_call
259+
(method_index_expression
260+
method: (identifier) @_method
261+
(#any-of? @_method "find" "match" "gmatch" "gsub"))
262+
arguments: (arguments
263+
.
264+
(string
265+
content: (string_content) @string.regexp)))

0 commit comments

Comments
 (0)