Unnamed repository; edit this file 'description' to name the repository.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170

;; Primitives
(boolean) @constant.builtin.boolean
(comment) @comment
(shebang_comment) @comment
(identifier) @variable
((identifier) @variable.builtin
  (#eq? @variable.builtin "self"))
(nil) @constant.builtin
(number) @constant.numeric
(string) @string
(table_constructor ["{" "}"] @constructor)
(varargs "..." @constant.builtin)
[ "," "." ":" ";" ] @punctuation.delimiter

(escape_sequence) @constant.character.escape
(format_specifier) @constant.character.escape

;; Basic statements/Keywords
[ "if" "then" "elseif" "else" ] @keyword.control.conditional
[ "for" "while" "repeat" "until" "do" ] @keyword.control.repeat
[ "end" ] @keyword
[ "in" ] @keyword.operator
[ "local" ] @keyword.storage.type
[ (break) (goto) ] @keyword.control
[ "return" ] @keyword.control.return
(label) @label

;; Global isn't a real keyword, but it gets special treatment in these places
(var_declaration "global" @keyword.storage.type)
(type_declaration "global" @keyword.storage.type)
(function_statement "global" @keyword.storage.type)
(record_declaration "global" @keyword.storage.type)
(interface_declaration "global" @keyword.storage.type)
(enum_declaration "global" @keyword.storage.type)

(macroexp_statement "macroexp" @keyword)

;; Ops
(bin_op (op) @operator)
(unary_op (op) @operator)
[ "=" "as" ] @operator

;; Functions
(function_statement
  "function" @keyword.function
  . name: (_) @function)
(anon_function
  "function" @keyword.function)
(function_body "end" @keyword.function)

(arg name: (identifier) @variable.parameter)

(function_signature
  (arguments
    . (arg name: (identifier) @variable.builtin))
  (#eq? @variable.builtin "self"))

(typeargs
  "<" @punctuation.bracket
  . (_) @type.parameter
  . ("," . (_) @type.parameter)*
  . ">" @punctuation.bracket)

(function_call
  (identifier) @function . (arguments))
(function_call
  (index (_) key: (identifier) @function) . (arguments))
(function_call
  (method_index (_) key: (identifier) @function) . (arguments))

;; Types

; Contextual keywords in record bodies
(record_declaration
  . [ "record" ] @keyword.storage.type
  name: (identifier) @type)
(anon_record . "record" @keyword.storage.type)
(record_body
  (record_declaration
    . [ "record" ] @keyword.storage.type
    . name: (identifier) @type))
(record_body
  (enum_declaration
    . [ "enum" ] @keyword.storage.type
    . name: (identifier) @type.enum))
(record_body
  (interface_declaration
    . [ "interface" ] @keyword.storage.type
    . name: (identifier) @type))
(record_body
  (typedef
    . "type" @keyword.storage.type
    . name: (identifier) @type . "="))
(record_body
  (macroexp_declaration
    . [ "macroexp" ] @keyword.storage.type))
(record_body (metamethod "metamethod" @keyword.storage.modifier))
(record_body (userdata) @keyword.storage.modifier)

; Contextual keywords in interface bodies
(interface_declaration
  . [ "interface" ] @keyword.storage.type
  name: (identifier) @type)
(anon_interface . "interface" @keyword.storage.type)
(interface_body
  (record_declaration
    . [ "record" ] @keyword.storage.type
    . name: (identifier) @type))
(interface_body
  (enum_declaration
    . [ "enum" ] @keyword.storage.type
    . name: (identifier) @type.enum))
(interface_body
  (interface_declaration
    . [ "interface" ] @keyword.storage.type
    . name: (identifier) @type))
(interface_body
  (typedef
    . "type" @keyword.storage.type
    . name: (identifier) @type . "="))
(interface_body
  (macroexp_declaration
    . [ "macroexp" ] @keyword.storage.type))
(interface_body (metamethod "metamethod" @keyword.storage.modifier))
(interface_body (userdata) @keyword.storage.modifier)

(enum_declaration
  "enum" @keyword.storage.type
  name: (identifier) @type.enum)

(type_declaration "type" @keyword.storage.type)
(type_declaration (identifier) @type)
(simple_type) @type
(type_index) @type
(type_union "|" @operator)
(function_type "function" @type)

;; The rest of it
(var_declaration
  declarators: (var_declarators
      (var name: (identifier) @variable)))
(var_declaration
  declarators: (var_declarators
    (var
      "<" @punctuation.bracket
      . attribute: (attribute) @attribute
      . ">" @punctuation.bracket)))
[ "(" ")" "[" "]" "{" "}" ] @punctuation.bracket

;; Only highlight format specifiers in calls to string.format
;; string.format('...')
;(function_call
;  called_object: (index
;    (identifier) @base
;    key: (identifier) @entry)
;  arguments: (arguments .
;    (string (format_specifier) @string.escape))
;
;  (#eq? @base "string")
;  (#eq? @entry "format"))

;; ('...'):format()
;(function_call
;  called_object: (method_index
;    (string (format_specifier) @string.escape)
;    key: (identifier) @func-name)
;    (#eq? @func-name "format"))