nvim-treesitter/queries/lua/highlights.scm
Santos Gallegos 989fc7aa6c Lua: highlight function definitions
In lua

```lua
function foo() end
```

is syntax sugar for

```lua
foo = function() end
```
2021-07-07 23:17:43 +02:00

154 lines
1.8 KiB
Scheme

;;; Highlighting for lua
;;; Builtins
(self) @variable.builtin
;; Keywords
(if_statement
[
"if"
"then"
"end"
] @conditional)
[
"else"
"elseif"
"then"
] @conditional
(for_statement
[
"for"
"do"
"end"
] @repeat)
(for_in_statement
[
"for"
"do"
"end"
] @repeat)
(while_statement
[
"while"
"do"
"end"
] @repeat)
(repeat_statement
[
"repeat"
"until"
] @repeat)
(do_statement
[
"do"
"end"
] @keyword)
[
"in"
"local"
(break_statement)
"goto"
] @keyword
"return" @keyword.return
;; Operators
[
"not"
"and"
"or"
] @keyword.operator
[
"="
"~="
"=="
"<="
">="
"<"
">"
"+"
"-"
"%"
"/"
"//"
"*"
"^"
"&"
"~"
"|"
">>"
"<<"
".."
"#"
] @operator
;; Punctuation
[ "," "." ":"] @punctuation.delimiter
;; Brackets
[
"("
")"
"["
"]"
"{"
"}"
] @punctuation.bracket
;; Variables
(identifier) @variable
;; Constants
[
(false)
(true)
] @boolean
(nil) @constant.builtin
(spread) @constant ;; "..."
;; Functions
(function [(function_name) (identifier)] @function)
(function ["function" "end"] @keyword.function)
(local_function (identifier) @function)
(local_function ["function" "end"] @keyword.function)
(variable_declaration
(variable_declarator (identifier) @function) (function_definition))
(local_variable_declaration
(variable_declarator (identifier) @function) (function_definition))
(function_definition ["function" "end"] @keyword.function)
(property_identifier) @property
(method) @method
(function_call (identifier) @function . (arguments))
(function_call (field_expression (property_identifier) @function) . (arguments))
;; Parameters
(parameters
(identifier) @parameter)
;; Nodes
(table ["{" "}"] @constructor)
(comment) @comment
(string) @string
(number) @number
(label_statement) @label
; A bit of a tricky one, this will only match field names
(field . (identifier) @field (_))
(shebang) @comment
;; Error
(ERROR) @error