Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update languages.toml: tree-sitter-lua grammar #9727

Merged
merged 3 commits into from
Feb 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion languages.toml
Original file line number Diff line number Diff line change
Expand Up @@ -1101,7 +1101,7 @@ language-servers = [ "lua-language-server" ]

[[grammar]]
name = "lua"
source = { git = "https://github.com/MunifTanjim/tree-sitter-lua", rev = "887dfd4e83c469300c279314ff1619b1d0b85b91" }
source = { git = "https://github.com/tree-sitter-grammars/tree-sitter-lua", rev = "88e446476a1e97a8724dff7a23e2d709855077f2" }

[[language]]
name = "svelte"
Expand Down
81 changes: 68 additions & 13 deletions runtime/queries/lua/highlights.scm
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
;;; Highlighting for lua

;;; Builtins
((identifier) @variable.builtin
(#eq? @variable.builtin "self"))

;; Keywords

(if_statement
Expand Down Expand Up @@ -130,16 +126,65 @@
((identifier) @constant
(#match? @constant "^[A-Z][A-Z_0-9]*$"))

;; Parameters
(parameters
(identifier) @variable.parameter)
;; Tables

(field name: (identifier) @variable.other.member)

(dot_index_expression field: (identifier) @variable.other.member)

(table_constructor
[
"{"
"}"
] @constructor)

; ;; Functions
(function_declaration name: (identifier) @function)
(function_call name: (identifier) @function.call)
;; Functions

(function_declaration name: (dot_index_expression field: (identifier) @function))
(function_call name: (dot_index_expression field: (identifier) @function.call))
(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)
])

; TODO: incorrectly highlights variable N in `N, nop = 42, function() end`
(assignment_statement
Expand All @@ -153,6 +198,7 @@
;; Nodes
(comment) @comment
(string) @string
(escape_sequence) @constant.character.escape
(number) @constant.numeric.integer
(label_statement) @label
; A bit of a tricky one, this will only match field names
Expand All @@ -162,7 +208,16 @@
;; Property
(dot_index_expression field: (identifier) @variable.other.member)

;; Variable
;; Variables
((identifier) @variable.builtin
(#eq? @variable.builtin "self"))

(variable_list
(attribute
"<" @punctuation.bracket
(identifier) @attribute
">" @punctuation.bracket))

(identifier) @variable

;; Error
Expand Down
Loading