| 1 | ; Variables |
| 2 | |
| 3 | (identifier) @variable |
| 4 | |
| 5 | ; Parameters |
| 6 | |
| 7 | (parameter |
| 8 | name: (identifier) @variable.parameter) |
| 9 | |
| 10 | ; Types |
| 11 | |
| 12 | (parameter |
| 13 | type: (identifier) @type) |
| 14 | |
| 15 | ((identifier) @type |
| 16 | (#match? @type "^[A-Z_][a-zA-Z0-9_]*")) |
| 17 | |
| 18 | (variable_declaration |
| 19 | (identifier) @type |
| 20 | "=" |
| 21 | [ |
| 22 | (struct_declaration) |
| 23 | (enum_declaration) |
| 24 | (union_declaration) |
| 25 | (opaque_declaration) |
| 26 | ]) |
| 27 | |
| 28 | [ |
| 29 | (builtin_type) |
| 30 | "anyframe" |
| 31 | ] @type.builtin |
| 32 | |
| 33 | ; Constants |
| 34 | |
| 35 | ((identifier) @constant |
| 36 | (#match? @constant "^[A-Z][A-Z_0-9]+$")) |
| 37 | |
| 38 | [ |
| 39 | "null" |
| 40 | "unreachable" |
| 41 | "undefined" |
| 42 | ] @constant.builtin |
| 43 | |
| 44 | (field_expression |
| 45 | . |
| 46 | member: (identifier) @constant) |
| 47 | |
| 48 | (enum_declaration |
| 49 | (container_field |
| 50 | type: (identifier) @constant)) |
| 51 | |
| 52 | ; Labels |
| 53 | |
| 54 | (block_label (identifier) @label) |
| 55 | |
| 56 | (break_label (identifier) @label) |
| 57 | |
| 58 | ; Fields |
| 59 | |
| 60 | (field_initializer |
| 61 | . |
| 62 | (identifier) @variable.member) |
| 63 | |
| 64 | (field_expression |
| 65 | (_) |
| 66 | member: (identifier) @variable.member) |
| 67 | |
| 68 | (container_field |
| 69 | name: (identifier) @variable.member) |
| 70 | |
| 71 | (initializer_list |
| 72 | (assignment_expression |
| 73 | left: (field_expression |
| 74 | . |
| 75 | member: (identifier) @variable.member))) |
| 76 | |
| 77 | ; Functions |
| 78 | |
| 79 | (builtin_identifier) @function.builtin |
| 80 | |
| 81 | (call_expression |
| 82 | function: (identifier) @function.call) |
| 83 | |
| 84 | (call_expression |
| 85 | function: (field_expression |
| 86 | member: (identifier) @function.call)) |
| 87 | |
| 88 | (function_declaration |
| 89 | name: (identifier) @function) |
| 90 | |
| 91 | ; Modules |
| 92 | |
| 93 | (variable_declaration |
| 94 | (identifier) @module |
| 95 | (builtin_function |
| 96 | (builtin_identifier) @keyword.import |
| 97 | (#any-of? @keyword.import "@import" "@cImport"))) |
| 98 | |
| 99 | ; Builtins |
| 100 | |
| 101 | [ |
| 102 | "c" |
| 103 | "..." |
| 104 | ] @variable.builtin |
| 105 | |
| 106 | ((identifier) @variable.builtin |
| 107 | (#eq? @variable.builtin "_")) |
| 108 | |
| 109 | (calling_convention |
| 110 | (identifier) @variable.builtin) |
| 111 | |
| 112 | ; Keywords |
| 113 | |
| 114 | [ |
| 115 | "asm" |
| 116 | "defer" |
| 117 | "errdefer" |
| 118 | "test" |
| 119 | "error" |
| 120 | "const" |
| 121 | "var" |
| 122 | ] @keyword |
| 123 | |
| 124 | [ |
| 125 | "struct" |
| 126 | "union" |
| 127 | "enum" |
| 128 | "opaque" |
| 129 | ] @keyword.type |
| 130 | |
| 131 | [ |
| 132 | "async" |
| 133 | "await" |
| 134 | "suspend" |
| 135 | "nosuspend" |
| 136 | "resume" |
| 137 | ] @keyword.coroutine |
| 138 | |
| 139 | "fn" @keyword.function |
| 140 | |
| 141 | [ |
| 142 | "and" |
| 143 | "or" |
| 144 | "orelse" |
| 145 | ] @keyword.operator |
| 146 | |
| 147 | "return" @keyword.return |
| 148 | |
| 149 | [ |
| 150 | "if" |
| 151 | "else" |
| 152 | "switch" |
| 153 | ] @keyword.conditional |
| 154 | |
| 155 | [ |
| 156 | "for" |
| 157 | "while" |
| 158 | "break" |
| 159 | "continue" |
| 160 | ] @keyword.repeat |
| 161 | |
| 162 | [ |
| 163 | "usingnamespace" |
| 164 | "export" |
| 165 | ] @keyword.import |
| 166 | |
| 167 | [ |
| 168 | "try" |
| 169 | "catch" |
| 170 | ] @keyword.exception |
| 171 | |
| 172 | [ |
| 173 | "volatile" |
| 174 | "allowzero" |
| 175 | "noalias" |
| 176 | "addrspace" |
| 177 | "align" |
| 178 | "callconv" |
| 179 | "linksection" |
| 180 | "pub" |
| 181 | "inline" |
| 182 | "noinline" |
| 183 | "extern" |
| 184 | "comptime" |
| 185 | "packed" |
| 186 | "threadlocal" |
| 187 | ] @keyword.modifier |
| 188 | |
| 189 | ; Operator |
| 190 | |
| 191 | [ |
| 192 | "=" |
| 193 | "*=" |
| 194 | "*%=" |
| 195 | "*|=" |
| 196 | "/=" |
| 197 | "%=" |
| 198 | "+=" |
| 199 | "+%=" |
| 200 | "+|=" |
| 201 | "-=" |
| 202 | "-%=" |
| 203 | "-|=" |
| 204 | "<<=" |
| 205 | "<<|=" |
| 206 | ">>=" |
| 207 | "&=" |
| 208 | "^=" |
| 209 | "|=" |
| 210 | "!" |
| 211 | "~" |
| 212 | "-" |
| 213 | "-%" |
| 214 | "&" |
| 215 | "==" |
| 216 | "!=" |
| 217 | ">" |
| 218 | ">=" |
| 219 | "<=" |
| 220 | "<" |
| 221 | "&" |
| 222 | "^" |
| 223 | "|" |
| 224 | "<<" |
| 225 | ">>" |
| 226 | "<<|" |
| 227 | "+" |
| 228 | "++" |
| 229 | "+%" |
| 230 | "-%" |
| 231 | "+|" |
| 232 | "-|" |
| 233 | "*" |
| 234 | "/" |
| 235 | "%" |
| 236 | "**" |
| 237 | "*%" |
| 238 | "*|" |
| 239 | "||" |
| 240 | ".*" |
| 241 | ".?" |
| 242 | "?" |
| 243 | ".." |
| 244 | ] @operator |
| 245 | |
| 246 | ; Literals |
| 247 | |
| 248 | (character) @character |
| 249 | |
| 250 | ([ |
| 251 | (string) |
| 252 | (multiline_string) |
| 253 | ] @string |
| 254 | (#set! "priority" 95)) |
| 255 | |
| 256 | (integer) @number |
| 257 | |
| 258 | (float) @number.float |
| 259 | |
| 260 | (boolean) @boolean |
| 261 | |
| 262 | (escape_sequence) @string.escape |
| 263 | |
| 264 | ; Punctuation |
| 265 | |
| 266 | [ |
| 267 | "[" |
| 268 | "]" |
| 269 | "(" |
| 270 | ")" |
| 271 | "{" |
| 272 | "}" |
| 273 | ] @punctuation.bracket |
| 274 | |
| 275 | [ |
| 276 | ";" |
| 277 | "." |
| 278 | "," |
| 279 | ":" |
| 280 | "=>" |
| 281 | "->" |
| 282 | ] @punctuation.delimiter |
| 283 | |
| 284 | (payload "|" @punctuation.bracket) |
| 285 | |
| 286 | ; Comments |
| 287 | |
| 288 | (comment) @comment @spell |
| 289 | |
| 290 | ((comment) @comment.documentation |
| 291 | (#lua-match? @comment.documentation "^//!")) |