Unnamed repository; edit this file 'description' to name the repository.
Diffstat (limited to 'runtime/queries/lua/highlights.scm')
| -rw-r--r-- | runtime/queries/lua/highlights.scm | 155 |
1 files changed, 50 insertions, 105 deletions
diff --git a/runtime/queries/lua/highlights.scm b/runtime/queries/lua/highlights.scm index 43e45b27..40c2be70 100644 --- a/runtime/queries/lua/highlights.scm +++ b/runtime/queries/lua/highlights.scm @@ -1,5 +1,8 @@ ;;; Highlighting for lua +;;; Builtins +(self) @variable.builtin + ;; Keywords (if_statement @@ -9,20 +12,20 @@ "end" ] @keyword.control.conditional) -(elseif_statement [ + "else" "elseif" "then" - "end" -] @keyword.control.conditional) +] @keyword.control.conditional -(else_statement +(for_statement [ - "else" + "for" + "do" "end" -] @keyword.control.conditional) +] @keyword.control.repeat) -(for_statement +(for_in_statement [ "for" "do" @@ -48,34 +51,21 @@ "end" ] @keyword) -"return" @keyword.control.return - [ "in" "local" (break_statement) "goto" + "return" ] @keyword -(function_declaration -[ - "function" - "end" -] @keyword.function) - -(function_definition -[ - "function" - "end" -] @keyword.function) - ;; Operators [ "not" "and" "or" -] @keyword.operator +] @operator [ "=" @@ -105,7 +95,6 @@ ["," "." ":" ";"] @punctuation.delimiter ;; Brackets - [ "(" ")" @@ -115,107 +104,63 @@ "}" ] @punctuation.bracket -;; Variables -(identifier) @variable - -((identifier) @variable.builtin - (#eq? @variable.builtin "self")) - -(variable_list - (attribute - "<" @punctuation.bracket - (identifier) @attribute - ">" @punctuation.bracket)) - ; ;; Constants [ (false) (true) ] @constant.builtin.boolean (nil) @constant.builtin -(vararg_expression) @constant - +(spread) @constant ;; "..." ((identifier) @constant (#match? @constant "^[A-Z][A-Z_0-9]*$")) -;; Tables +;; Parameters +(parameters + (identifier) @variable.parameter) -(field name: (identifier) @variable.other.member) +; ;; Functions +(function [(function_name) (identifier)] @function) +(function ["function" "end"] @keyword.function) -(dot_index_expression field: (identifier) @variable.other.member) +(function + (function_name + (function_name_field + (property_identifier) @function .))) -(table_constructor -[ - "{" - "}" -] @constructor) +(local_function (identifier) @function) +(local_function ["function" "end"] @keyword.function) -;; Functions +(variable_declaration + (variable_declarator (identifier) @function) (function_definition)) +(local_variable_declaration + (variable_declarator (identifier) @function) (function_definition)) -(parameters (identifier) @variable.parameter) +(function_definition ["function" "end"] @keyword.function) (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))) - -;; Property -(dot_index_expression field: (identifier) @variable.other.member) - -(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 - (variable_list - name: (identifier) @function) - (expression_list - value: (function_definition))) - -(method_index_expression method: (identifier) @function.method) + [ + ((identifier) @variable (method) @function.method) + ((_) (method) @function.method) + (identifier) @function + (field_expression (property_identifier) @function) + ] + . (arguments)) ;; Nodes +(table ["{" "}"] @constructor) (comment) @comment (string) @string -(escape_sequence) @constant.character.escape -(number) @constant.numeric.integer +(number) @number (label_statement) @label ; A bit of a tricky one, this will only match field names -(field . (identifier) @variable.other.member (_)) -(hash_bang_line) @comment +(field . (identifier) @property (_)) +(shebang) @comment + +;; Property +(property_identifier) @property + +;; Variable +(identifier) @variable + +;; Error +(ERROR) @error |