summaryrefslogtreecommitdiff
path: root/runtime
diff options
context:
space:
mode:
authorBrian Dorsey2024-02-28 19:55:17 +0000
committerGitHub2024-02-28 19:55:17 +0000
commitf03b91d1b7907e78a4242c5b525e47c997f4457d (patch)
tree43934dfeb060f8fdfcfc436d25b16692f4dc9901 /runtime
parent083a9e775d31678f4d984c526e7140c0d2bb2312 (diff)
update languages.toml: tree-sitter-lua grammar (#9727)
* update languages.toml: tree-sitter-lua grammar repo has moved, use new URL and the rev of the latest release (v0.0.19) * update highlight queries a novice attempt to port query updates from the source repo to Helix captures and ordering * Apply suggestions from code review Co-authored-by: Michael Davis <mcarsondavis@gmail.com> --------- Co-authored-by: Michael Davis <mcarsondavis@gmail.com>
Diffstat (limited to 'runtime')
-rw-r--r--runtime/queries/lua/highlights.scm81
1 files changed, 68 insertions, 13 deletions
diff --git a/runtime/queries/lua/highlights.scm b/runtime/queries/lua/highlights.scm
index f48e607c..2f3b3c05 100644
--- a/runtime/queries/lua/highlights.scm
+++ b/runtime/queries/lua/highlights.scm
@@ -1,9 +1,5 @@
;;; Highlighting for lua
-;;; Builtins
-((identifier) @variable.builtin
- (#eq? @variable.builtin "self"))
-
;; Keywords
(if_statement
@@ -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
@@ -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
@@ -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