1;; Keywords
2
3"return" @keyword
4
5[
6 "goto"
7 "in"
8 "local"
9] @keyword
10
11(break_statement) @keyword
12
13(do_statement
14[
15 "do"
16 "end"
17] @keyword)
18
19(while_statement
20[
21 "while"
22 "do"
23 "end"
24] @keyword)
25
26(repeat_statement
27[
28 "repeat"
29 "until"
30] @keyword)
31
32(if_statement
33[
34 "if"
35 "elseif"
36 "else"
37 "then"
38 "end"
39] @keyword)
40
41(elseif_statement
42[
43 "elseif"
44 "then"
45 "end"
46] @keyword)
47
48(else_statement
49[
50 "else"
51 "end"
52] @keyword)
53
54(for_statement
55[
56 "for"
57 "do"
58 "end"
59] @keyword)
60
61(function_declaration
62[
63 "function"
64 "end"
65] @keyword)
66
67(function_definition
68[
69 "function"
70 "end"
71] @keyword)
72
73;; Operators
74
75[
76 "and"
77 "not"
78 "or"
79] @operator
80
81[
82 "+"
83 "-"
84 "*"
85 "/"
86 "%"
87 "^"
88 "#"
89 "=="
90 "~="
91 "<="
92 ">="
93 "<"
94 ">"
95 "="
96 "&"
97 "~"
98 "|"
99 "<<"
100 ">>"
101 "//"
102 ".."
103] @operator
104
105;; Punctuations
106
107[
108 ";"
109 ":"
110 ","
111 "."
112] @punctuation.delimiter
113
114;; Brackets
115
116[
117 "("
118 ")"
119 "["
120 "]"
121 "{"
122 "}"
123] @punctuation.bracket
124
125;; Variables
126
127(identifier) @variable
128
129((identifier) @variable.special
130 (#eq? @variable.special "self"))
131
132(variable_list
133 attribute: (attribute
134 (["<" ">"] @punctuation.bracket
135 (identifier) @attribute)))
136
137;; Constants
138
139((identifier) @constant
140 (#match? @constant "^[A-Z][A-Z_0-9]*$"))
141
142(vararg_expression) @constant
143
144(nil) @constant.builtin
145
146[
147 (false)
148 (true)
149] @boolean
150
151;; Tables
152
153(field name: (identifier) @property)
154
155(dot_index_expression field: (identifier) @property)
156
157(table_constructor
158[
159 "{"
160 "}"
161] @constructor)
162
163;; Functions
164
165(parameters (identifier) @parameter)
166
167(function_call
168 name: [
169 (identifier) @function
170 (dot_index_expression field: (identifier) @function)
171 ])
172
173(function_declaration
174 name: [
175 (identifier) @function.definition
176 (dot_index_expression field: (identifier) @function.definition)
177 ])
178
179(method_index_expression method: (identifier) @function.method)
180
181(function_call
182 (identifier) @function.builtin
183 (#any-of? @function.builtin
184 ;; built-in functions in Lua 5.1
185 "assert" "collectgarbage" "dofile" "error" "getfenv" "getmetatable" "ipairs"
186 "load" "loadfile" "loadstring" "module" "next" "pairs" "pcall" "print"
187 "rawequal" "rawget" "rawset" "require" "select" "setfenv" "setmetatable"
188 "tonumber" "tostring" "type" "unpack" "xpcall"))
189
190;; Others
191
192(comment) @comment
193
194(hash_bang_line) @preproc
195
196(number) @number
197
198(string) @string
199(escape_sequence) @string.escape