Debian Codegraph @

runtime/queries/lua/highlights.scm

raw symbols SCIP
1 ;;; Highlighting for lua
2
3 ;; Keywords
4
5 (if_statement
6 [
7 "if"
8 "then"
9 "end"
10 ] @keyword.control.conditional)
11
12 (elseif_statement
13 [
14 "elseif"
15 "then"
16 "end"
17 ] @keyword.control.conditional)
18
19 (else_statement
20 [
21 "else"
22 "end"
23 ] @keyword.control.conditional)
24
25 (for_statement
26 [
27 "for"
28 "do"
29 "end"
30 ] @keyword.control.repeat)
31
32 (while_statement
33 [
34 "while"
35 "do"
36 "end"
37 ] @keyword.control.repeat)
38
39 (repeat_statement
40 [
41 "repeat"
42 "until"
43 ] @keyword.control.repeat)
44
45 (do_statement
46 [
47 "do"
48 "end"
49 ] @keyword)
50
51 "return" @keyword.control.return
52
53 [
54 "in"
55 "local"
56 "global"
57 (break_statement)
58 "goto"
59 ] @keyword
60
61 (function_declaration
62 [
63 "function"
64 "end"
65 ] @keyword.function)
66
67 (function_definition
68 [
69 "function"
70 "end"
71 ] @keyword.function)
72
73 ;; Operators
74
75 [
76 "not"
77 "and"
78 "or"
79 ] @keyword.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 ;; Punctuation
106 ["," "." ":" ";"] @punctuation.delimiter
107
108 ;; Brackets
109
110 [
111 "("
112 ")"
113 "["
114 "]"
115 "{"
116 "}"
117 ] @punctuation.bracket
118
119 ;; Variables
120 (identifier) @variable
121
122 ((identifier) @variable.builtin
123 (#eq? @variable.builtin "self"))
124
125 (variable_list
126 (attribute
127 "<" @punctuation.bracket
128 (identifier) @attribute
129 ">" @punctuation.bracket))
130
131 ; ;; Constants
132 [
133 (false)
134 (true)
135 ] @constant.builtin.boolean
136 (nil) @constant.builtin
137 (vararg_expression) @constant
138
139 ((identifier) @constant
140 (#match? @constant "^[A-Z][A-Z_0-9]*$"))
141
142 ;; Tables
143
144 (field name: (identifier) @variable.other.member)
145
146 (dot_index_expression field: (identifier) @variable.other.member)
147
148 ;; Functions
149
150 (parameters (identifier) @variable.parameter)
151
152 (function_call
153 (identifier) @function.builtin
154 (#any-of? @function.builtin
155 ;; built-in functions in Lua 5.1
156 "assert" "collectgarbage" "dofile" "error" "getfenv" "getmetatable" "ipairs"
157 "load" "loadfile" "loadstring" "module" "next" "pairs" "pcall" "print"
158 "rawequal" "rawget" "rawset" "require" "select" "setfenv" "setmetatable"
159 "tonumber" "tostring" "type" "unpack" "xpcall"))
160
161 (function_declaration
162 name: [
163 (identifier) @function
164 (dot_index_expression
165 field: (identifier) @function)
166 ])
167
168 (function_declaration
169 name: (method_index_expression
170 method: (identifier) @function.method))
171
172 (assignment_statement
173 (variable_list .
174 name: [
175 (identifier) @function
176 (dot_index_expression
177 field: (identifier) @function)
178 ])
179 (expression_list .
180 value: (function_definition)))
181
182 (table_constructor
183 (field
184 name: (identifier) @function
185 value: (function_definition)))
186
187 ;; Property
188 (dot_index_expression field: (identifier) @variable.other.member)
189
190 (function_call
191 name: [
192 (identifier) @function
193 (dot_index_expression
194 field: (identifier) @function)
195 (method_index_expression
196 method: (identifier) @function.method)
197 ])
198
199 ; TODO: incorrectly highlights variable N in `N, nop = 42, function() end`
200 (assignment_statement
201 (variable_list
202 name: (identifier) @function)
203 (expression_list
204 value: (function_definition)))
205
206 (method_index_expression method: (identifier) @function.method)
207
208 ;; Nodes
209 (comment) @comment
210 (string) @string
211 (escape_sequence) @constant.character.escape
212 (number) @constant.numeric.integer
213 (label_statement) @label
214 ; A bit of a tricky one, this will only match field names
215 (field . (identifier) @variable.other.member (_))
216 (hash_bang_line) @comment