2021-09-01 17:54:21 +02:00
|
|
|
;;; Highlighting for lua
|
|
|
|
|
|
|
|
;; Keywords
|
|
|
|
|
|
|
|
(if_statement
|
|
|
|
[
|
|
|
|
"if"
|
|
|
|
"then"
|
|
|
|
"end"
|
|
|
|
] @keyword.control.conditional)
|
|
|
|
|
2022-10-12 15:45:56 +02:00
|
|
|
(elseif_statement
|
2021-09-01 17:54:21 +02:00
|
|
|
[
|
|
|
|
"elseif"
|
|
|
|
"then"
|
2022-10-12 15:45:56 +02:00
|
|
|
"end"
|
|
|
|
] @keyword.control.conditional)
|
2021-09-01 17:54:21 +02:00
|
|
|
|
2022-10-12 15:45:56 +02:00
|
|
|
(else_statement
|
2021-09-01 17:54:21 +02:00
|
|
|
[
|
2022-10-12 15:45:56 +02:00
|
|
|
"else"
|
2021-09-01 17:54:21 +02:00
|
|
|
"end"
|
2022-10-12 15:45:56 +02:00
|
|
|
] @keyword.control.conditional)
|
2021-09-01 17:54:21 +02:00
|
|
|
|
2022-10-12 15:45:56 +02:00
|
|
|
(for_statement
|
2021-09-01 17:54:21 +02:00
|
|
|
[
|
|
|
|
"for"
|
|
|
|
"do"
|
|
|
|
"end"
|
2021-09-03 03:39:30 +02:00
|
|
|
] @keyword.control.repeat)
|
2021-09-01 17:54:21 +02:00
|
|
|
|
|
|
|
(while_statement
|
|
|
|
[
|
|
|
|
"while"
|
|
|
|
"do"
|
|
|
|
"end"
|
2021-09-03 03:39:30 +02:00
|
|
|
] @keyword.control.repeat)
|
2021-09-01 17:54:21 +02:00
|
|
|
|
|
|
|
(repeat_statement
|
|
|
|
[
|
|
|
|
"repeat"
|
|
|
|
"until"
|
2021-09-03 03:39:30 +02:00
|
|
|
] @keyword.control.repeat)
|
2021-09-01 17:54:21 +02:00
|
|
|
|
|
|
|
(do_statement
|
|
|
|
[
|
|
|
|
"do"
|
|
|
|
"end"
|
|
|
|
] @keyword)
|
|
|
|
|
2022-10-12 15:45:56 +02:00
|
|
|
"return" @keyword.control.return
|
|
|
|
|
2021-09-01 17:54:21 +02:00
|
|
|
[
|
|
|
|
"in"
|
|
|
|
"local"
|
|
|
|
(break_statement)
|
|
|
|
"goto"
|
|
|
|
] @keyword
|
|
|
|
|
2022-10-12 15:45:56 +02:00
|
|
|
(function_declaration
|
|
|
|
[
|
|
|
|
"function"
|
|
|
|
"end"
|
|
|
|
] @keyword.function)
|
|
|
|
|
|
|
|
(function_definition
|
|
|
|
[
|
|
|
|
"function"
|
|
|
|
"end"
|
|
|
|
] @keyword.function)
|
|
|
|
|
2021-09-01 17:54:21 +02:00
|
|
|
;; Operators
|
|
|
|
|
|
|
|
[
|
|
|
|
"not"
|
|
|
|
"and"
|
|
|
|
"or"
|
2022-10-12 15:45:56 +02:00
|
|
|
] @keyword.operator
|
2021-09-01 17:54:21 +02:00
|
|
|
|
|
|
|
[
|
|
|
|
"="
|
|
|
|
"~="
|
|
|
|
"=="
|
|
|
|
"<="
|
|
|
|
">="
|
|
|
|
"<"
|
|
|
|
">"
|
|
|
|
"+"
|
|
|
|
"-"
|
|
|
|
"%"
|
|
|
|
"/"
|
|
|
|
"//"
|
|
|
|
"*"
|
|
|
|
"^"
|
|
|
|
"&"
|
|
|
|
"~"
|
|
|
|
"|"
|
|
|
|
">>"
|
|
|
|
"<<"
|
|
|
|
".."
|
|
|
|
"#"
|
|
|
|
] @operator
|
|
|
|
|
|
|
|
;; Punctuation
|
|
|
|
["," "." ":" ";"] @punctuation.delimiter
|
|
|
|
|
|
|
|
;; Brackets
|
2022-10-12 15:45:56 +02:00
|
|
|
|
2021-09-01 17:54:21 +02:00
|
|
|
[
|
|
|
|
"("
|
|
|
|
")"
|
|
|
|
"["
|
|
|
|
"]"
|
|
|
|
"{"
|
|
|
|
"}"
|
|
|
|
] @punctuation.bracket
|
|
|
|
|
|
|
|
; ;; Constants
|
|
|
|
[
|
|
|
|
(false)
|
|
|
|
(true)
|
2021-09-02 07:58:57 +02:00
|
|
|
] @constant.builtin.boolean
|
2021-09-01 17:54:21 +02:00
|
|
|
(nil) @constant.builtin
|
2022-10-12 15:45:56 +02:00
|
|
|
(vararg_expression) @constant
|
|
|
|
|
2021-09-01 17:54:21 +02:00
|
|
|
((identifier) @constant
|
|
|
|
(#match? @constant "^[A-Z][A-Z_0-9]*$"))
|
|
|
|
|
2024-02-28 20:55:17 +01:00
|
|
|
;; Tables
|
|
|
|
|
|
|
|
(field name: (identifier) @variable.other.member)
|
|
|
|
|
|
|
|
(dot_index_expression field: (identifier) @variable.other.member)
|
|
|
|
|
|
|
|
(table_constructor
|
|
|
|
[
|
|
|
|
"{"
|
|
|
|
"}"
|
|
|
|
] @constructor)
|
2021-09-01 17:54:21 +02:00
|
|
|
|
2024-02-28 20:55:17 +01:00
|
|
|
;; Functions
|
2021-09-01 17:54:21 +02:00
|
|
|
|
2024-02-28 20:55:17 +01:00
|
|
|
(parameters (identifier) @variable.parameter)
|
|
|
|
|
|
|
|
(function_call
|
|
|
|
(identifier) @function.builtin
|
|
|
|
(#any-of? @function.builtin
|
|
|
|
;; built-in functions in Lua 5.1
|
|
|
|
"assert" "collectgarbage" "dofile" "error" "getfenv" "getmetatable" "ipairs"
|
|
|
|
"load" "loadfile" "loadstring" "module" "next" "pairs" "pcall" "print"
|
|
|
|
"rawequal" "rawget" "rawset" "require" "select" "setfenv" "setmetatable"
|
|
|
|
"tonumber" "tostring" "type" "unpack" "xpcall"))
|
|
|
|
|
|
|
|
(function_declaration
|
|
|
|
name: [
|
|
|
|
(identifier) @function
|
|
|
|
(dot_index_expression
|
|
|
|
field: (identifier) @function)
|
|
|
|
])
|
|
|
|
|
|
|
|
(function_declaration
|
|
|
|
name: (method_index_expression
|
|
|
|
method: (identifier) @function.method))
|
|
|
|
|
|
|
|
(assignment_statement
|
|
|
|
(variable_list .
|
|
|
|
name: [
|
|
|
|
(identifier) @function
|
|
|
|
(dot_index_expression
|
|
|
|
field: (identifier) @function)
|
|
|
|
])
|
|
|
|
(expression_list .
|
|
|
|
value: (function_definition)))
|
|
|
|
|
|
|
|
(table_constructor
|
|
|
|
(field
|
|
|
|
name: (identifier) @function
|
|
|
|
value: (function_definition)))
|
|
|
|
|
|
|
|
(function_call
|
|
|
|
name: [
|
|
|
|
(identifier) @function.call
|
|
|
|
(dot_index_expression
|
|
|
|
field: (identifier) @function.call)
|
|
|
|
(method_index_expression
|
|
|
|
method: (identifier) @function.method.call)
|
|
|
|
])
|
2021-09-01 17:54:21 +02:00
|
|
|
|
2022-10-12 15:45:56 +02:00
|
|
|
; TODO: incorrectly highlights variable N in `N, nop = 42, function() end`
|
|
|
|
(assignment_statement
|
|
|
|
(variable_list
|
|
|
|
name: (identifier) @function)
|
|
|
|
(expression_list
|
|
|
|
value: (function_definition)))
|
2021-09-01 17:54:21 +02:00
|
|
|
|
2022-10-12 15:45:56 +02:00
|
|
|
(method_index_expression method: (identifier) @function.method)
|
2021-09-01 17:54:21 +02:00
|
|
|
|
|
|
|
;; Nodes
|
|
|
|
(comment) @comment
|
|
|
|
(string) @string
|
2024-02-28 20:55:17 +01:00
|
|
|
(escape_sequence) @constant.character.escape
|
2021-11-03 04:00:52 +01:00
|
|
|
(number) @constant.numeric.integer
|
2021-09-01 17:54:21 +02:00
|
|
|
(label_statement) @label
|
|
|
|
; A bit of a tricky one, this will only match field names
|
2021-11-03 04:00:52 +01:00
|
|
|
(field . (identifier) @variable.other.member (_))
|
2022-10-12 15:45:56 +02:00
|
|
|
(hash_bang_line) @comment
|
2021-09-01 17:54:21 +02:00
|
|
|
|
|
|
|
;; Property
|
2022-10-12 15:45:56 +02:00
|
|
|
(dot_index_expression field: (identifier) @variable.other.member)
|
2021-09-01 17:54:21 +02:00
|
|
|
|
2024-02-28 20:55:17 +01:00
|
|
|
;; Variables
|
|
|
|
((identifier) @variable.builtin
|
|
|
|
(#eq? @variable.builtin "self"))
|
|
|
|
|
|
|
|
(variable_list
|
|
|
|
(attribute
|
|
|
|
"<" @punctuation.bracket
|
|
|
|
(identifier) @attribute
|
|
|
|
">" @punctuation.bracket))
|
|
|
|
|
2021-09-01 17:54:21 +02:00
|
|
|
(identifier) @variable
|
|
|
|
|
|
|
|
;; Error
|
|
|
|
(ERROR) @error
|