highlights.scm 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342
  1. ; Lower priority to prefer @variable.parameter when identifier appears in parameter_declaration.
  2. ((identifier) @variable
  3. (#set! priority 95))
  4. (preproc_def
  5. (preproc_arg) @variable)
  6. [
  7. "default"
  8. "goto"
  9. "asm"
  10. "__asm__"
  11. ] @keyword
  12. [
  13. "enum"
  14. "struct"
  15. "union"
  16. "typedef"
  17. ] @keyword.type
  18. [
  19. "sizeof"
  20. "offsetof"
  21. ] @keyword.operator
  22. (alignof_expression
  23. .
  24. _ @keyword.operator)
  25. "return" @keyword.return
  26. [
  27. "while"
  28. "for"
  29. "do"
  30. "continue"
  31. "break"
  32. ] @keyword.repeat
  33. [
  34. "if"
  35. "else"
  36. "case"
  37. "switch"
  38. ] @keyword.conditional
  39. [
  40. "#if"
  41. "#ifdef"
  42. "#ifndef"
  43. "#else"
  44. "#elif"
  45. "#endif"
  46. "#elifdef"
  47. "#elifndef"
  48. (preproc_directive)
  49. ] @keyword.directive
  50. "#define" @keyword.directive.define
  51. "#include" @keyword.import
  52. [
  53. ";"
  54. ":"
  55. ","
  56. "::"
  57. ] @punctuation.delimiter
  58. "..." @punctuation.special
  59. [
  60. "("
  61. ")"
  62. "["
  63. "]"
  64. "{"
  65. "}"
  66. ] @punctuation.bracket
  67. [
  68. "="
  69. "-"
  70. "*"
  71. "/"
  72. "+"
  73. "%"
  74. "~"
  75. "|"
  76. "&"
  77. "^"
  78. "<<"
  79. ">>"
  80. "->"
  81. "."
  82. "<"
  83. "<="
  84. ">="
  85. ">"
  86. "=="
  87. "!="
  88. "!"
  89. "&&"
  90. "||"
  91. "-="
  92. "+="
  93. "*="
  94. "/="
  95. "%="
  96. "|="
  97. "&="
  98. "^="
  99. ">>="
  100. "<<="
  101. "--"
  102. "++"
  103. ] @operator
  104. ; Make sure the comma operator is given a highlight group after the comma
  105. ; punctuator so the operator is highlighted properly.
  106. (comma_expression
  107. "," @operator)
  108. [
  109. (true)
  110. (false)
  111. ] @boolean
  112. (conditional_expression
  113. [
  114. "?"
  115. ":"
  116. ] @keyword.conditional.ternary)
  117. (string_literal) @string
  118. (system_lib_string) @string
  119. (escape_sequence) @string.escape
  120. (null) @constant.builtin
  121. (number_literal) @number
  122. (char_literal) @character
  123. (preproc_defined) @function.macro
  124. ((field_expression
  125. (field_identifier) @property) @_parent
  126. (#not-has-parent? @_parent template_method function_declarator call_expression))
  127. (field_designator) @property
  128. ((field_identifier) @property
  129. (#has-ancestor? @property field_declaration)
  130. (#not-has-ancestor? @property function_declarator))
  131. (statement_identifier) @label
  132. (declaration
  133. type: (type_identifier) @_type
  134. declarator: (identifier) @label
  135. (#eq? @_type "__label__"))
  136. [
  137. (type_identifier)
  138. (type_descriptor)
  139. ] @type
  140. (storage_class_specifier) @keyword.modifier
  141. [
  142. (type_qualifier)
  143. (gnu_asm_qualifier)
  144. "__extension__"
  145. ] @keyword.modifier
  146. (linkage_specification
  147. "extern" @keyword.modifier)
  148. (type_definition
  149. declarator: (type_identifier) @type.definition)
  150. (primitive_type) @type.builtin
  151. (sized_type_specifier
  152. _ @type.builtin
  153. type: _?)
  154. ((identifier) @constant
  155. (#lua-match? @constant "^[A-Z][A-Z0-9_]+$"))
  156. (preproc_def
  157. (preproc_arg) @constant
  158. (#lua-match? @constant "^[A-Z][A-Z0-9_]+$"))
  159. (enumerator
  160. name: (identifier) @constant)
  161. (case_statement
  162. value: (identifier) @constant)
  163. ((identifier) @constant.builtin
  164. ; format-ignore
  165. (#any-of? @constant.builtin
  166. "stderr" "stdin" "stdout"
  167. "__FILE__" "__LINE__" "__DATE__" "__TIME__"
  168. "__STDC__" "__STDC_VERSION__" "__STDC_HOSTED__"
  169. "__cplusplus" "__OBJC__" "__ASSEMBLER__"
  170. "__BASE_FILE__" "__FILE_NAME__" "__INCLUDE_LEVEL__"
  171. "__TIMESTAMP__" "__clang__" "__clang_major__"
  172. "__clang_minor__" "__clang_patchlevel__"
  173. "__clang_version__" "__clang_literal_encoding__"
  174. "__clang_wide_literal_encoding__"
  175. "__FUNCTION__" "__func__" "__PRETTY_FUNCTION__"
  176. "__VA_ARGS__" "__VA_OPT__"))
  177. (preproc_def
  178. (preproc_arg) @constant.builtin
  179. ; format-ignore
  180. (#any-of? @constant.builtin
  181. "stderr" "stdin" "stdout"
  182. "__FILE__" "__LINE__" "__DATE__" "__TIME__"
  183. "__STDC__" "__STDC_VERSION__" "__STDC_HOSTED__"
  184. "__cplusplus" "__OBJC__" "__ASSEMBLER__"
  185. "__BASE_FILE__" "__FILE_NAME__" "__INCLUDE_LEVEL__"
  186. "__TIMESTAMP__" "__clang__" "__clang_major__"
  187. "__clang_minor__" "__clang_patchlevel__"
  188. "__clang_version__" "__clang_literal_encoding__"
  189. "__clang_wide_literal_encoding__"
  190. "__FUNCTION__" "__func__" "__PRETTY_FUNCTION__"
  191. "__VA_ARGS__" "__VA_OPT__"))
  192. (attribute_specifier
  193. (argument_list
  194. (identifier) @variable.builtin))
  195. (attribute_specifier
  196. (argument_list
  197. (call_expression
  198. function: (identifier) @variable.builtin)))
  199. ((call_expression
  200. function: (identifier) @function.builtin)
  201. (#lua-match? @function.builtin "^__builtin_"))
  202. ((call_expression
  203. function: (identifier) @function.builtin)
  204. (#has-ancestor? @function.builtin attribute_specifier))
  205. ; Preproc def / undef
  206. (preproc_def
  207. name: (_) @constant.macro)
  208. (preproc_call
  209. directive: (preproc_directive) @_u
  210. argument: (_) @constant.macro
  211. (#eq? @_u "#undef"))
  212. (preproc_ifdef
  213. name: (identifier) @constant.macro)
  214. (preproc_elifdef
  215. name: (identifier) @constant.macro)
  216. (preproc_defined
  217. (identifier) @constant.macro)
  218. (call_expression
  219. function: (identifier) @function.call)
  220. (call_expression
  221. function: (field_expression
  222. field: (field_identifier) @function.call))
  223. (function_declarator
  224. declarator: (identifier) @function)
  225. (function_declarator
  226. declarator: (parenthesized_declarator
  227. (pointer_declarator
  228. declarator: (field_identifier) @function)))
  229. (preproc_function_def
  230. name: (identifier) @function.macro)
  231. (comment) @comment @spell
  232. ((comment) @comment.documentation
  233. (#lua-match? @comment.documentation "^/[*][*][^*].*[*]/$"))
  234. ; Parameters
  235. (parameter_declaration
  236. declarator: (identifier) @variable.parameter)
  237. (parameter_declaration
  238. declarator: (array_declarator) @variable.parameter)
  239. (parameter_declaration
  240. declarator: (pointer_declarator) @variable.parameter)
  241. ; K&R functions
  242. ; To enable support for K&R functions,
  243. ; add the following lines to your own query config and uncomment them.
  244. ; They are commented out as they'll conflict with C++
  245. ; Note that you'll need to have `; extends` at the top of your query file.
  246. ;
  247. ; (parameter_list (identifier) @variable.parameter)
  248. ;
  249. ; (function_definition
  250. ; declarator: _
  251. ; (declaration
  252. ; declarator: (identifier) @variable.parameter))
  253. ;
  254. ; (function_definition
  255. ; declarator: _
  256. ; (declaration
  257. ; declarator: (array_declarator) @variable.parameter))
  258. ;
  259. ; (function_definition
  260. ; declarator: _
  261. ; (declaration
  262. ; declarator: (pointer_declarator) @variable.parameter))
  263. (preproc_params
  264. (identifier) @variable.parameter)
  265. [
  266. "__attribute__"
  267. "__declspec"
  268. "__based"
  269. "__cdecl"
  270. "__clrcall"
  271. "__stdcall"
  272. "__fastcall"
  273. "__thiscall"
  274. "__vectorcall"
  275. (ms_pointer_modifier)
  276. (attribute_declaration)
  277. ] @attribute