1; https://github.com/nvim-treesitter/nvim-treesitter/blob/cb79d2446196d25607eb1d982c96939abdf67b8e/queries/hcl/highlights.scm
2; highlights.scm
3[
4 "!"
5 "\*"
6 "/"
7 "%"
8 "\+"
9 "-"
10 ">"
11 ">="
12 "<"
13 "<="
14 "=="
15 "!="
16 "&&"
17 "||"
18] @operator
19
20[
21 "{"
22 "}"
23 "["
24 "]"
25 "("
26 ")"
27] @punctuation.bracket
28
29[
30 "."
31 ".*"
32 ","
33 "[*]"
34] @punctuation.delimiter
35
36[
37 (ellipsis)
38 "\?"
39 "=>"
40] @punctuation.special
41
42[
43 ":"
44 "="
45] @punctuation
46
47[
48 "for"
49 "endfor"
50 "in"
51 "if"
52 "else"
53 "endif"
54] @keyword
55
56[
57 (quoted_template_start) ; "
58 (quoted_template_end) ; "
59 (template_literal) ; non-interpolation/directive content
60] @string
61
62[
63 (heredoc_identifier) ; END
64 (heredoc_start) ; << or <<-
65] @punctuation.delimiter
66
67[
68 (template_interpolation_start) ; ${
69 (template_interpolation_end) ; }
70 (template_directive_start) ; %{
71 (template_directive_end) ; }
72 (strip_marker) ; ~
73] @punctuation.special
74
75(numeric_lit) @number
76
77(bool_lit) @boolean
78
79(null_lit) @constant
80
81(comment) @comment
82
83(identifier) @variable
84
85(body
86 (block
87 (identifier) @keyword))
88
89(body
90 (block
91 (body
92 (block
93 (identifier) @type))))
94
95(function_call
96 (identifier) @function)
97
98(attribute
99 (identifier) @variable)
100
101; { key: val }
102;
103; highlight identifier keys as though they were block attributes
104(object_elem
105 key:
106 (expression
107 (variable_expr
108 (identifier) @variable)))
109
110; var.foo, data.bar
111;
112; first element in get_attr is a variable.builtin or a reference to a variable.builtin
113(expression
114 (variable_expr
115 (identifier) @variable)
116 (get_attr
117 (identifier) @variable))
118
119; https://github.com/nvim-treesitter/nvim-treesitter/blob/cb79d2446196d25607eb1d982c96939abdf67b8e/queries/terraform/highlights.scm
120; Terraform specific references
121;
122;
123; local/module/data/var/output
124(expression
125 (variable_expr
126 (identifier) @variable
127 (#any-of? @variable "data" "var" "local" "module" "output"))
128 (get_attr
129 (identifier) @variable))
130
131; path.root/cwd/module
132(expression
133 (variable_expr
134 (identifier) @type
135 (#eq? @type "path"))
136 (get_attr
137 (identifier) @variable
138 (#any-of? @variable "root" "cwd" "module")))
139
140; terraform.workspace
141(expression
142 (variable_expr
143 (identifier) @type
144 (#eq? @type "terraform"))
145 (get_attr
146 (identifier) @variable
147 (#any-of? @variable "workspace")))
148
149; Terraform specific keywords
150; TODO: ideally only for identifiers under a `variable` block to minimize false positives
151((identifier) @type
152 (#any-of? @type "bool" "string" "number" "object" "tuple" "list" "map" "set" "any"))
153
154(object_elem
155 val:
156 (expression
157 (variable_expr
158 (identifier) @type
159 (#any-of? @type "bool" "string" "number" "object" "tuple" "list" "map" "set" "any"))))