diff options
| author | Amaan Qureshi <amaanq12@gmail.com> | 2023-02-24 07:42:04 -0500 |
|---|---|---|
| committer | Stephan Seitz <stephan.seitz@fau.de> | 2023-02-24 13:05:33 -0800 |
| commit | 5c511dd1244fc8eeccf8920a5a4754ae01da296e (patch) | |
| tree | 44a7929f9b7c006726dd79bdbdaa50887293c05c /queries/solidity | |
| parent | ci: bump release workflow (diff) | |
| download | nvim-treesitter-5c511dd1244fc8eeccf8920a5a4754ae01da296e.tar nvim-treesitter-5c511dd1244fc8eeccf8920a5a4754ae01da296e.tar.gz nvim-treesitter-5c511dd1244fc8eeccf8920a5a4754ae01da296e.tar.bz2 nvim-treesitter-5c511dd1244fc8eeccf8920a5a4754ae01da296e.tar.lz nvim-treesitter-5c511dd1244fc8eeccf8920a5a4754ae01da296e.tar.xz nvim-treesitter-5c511dd1244fc8eeccf8920a5a4754ae01da296e.tar.zst nvim-treesitter-5c511dd1244fc8eeccf8920a5a4754ae01da296e.zip | |
feat(solidity): use maintained parser and update highlights accordingly
Diffstat (limited to 'queries/solidity')
| -rw-r--r-- | queries/solidity/highlights.scm | 218 |
1 files changed, 129 insertions, 89 deletions
diff --git a/queries/solidity/highlights.scm b/queries/solidity/highlights.scm index 33c837d5c..5afebb990 100644 --- a/queries/solidity/highlights.scm +++ b/queries/solidity/highlights.scm @@ -1,73 +1,75 @@ -(comment) @comment -;; Handles natspec comments -((comment) @preproc - (#match? @preproc "^/// .*")) - ; Pragma -(pragma_directive) @attribute +[ + "pragma" + "solidity" +] @preproc + +(solidity_pragma_token + "||" @symbol) +(solidity_pragma_token + "-" @symbol) + +(solidity_version_comparison_operator) @operator ; Literals + [ (string) - (hex_string_literal) - (unicode_string_literal) (yul_string_literal) ] @string + +(hex_string_literal + "hex" @symbol + (_) @string) + +(unicode_string_literal + "unicode" @symbol + (_) @string) + [ (number_literal) (yul_decimal_number) (yul_hex_number) ] @number -[ - (true) - (false) -] @constant.builtin +(yul_boolean) @boolean ; Type (type_name (identifier) @type) -(type_name "mapping" @type) -(primitive_type) @type +(type_name "mapping" @function.builtin) + +[ + (primitive_type) + (number_unit) +] @type.builtin + (contract_declaration name: (identifier) @type) -(struct_declaration struct_name: (identifier) @type) +(struct_declaration name: (identifier) @type) (struct_member name: (identifier) @field) -(enum_declaration enum_type_name: (identifier) @type) +(enum_declaration name: (identifier) @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) - +(override_specifier (user_defined_type) @type) ; Functions and parameters (function_definition - function_name: (identifier) @function) + name: (identifier) @function) (modifier_definition name: (identifier) @function) (yul_evm_builtin) @function.builtin ; Use constructor 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) @method.call)) +(call_expression . (member_expression (identifier) @method.call)) ; Handles expressions like g(); (call_expression . (identifier) @function.call) -(function_definition - function_name: (identifier) @function) - -; Handles the field in struct literals like MyStruct({MyField: MyVar * 2}) -(call_expression (identifier) @field . ":") ; Function parameters (event_paramater name: (identifier) @parameter) @@ -81,100 +83,123 @@ (meta_type_expression "type" @keyword) -(member_expression (property_identifier) @field) -(property_identifier) @field -(struct_expression ((identifier) @field . ":")) +(member_expression property: (identifier) @field) +(call_struct_argument name: (identifier) @field) +(struct_field_assignment name: (identifier) @field) (enum_value) @constant ; Keywords [ - "contract" - "interface" - "library" - "is" - "struct" - "enum" - "event" - "assembly" - "emit" - "modifier" - "var" - (virtual) - (override_specifier) + "contract" + "interface" + "library" + "is" + "struct" + "enum" + "event" + "assembly" + "emit" + "override" + "modifier" + "var" + "let" + "emit" + "fallback" + "receive" + (virtual) ] @keyword +; FIXME: update grammar +; (block_statement "unchecked" @keyword) + +(event_paramater "indexed" @keyword) + [ - "public" - "internal" - "private" - "external" - "pure" - "view" - "payable" + "public" + "internal" + "private" + "external" + "pure" + "view" + "payable" + (immutable) ] @type.qualifier [ - "memory" - "storage" - "calldata" - (constant) + "memory" + "storage" + "calldata" + "constant" ] @storageclass [ - "for" - "while" - "do" + "for" + "while" + "do" + "break" + "continue" ] @repeat [ - "break" - "continue" - "if" - "else" - "switch" - "case" - "default" + "if" + "else" + "switch" + "case" + "default" ] @conditional +(ternary_expression + "?" @conditional.ternary + ":" @conditional.ternary) + [ - "try" - "catch" + "try" + "catch" + "revert" ] @exception [ - "return" - "returns" - (yul_leave) + "return" + "returns" + (yul_leave) ] @keyword.return "function" @keyword.function -"pragma" @preproc - -["import" "using"] @include +[ + "import" + "using" +] @include (import_directive "as" @include) (import_directive "from" @include) - -(event_paramater "indexed" @keyword) +(import_directive "*" @character.special) ; Punctuation -[ - "(" - ")" - "[" - "]" - "{" - "}" -] @punctuation.bracket +[ "{" "}" ] @punctuation.bracket + +[ "[" "]" ] @punctuation.bracket +[ "(" ")" ] @punctuation.bracket [ "." "," + ; FIXME: update grammar + ; (semicolon) + "->" + "=>" ] @punctuation.delimiter +(call_struct_argument + ":" @punctuation.delimiter) +(slice_access + ":" @punctuation.delimiter) +(struct_field_assignment + ":" @punctuation.delimiter) +(yul_label + ":" @punctuation.delimiter) ; Operators @@ -206,12 +231,27 @@ "+" "++" "--" + ":=" ] @operator +(yul_assignment + ":" @operator + "=" @operator) + [ "delete" "new" ] @keyword.operator -(identifier) @variable -(yul_identifier) @variable +[ + (identifier) + (yul_identifier) +] @variable + +; Comments + +(comment) @comment @spell + +; Errors + +(ERROR) @error |
