highlights.scm 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266
  1. ; Keywords
  2. "return" @keyword.return
  3. [
  4. "goto"
  5. "in"
  6. "local"
  7. ] @keyword
  8. (break_statement) @keyword
  9. (do_statement
  10. [
  11. "do"
  12. "end"
  13. ] @keyword)
  14. (while_statement
  15. [
  16. "while"
  17. "do"
  18. "end"
  19. ] @keyword.repeat)
  20. (repeat_statement
  21. [
  22. "repeat"
  23. "until"
  24. ] @keyword.repeat)
  25. (if_statement
  26. [
  27. "if"
  28. "elseif"
  29. "else"
  30. "then"
  31. "end"
  32. ] @keyword.conditional)
  33. (elseif_statement
  34. [
  35. "elseif"
  36. "then"
  37. "end"
  38. ] @keyword.conditional)
  39. (else_statement
  40. [
  41. "else"
  42. "end"
  43. ] @keyword.conditional)
  44. (for_statement
  45. [
  46. "for"
  47. "do"
  48. "end"
  49. ] @keyword.repeat)
  50. (function_declaration
  51. [
  52. "function"
  53. "end"
  54. ] @keyword.function)
  55. (function_definition
  56. [
  57. "function"
  58. "end"
  59. ] @keyword.function)
  60. ; Operators
  61. [
  62. "and"
  63. "not"
  64. "or"
  65. ] @keyword.operator
  66. [
  67. "+"
  68. "-"
  69. "*"
  70. "/"
  71. "%"
  72. "^"
  73. "#"
  74. "=="
  75. "~="
  76. "<="
  77. ">="
  78. "<"
  79. ">"
  80. "="
  81. "&"
  82. "~"
  83. "|"
  84. "<<"
  85. ">>"
  86. "//"
  87. ".."
  88. ] @operator
  89. ; Punctuations
  90. [
  91. ";"
  92. ":"
  93. "::"
  94. ","
  95. "."
  96. ] @punctuation.delimiter
  97. ; Brackets
  98. [
  99. "("
  100. ")"
  101. "["
  102. "]"
  103. "{"
  104. "}"
  105. ] @punctuation.bracket
  106. ; Variables
  107. (identifier) @variable
  108. ((identifier) @constant.builtin
  109. (#eq? @constant.builtin "_VERSION"))
  110. ((identifier) @variable.builtin
  111. (#eq? @variable.builtin "self"))
  112. ((identifier) @module.builtin
  113. (#any-of? @module.builtin "_G" "debug" "io" "jit" "math" "os" "package" "string" "table" "utf8"))
  114. ((identifier) @keyword.coroutine
  115. (#eq? @keyword.coroutine "coroutine"))
  116. (variable_list
  117. (attribute
  118. "<" @punctuation.bracket
  119. (identifier) @attribute
  120. ">" @punctuation.bracket))
  121. ; Labels
  122. (label_statement
  123. (identifier) @label)
  124. (goto_statement
  125. (identifier) @label)
  126. ; Constants
  127. ((identifier) @constant
  128. (#lua-match? @constant "^[A-Z][A-Z_0-9]*$"))
  129. (nil) @constant.builtin
  130. [
  131. (false)
  132. (true)
  133. ] @boolean
  134. ; Tables
  135. (field
  136. name: (identifier) @property)
  137. (dot_index_expression
  138. field: (identifier) @variable.member)
  139. (table_constructor
  140. [
  141. "{"
  142. "}"
  143. ] @constructor)
  144. ; Functions
  145. (parameters
  146. (identifier) @variable.parameter)
  147. (vararg_expression) @variable.parameter.builtin
  148. (function_declaration
  149. name: [
  150. (identifier) @function
  151. (dot_index_expression
  152. field: (identifier) @function)
  153. ])
  154. (function_declaration
  155. name: (method_index_expression
  156. method: (identifier) @function.method))
  157. (assignment_statement
  158. (variable_list
  159. .
  160. name: [
  161. (identifier) @function
  162. (dot_index_expression
  163. field: (identifier) @function)
  164. ])
  165. (expression_list
  166. .
  167. value: (function_definition)))
  168. (table_constructor
  169. (field
  170. name: (identifier) @function
  171. value: (function_definition)))
  172. (function_call
  173. name: [
  174. (identifier) @function.call
  175. (dot_index_expression
  176. field: (identifier) @function.call)
  177. (method_index_expression
  178. method: (identifier) @function.method.call)
  179. ])
  180. (function_call
  181. (identifier) @function.builtin
  182. (#any-of? @function.builtin
  183. ; built-in functions in Lua 5.1
  184. "assert" "collectgarbage" "dofile" "error" "getfenv" "getmetatable" "ipairs" "load" "loadfile"
  185. "loadstring" "module" "next" "pairs" "pcall" "print" "rawequal" "rawget" "rawlen" "rawset"
  186. "require" "select" "setfenv" "setmetatable" "tonumber" "tostring" "type" "unpack" "xpcall"
  187. "__add" "__band" "__bnot" "__bor" "__bxor" "__call" "__concat" "__div" "__eq" "__gc" "__idiv"
  188. "__index" "__le" "__len" "__lt" "__metatable" "__mod" "__mul" "__name" "__newindex" "__pairs"
  189. "__pow" "__shl" "__shr" "__sub" "__tostring" "__unm"))
  190. ; Others
  191. (comment) @comment @spell
  192. ((comment) @comment.documentation
  193. (#lua-match? @comment.documentation "^[-][-][-]"))
  194. ((comment) @comment.documentation
  195. (#lua-match? @comment.documentation "^[-][-](%s?)@"))
  196. (hash_bang_line) @keyword.directive
  197. (number) @number
  198. (string) @string
  199. (escape_sequence) @string.escape
  200. ; string.match("123", "%d+")
  201. (function_call
  202. (dot_index_expression
  203. field: (identifier) @_method
  204. (#any-of? @_method "find" "match" "gmatch" "gsub"))
  205. arguments: (arguments
  206. .
  207. (_)
  208. .
  209. (string
  210. content: (string_content) @string.regexp)))
  211. ;("123"):match("%d+")
  212. (function_call
  213. (method_index_expression
  214. method: (identifier) @_method
  215. (#any-of? @_method "find" "match" "gmatch" "gsub"))
  216. arguments: (arguments
  217. .
  218. (string
  219. content: (string_content) @string.regexp)))