|
1 | | -;; Keywords |
2 | | - |
| 1 | +; Keywords |
3 | 2 | "return" @keyword.return |
4 | 3 |
|
5 | 4 | [ |
6 | | - "goto" |
7 | | - "in" |
8 | | - "local" |
| 5 | + "goto" |
| 6 | + "in" |
| 7 | + "local" |
9 | 8 | ] @keyword |
10 | 9 |
|
11 | | -(label_statement) @label |
12 | | - |
13 | 10 | (break_statement) @keyword |
14 | 11 |
|
15 | 12 | (do_statement |
16 | | -[ |
17 | | - "do" |
18 | | - "end" |
19 | | -] @keyword) |
| 13 | + [ |
| 14 | + "do" |
| 15 | + "end" |
| 16 | + ] @keyword) |
20 | 17 |
|
21 | 18 | (while_statement |
22 | | -[ |
23 | | - "while" |
24 | | - "do" |
25 | | - "end" |
26 | | -] @repeat) |
| 19 | + [ |
| 20 | + "while" |
| 21 | + "do" |
| 22 | + "end" |
| 23 | + ] @keyword.repeat) |
27 | 24 |
|
28 | 25 | (repeat_statement |
29 | | -[ |
30 | | - "repeat" |
31 | | - "until" |
32 | | -] @repeat) |
| 26 | + [ |
| 27 | + "repeat" |
| 28 | + "until" |
| 29 | + ] @keyword.repeat) |
33 | 30 |
|
34 | 31 | (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) |
42 | 39 |
|
43 | 40 | (elseif_statement |
44 | | -[ |
45 | | - "elseif" |
46 | | - "then" |
47 | | - "end" |
48 | | -] @conditional) |
| 41 | + [ |
| 42 | + "elseif" |
| 43 | + "then" |
| 44 | + "end" |
| 45 | + ] @keyword.conditional) |
49 | 46 |
|
50 | 47 | (else_statement |
51 | | -[ |
52 | | - "else" |
53 | | - "end" |
54 | | -] @conditional) |
| 48 | + [ |
| 49 | + "else" |
| 50 | + "end" |
| 51 | + ] @keyword.conditional) |
55 | 52 |
|
56 | 53 | (for_statement |
57 | | -[ |
58 | | - "for" |
59 | | - "do" |
60 | | - "end" |
61 | | -] @repeat) |
| 54 | + [ |
| 55 | + "for" |
| 56 | + "do" |
| 57 | + "end" |
| 58 | + ] @keyword.repeat) |
62 | 59 |
|
63 | 60 | (function_declaration |
64 | | -[ |
65 | | - "function" |
66 | | - "end" |
67 | | -] @keyword.function) |
| 61 | + [ |
| 62 | + "function" |
| 63 | + "end" |
| 64 | + ] @keyword.function) |
68 | 65 |
|
69 | 66 | (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) |
80 | 71 |
|
| 72 | +; Operators |
81 | 73 | [ |
82 | | - "and" |
83 | | - "not" |
84 | | - "or" |
| 74 | + "and" |
| 75 | + "not" |
| 76 | + "or" |
85 | 77 | ] @keyword.operator |
86 | 78 |
|
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 |
89 | 104 | [ |
90 | 105 | ";" |
91 | 106 | ":" |
| 107 | + "::" |
92 | 108 | "," |
93 | 109 | "." |
94 | 110 | ] @punctuation.delimiter |
95 | 111 |
|
96 | | -;; Brackets |
97 | | - |
| 112 | +; Brackets |
98 | 113 | [ |
99 | | - "(" |
100 | | - ")" |
101 | | - "[" |
102 | | - "]" |
103 | | - "{" |
104 | | - "}" |
| 114 | + "(" |
| 115 | + ")" |
| 116 | + "[" |
| 117 | + "]" |
| 118 | + "{" |
| 119 | + "}" |
105 | 120 | ] @punctuation.bracket |
106 | 121 |
|
107 | | -;; Variables |
108 | | - |
| 122 | +; Variables |
109 | 123 | (identifier) @variable |
110 | 124 |
|
| 125 | +((identifier) @constant.builtin |
| 126 | + (#eq? @constant.builtin "_VERSION")) |
| 127 | + |
111 | 128 | ((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")) |
113 | 136 |
|
114 | 137 | (variable_list |
115 | 138 | (attribute |
116 | 139 | "<" @punctuation.bracket |
117 | 140 | (identifier) @attribute |
118 | 141 | ">" @punctuation.bracket)) |
119 | 142 |
|
120 | | -;; Constants |
| 143 | +; Labels |
| 144 | +(label_statement |
| 145 | + (identifier) @label) |
121 | 146 |
|
122 | | -((identifier) @constant |
123 | | - (#match? @constant "^[A-Z][A-Z_0-9]*$")) |
| 147 | +(goto_statement |
| 148 | + (identifier) @label) |
124 | 149 |
|
125 | | -(vararg_expression) @constant |
| 150 | +; Constants |
| 151 | +((identifier) @constant |
| 152 | + (#lua-match? @constant "^[A-Z][A-Z_0-9]*$")) |
126 | 153 |
|
127 | 154 | (nil) @constant.builtin |
128 | 155 |
|
|
131 | 158 | (true) |
132 | 159 | ] @boolean |
133 | 160 |
|
134 | | -;; Tables |
| 161 | +; Tables |
| 162 | +(field |
| 163 | + name: (identifier) @property) |
135 | 164 |
|
136 | | -(field name: (identifier) @field) |
137 | | - |
138 | | -(dot_index_expression field: (identifier) @field) |
| 165 | +(dot_index_expression |
| 166 | + field: (identifier) @variable.member) |
139 | 167 |
|
140 | 168 | (table_constructor |
141 | | -[ |
142 | | - "{" |
143 | | - "}" |
144 | | -] @constructor) |
| 169 | + [ |
| 170 | + "{" |
| 171 | + "}" |
| 172 | + ] @constructor) |
145 | 173 |
|
146 | | -;; Functions |
| 174 | +; Functions |
| 175 | +(parameters |
| 176 | + (identifier) @variable.parameter) |
147 | 177 |
|
148 | | -(parameters (identifier) @parameter) |
| 178 | +(vararg_expression) @variable.parameter.builtin |
149 | 179 |
|
150 | 180 | (function_declaration |
151 | 181 | name: [ |
|
156 | 186 |
|
157 | 187 | (function_declaration |
158 | 188 | name: (method_index_expression |
159 | | - method: (identifier) @method)) |
| 189 | + method: (identifier) @function.method)) |
160 | 190 |
|
161 | 191 | (assignment_statement |
162 | | - (variable_list . |
| 192 | + (variable_list |
| 193 | + . |
163 | 194 | name: [ |
164 | 195 | (identifier) @function |
165 | 196 | (dot_index_expression |
166 | 197 | field: (identifier) @function) |
167 | 198 | ]) |
168 | | - (expression_list . |
| 199 | + (expression_list |
| 200 | + . |
169 | 201 | value: (function_definition))) |
170 | 202 |
|
171 | 203 | (table_constructor |
|
179 | 211 | (dot_index_expression |
180 | 212 | field: (identifier) @function.call) |
181 | 213 | (method_index_expression |
182 | | - method: (identifier) @method.call) |
| 214 | + method: (identifier) @function.method.call) |
183 | 215 | ]) |
184 | 216 |
|
185 | 217 | (function_call |
186 | 218 | (identifier) @function.builtin |
187 | 219 | (#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")) |
193 | 227 |
|
194 | | -;; Others |
| 228 | +; Others |
| 229 | +(comment) @comment @spell |
195 | 230 |
|
196 | | -(comment) @comment |
| 231 | +((comment) @comment.documentation |
| 232 | + (#lua-match? @comment.documentation "^[-][-][-]")) |
197 | 233 |
|
198 | | -(hash_bang_line) @preproc |
| 234 | +((comment) @comment.documentation |
| 235 | + (#lua-match? @comment.documentation "^[-][-](%s?)@")) |
| 236 | + |
| 237 | +(hash_bang_line) @keyword.directive |
199 | 238 |
|
200 | 239 | (number) @number |
201 | 240 |
|
202 | 241 | (string) @string |
203 | 242 |
|
204 | 243 | (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