aboutsummaryrefslogtreecommitdiff
path: root/runtime/queries/solidity/highlights.scm
blob: 61c89ac8ad06cf104ba96bc08eba93d58f662b65 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
(comment) @comment

; Pragma
(pragma_directive) @tag
(solidity_version_comparison_operator ">=" @tag)
(solidity_version_comparison_operator "<=" @tag)
(solidity_version_comparison_operator "=" @tag)
(solidity_version_comparison_operator "~" @tag)
(solidity_version_comparison_operator "^" @tag)


; Literals
[
 (string)
 (hex_string_literal)
 (unicode_string_literal)
 (yul_string_literal)
] @string
[
 (number_literal)
 (yul_decimal_number)
 (yul_hex_number)
] @constant.numeric
[
 (true)
 (false)
] @constant.builtin


; Type
(type_name) @type
(primitive_type) @type
(struct_declaration struct_name: (identifier) @type)
(enum_declaration enum_type_name: (identifier) @type)
; Color payable in payable address conversion as type and not as keyword
(payable_conversion_expression "payable" @type)
(emit_statement . (identifier) @type)
; Handles ContractA, ContractB in function foo() override(ContractA, contractB) {}
(override_specifier (identifier) @type)
; Ensures that delimiters in mapping( ... => .. ) are not colored like types
(type_name "(" @punctuation.bracket "=>" @punctuation.delimiter ")" @punctuation.bracket)



; Functions and parameters

(function_definition
  function_name:  (identifier) @function)
(modifier_definition
  name:  (identifier) @function)
(yul_evm_builtin) @function.builtin

; Use contructor coloring for special functions
(constructor_definition "constructor" @constructor)
(fallback_receive_definition "receive" @constructor)
(fallback_receive_definition "fallback" @constructor)

(modifier_invocation (identifier) @function)

; Handles expressions like structVariable.g();
(call_expression . (member_expression (property_identifier) @function.method))

; Handles expressions like g();
(call_expression . (identifier) @function)

; Function parameters
(event_paramater name: (identifier) @variable.parameter)
(function_definition
  function_name:  (identifier) @variable.parameter)

; Yul functions
(yul_function_call function: (yul_identifier) @function)

; Yul function parameters
(yul_function_definition . (yul_identifier) @function (yul_identifier) @variable.parameter)

(meta_type_expression "type" @keyword)

(member_expression (property_identifier) @variable.other.member)
(property_identifier) @variable.other.member
(struct_expression ((identifier) @variable.other.member . ":"))
(enum_value) @variable.other.member


; Keywords
[
 "pragma"
 "import"
 "contract"
 "interface"
 "library"
 "is"
 "struct"
 "enum"
 "event"
 "using"
 "assembly"
 "switch"
 "case"
 "default"
 "break"
 "continue"
 "if"
 "else"
 "for"
 "while"
 "do"
 "try"
 "catch"
 "return"
 "emit"
 "public"
 "internal"
 "private"
 "external"
 "pure"
 "view"
 "payable"
 "modifier"
 "returns"
 "memory"
 "storage"
 "calldata"
 "function"
 "var"
 (constant)
 (virtual)
 (override_specifier)
 (yul_leave)
] @keyword

(import_directive "as" @keyword)
(import_directive "from" @keyword)
(event_paramater "indexed" @keyword)

; Punctuation

[
  "("
  ")"
  "["
  "]"
  "{"
  "}"
]  @punctuation.bracket


[
  "."
  ","
] @punctuation.delimiter


; Operators

[
  "&&"
  "||"
  ">>"
  ">>>"
  "<<"
  "&"
  "^"
  "|"
  "+"
  "-"
  "*"
  "/"
  "%"
  "**"
  "<"
  "<="
  "=="
  "!="
  "!=="
  ">="
  ">"
  "!"
  "~"
  "-"
  "+"
  "delete"
  "new"
  "++"
  "--"
] @operator

(identifier) @variable
(yul_identifier) @variable