aboutsummaryrefslogtreecommitdiff
path: root/runtime/queries
diff options
context:
space:
mode:
authorBlaž Hrastnik2022-09-05 01:50:32 +0000
committerBlaž Hrastnik2022-09-05 01:50:32 +0000
commit20ed8c259519f1e37cf6c2a37479bdd681e9b924 (patch)
tree3234271a76dab7742b14e853b480b22dd332bb1d /runtime/queries
parent44b447947c810b7fc6a13383b4379f0f48501c17 (diff)
tree-sitter-solidity: Use upstream, update queries
Diffstat (limited to 'runtime/queries')
-rw-r--r--runtime/queries/solidity/highlights.scm134
-rw-r--r--runtime/queries/solidity/locals.scm9
2 files changed, 91 insertions, 52 deletions
diff --git a/runtime/queries/solidity/highlights.scm b/runtime/queries/solidity/highlights.scm
index 544cf3d9..08178c36 100644
--- a/runtime/queries/solidity/highlights.scm
+++ b/runtime/queries/solidity/highlights.scm
@@ -1,15 +1,16 @@
-(comment) @comment
+; identifiers
+; -----------
+(identifier) @variable
+(yul_identifier) @variable
; 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)
+(solidity_version_comparison_operator _ @tag)
; Literals
+; --------
+
[
(string)
(hex_string_literal)
@@ -26,26 +27,38 @@
(false)
] @constant.builtin
+(comment) @comment
+
+
+; Definitions and references
+; -----------
-; Type
(type_name) @type
(primitive_type) @type
-(struct_declaration struct_name: (identifier) @type)
-(enum_declaration enum_type_name: (identifier) @type)
+(user_defined_type (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
+; Definitions
+(struct_declaration
+ name: (identifier) @type)
+(enum_declaration
+ name: (identifier) @type)
+(contract_declaration
+ name: (identifier) @type)
+(library_declaration
+ name: (identifier) @type)
+(interface_declaration
+ name: (identifier) @type)
+(event_definition
+ name: (identifier) @type)
(function_definition
- function_name: (identifier) @function)
+ name: (identifier) @function)
+
(modifier_definition
name: (identifier) @function)
(yul_evm_builtin) @function.builtin
@@ -55,37 +68,38 @@
(fallback_receive_definition "receive" @constructor)
(fallback_receive_definition "fallback" @constructor)
-(modifier_invocation (identifier) @function)
+(struct_member name: (identifier) @variable.other.member)
+(enum_value) @constant
-; Handles expressions like structVariable.g();
-(call_expression . (member_expression (property_identifier) @function.method))
+; Invocations
+(emit_statement . (identifier) @type)
+(modifier_invocation (identifier) @function)
-; Handles expressions like g();
+(call_expression . (member_expression property: (identifier) @function.method))
(call_expression . (identifier) @function)
; Function parameters
-(event_paramater name: (identifier) @variable.parameter) ; TODO fix spelling once fixed upstream
-(function_definition
- function_name: (identifier) @variable.parameter)
+(call_struct_argument name: (identifier) @field)
+(event_paramater name: (identifier) @variable.parameter)
+(parameter 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
+; Structs and members
+(member_expression property: (identifier) @variable.other.member)
+(struct_expression type: ((identifier) @type .))
+(struct_field_assignment name: (identifier) @variable.other.member)
+; Tokens
+; -------
; Keywords
+(meta_type_expression "type" @keyword)
[
"pragma"
- "import"
"contract"
"interface"
"library"
@@ -95,19 +109,6 @@
"event"
"using"
"assembly"
- "switch"
- "case"
- "default"
- "break"
- "continue"
- "if"
- "else"
- "for"
- "while"
- "do"
- "try"
- "catch"
- "return"
"emit"
"public"
"internal"
@@ -117,20 +118,47 @@
"view"
"payable"
"modifier"
- "returns"
"memory"
"storage"
"calldata"
- "function"
"var"
- (constant)
+ "constant"
(virtual)
(override_specifier)
(yul_leave)
] @keyword
-(import_directive "as" @keyword)
-(import_directive "from" @keyword)
+[
+ "for"
+ "while"
+ "do"
+] @keyword.control.repeat
+
+[
+ "break"
+ "continue"
+ "if"
+ "else"
+ "switch"
+ "case"
+ "default"
+] @keyword.control.conditional
+
+[
+ "try"
+ "catch"
+] @keyword.control.exception
+
+[
+ "return"
+ "returns"
+] @keyword.control.return
+
+"function" @keyword.function
+
+"import" @keyword.control.import
+(import_directive "as" @keyword.control.import)
+(import_directive "from" @keyword.control.import)
(event_paramater "indexed" @keyword) ; TODO fix spelling once fixed upstream
; Punctuation
@@ -142,7 +170,7 @@
"]"
"{"
"}"
-] @punctuation.bracket
+] @punctuation.bracket
[
@@ -185,5 +213,7 @@
"--"
] @operator
-(identifier) @variable
-(yul_identifier) @variable
+[
+ "delete"
+ "new"
+] @keyword.operator
diff --git a/runtime/queries/solidity/locals.scm b/runtime/queries/solidity/locals.scm
new file mode 100644
index 00000000..29bdc02c
--- /dev/null
+++ b/runtime/queries/solidity/locals.scm
@@ -0,0 +1,9 @@
+(function_definition) @local.scope
+(block_statement) @local.scope
+
+(function_definition (parameter name: (identifier) @local.definition))
+
+; still have to support tuple assignments
+(assignment_expression left: (identifier) @local.definition)
+
+(identifier) @local.reference \ No newline at end of file