mirror of
https://github.com/nvim-treesitter/nvim-treesitter.git
synced 2026-07-13 17:00:09 -04:00
feat(solidity): use maintained parser and update highlights accordingly
This commit is contained in:
parent
b401b7423d
commit
5c511dd124
5 changed files with 138 additions and 98 deletions
|
|
@ -303,7 +303,7 @@ We are looking for maintainers to add more parsers and to write query files for
|
||||||
- [x] [slint](https://github.com/jrmoulton/tree-sitter-slint) (experimental, maintained by @jrmoulton)
|
- [x] [slint](https://github.com/jrmoulton/tree-sitter-slint) (experimental, maintained by @jrmoulton)
|
||||||
- [x] [smali](https://git.sr.ht/~yotam/tree-sitter-smali) (maintained by @amaanq)
|
- [x] [smali](https://git.sr.ht/~yotam/tree-sitter-smali) (maintained by @amaanq)
|
||||||
- [x] [smithy](https://github.com/indoorvivants/tree-sitter-smithy) (maintained by @amaanq, @keynmol)
|
- [x] [smithy](https://github.com/indoorvivants/tree-sitter-smithy) (maintained by @amaanq, @keynmol)
|
||||||
- [x] [solidity](https://github.com/YongJieYongJie/tree-sitter-solidity) (maintained by @YongJieYongJie)
|
- [x] [solidity](https://github.com/JoranHonig/tree-sitter-solidity) (maintained by @amaanq)
|
||||||
- [x] [sparql](https://github.com/BonaBeavis/tree-sitter-sparql) (maintained by @BonaBeavis)
|
- [x] [sparql](https://github.com/BonaBeavis/tree-sitter-sparql) (maintained by @BonaBeavis)
|
||||||
- [x] [sql](https://github.com/derekstride/tree-sitter-sql) (maintained by @derekstride)
|
- [x] [sql](https://github.com/derekstride/tree-sitter-sql) (maintained by @derekstride)
|
||||||
- [x] [starlark](https://github.com/amaanq/tree-sitter-starlark) (maintained by @amaanq)
|
- [x] [starlark](https://github.com/amaanq/tree-sitter-starlark) (maintained by @amaanq)
|
||||||
|
|
|
||||||
|
|
@ -390,7 +390,7 @@
|
||||||
"revision": "cf8c7eb9faf7c7049839585eac19c94af231e6a0"
|
"revision": "cf8c7eb9faf7c7049839585eac19c94af231e6a0"
|
||||||
},
|
},
|
||||||
"solidity": {
|
"solidity": {
|
||||||
"revision": "52ed0880c0126df2f2c7693f215fe6f38e4a2e0a"
|
"revision": "168020304759ad5d8b4a88a541a699134e3730c5"
|
||||||
},
|
},
|
||||||
"sparql": {
|
"sparql": {
|
||||||
"revision": "05f949d3c1c15e3261473a244d3ce87777374dec"
|
"revision": "05f949d3c1c15e3261473a244d3ce87777374dec"
|
||||||
|
|
|
||||||
|
|
@ -1235,11 +1235,11 @@ list.smithy = {
|
||||||
|
|
||||||
list.solidity = {
|
list.solidity = {
|
||||||
install_info = {
|
install_info = {
|
||||||
url = "https://github.com/YongJieYongJie/tree-sitter-solidity",
|
url = "https://github.com/JoranHonig/tree-sitter-solidity",
|
||||||
branch = "with-generated-c-code",
|
branch = "master",
|
||||||
files = { "src/parser.c" },
|
files = { "src/parser.c" },
|
||||||
},
|
},
|
||||||
maintainers = { "@YongJieYongJie" },
|
maintainers = { "@amaanq" },
|
||||||
}
|
}
|
||||||
|
|
||||||
list.sparql = {
|
list.sparql = {
|
||||||
|
|
|
||||||
|
|
@ -1,73 +1,75 @@
|
||||||
(comment) @comment
|
|
||||||
;; Handles natspec comments
|
|
||||||
((comment) @preproc
|
|
||||||
(#match? @preproc "^/// .*"))
|
|
||||||
|
|
||||||
; Pragma
|
; Pragma
|
||||||
(pragma_directive) @attribute
|
|
||||||
|
|
||||||
|
[
|
||||||
|
"pragma"
|
||||||
|
"solidity"
|
||||||
|
] @preproc
|
||||||
|
|
||||||
|
(solidity_pragma_token
|
||||||
|
"||" @symbol)
|
||||||
|
(solidity_pragma_token
|
||||||
|
"-" @symbol)
|
||||||
|
|
||||||
|
(solidity_version_comparison_operator) @operator
|
||||||
|
|
||||||
; Literals
|
; Literals
|
||||||
|
|
||||||
[
|
[
|
||||||
(string)
|
(string)
|
||||||
(hex_string_literal)
|
|
||||||
(unicode_string_literal)
|
|
||||||
(yul_string_literal)
|
(yul_string_literal)
|
||||||
] @string
|
] @string
|
||||||
|
|
||||||
|
(hex_string_literal
|
||||||
|
"hex" @symbol
|
||||||
|
(_) @string)
|
||||||
|
|
||||||
|
(unicode_string_literal
|
||||||
|
"unicode" @symbol
|
||||||
|
(_) @string)
|
||||||
|
|
||||||
[
|
[
|
||||||
(number_literal)
|
(number_literal)
|
||||||
(yul_decimal_number)
|
(yul_decimal_number)
|
||||||
(yul_hex_number)
|
(yul_hex_number)
|
||||||
] @number
|
] @number
|
||||||
[
|
|
||||||
(true)
|
|
||||||
(false)
|
|
||||||
] @constant.builtin
|
|
||||||
|
|
||||||
|
(yul_boolean) @boolean
|
||||||
|
|
||||||
; Type
|
; Type
|
||||||
(type_name (identifier) @type)
|
(type_name (identifier) @type)
|
||||||
(type_name "mapping" @type)
|
(type_name "mapping" @function.builtin)
|
||||||
(primitive_type) @type
|
|
||||||
|
[
|
||||||
|
(primitive_type)
|
||||||
|
(number_unit)
|
||||||
|
] @type.builtin
|
||||||
|
|
||||||
(contract_declaration name: (identifier) @type)
|
(contract_declaration name: (identifier) @type)
|
||||||
(struct_declaration struct_name: (identifier) @type)
|
(struct_declaration name: (identifier) @type)
|
||||||
(struct_member name: (identifier) @field)
|
(struct_member name: (identifier) @field)
|
||||||
(enum_declaration enum_type_name: (identifier) @type)
|
(enum_declaration name: (identifier) @type)
|
||||||
(emit_statement . (identifier) @type)
|
(emit_statement . (identifier) @type)
|
||||||
; Handles ContractA, ContractB in function foo() override(ContractA, contractB) {}
|
; Handles ContractA, ContractB in function foo() override(ContractA, contractB) {}
|
||||||
(override_specifier (identifier) @type)
|
(override_specifier (user_defined_type) @type)
|
||||||
; Ensures that delimiters in mapping( ... => .. ) are not colored like types
|
|
||||||
(type_name
|
|
||||||
"(" @punctuation.bracket
|
|
||||||
"=>" @punctuation.delimiter
|
|
||||||
")" @punctuation.bracket)
|
|
||||||
|
|
||||||
|
|
||||||
; Functions and parameters
|
; Functions and parameters
|
||||||
|
|
||||||
(function_definition
|
(function_definition
|
||||||
function_name: (identifier) @function)
|
name: (identifier) @function)
|
||||||
(modifier_definition
|
(modifier_definition
|
||||||
name: (identifier) @function)
|
name: (identifier) @function)
|
||||||
(yul_evm_builtin) @function.builtin
|
(yul_evm_builtin) @function.builtin
|
||||||
|
|
||||||
; Use constructor coloring for special functions
|
; Use constructor coloring for special functions
|
||||||
(constructor_definition "constructor" @constructor)
|
(constructor_definition "constructor" @constructor)
|
||||||
(fallback_receive_definition "receive" @constructor)
|
|
||||||
(fallback_receive_definition "fallback" @constructor)
|
|
||||||
|
|
||||||
(modifier_invocation (identifier) @function)
|
(modifier_invocation (identifier) @function)
|
||||||
|
|
||||||
; Handles expressions like structVariable.g();
|
; Handles expressions like structVariable.g();
|
||||||
(call_expression . (member_expression (property_identifier) @method.call))
|
(call_expression . (member_expression (identifier) @method.call))
|
||||||
|
|
||||||
; Handles expressions like g();
|
; Handles expressions like g();
|
||||||
(call_expression . (identifier) @function.call)
|
(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
|
; Function parameters
|
||||||
(event_paramater name: (identifier) @parameter)
|
(event_paramater name: (identifier) @parameter)
|
||||||
|
|
@ -81,100 +83,123 @@
|
||||||
|
|
||||||
(meta_type_expression "type" @keyword)
|
(meta_type_expression "type" @keyword)
|
||||||
|
|
||||||
(member_expression (property_identifier) @field)
|
(member_expression property: (identifier) @field)
|
||||||
(property_identifier) @field
|
(call_struct_argument name: (identifier) @field)
|
||||||
(struct_expression ((identifier) @field . ":"))
|
(struct_field_assignment name: (identifier) @field)
|
||||||
(enum_value) @constant
|
(enum_value) @constant
|
||||||
|
|
||||||
|
|
||||||
; Keywords
|
; Keywords
|
||||||
[
|
[
|
||||||
"contract"
|
"contract"
|
||||||
"interface"
|
"interface"
|
||||||
"library"
|
"library"
|
||||||
"is"
|
"is"
|
||||||
"struct"
|
"struct"
|
||||||
"enum"
|
"enum"
|
||||||
"event"
|
"event"
|
||||||
"assembly"
|
"assembly"
|
||||||
"emit"
|
"emit"
|
||||||
"modifier"
|
"override"
|
||||||
"var"
|
"modifier"
|
||||||
(virtual)
|
"var"
|
||||||
(override_specifier)
|
"let"
|
||||||
|
"emit"
|
||||||
|
"fallback"
|
||||||
|
"receive"
|
||||||
|
(virtual)
|
||||||
] @keyword
|
] @keyword
|
||||||
|
|
||||||
|
; FIXME: update grammar
|
||||||
|
; (block_statement "unchecked" @keyword)
|
||||||
|
|
||||||
|
(event_paramater "indexed" @keyword)
|
||||||
|
|
||||||
[
|
[
|
||||||
"public"
|
"public"
|
||||||
"internal"
|
"internal"
|
||||||
"private"
|
"private"
|
||||||
"external"
|
"external"
|
||||||
"pure"
|
"pure"
|
||||||
"view"
|
"view"
|
||||||
"payable"
|
"payable"
|
||||||
|
(immutable)
|
||||||
] @type.qualifier
|
] @type.qualifier
|
||||||
|
|
||||||
[
|
[
|
||||||
"memory"
|
"memory"
|
||||||
"storage"
|
"storage"
|
||||||
"calldata"
|
"calldata"
|
||||||
(constant)
|
"constant"
|
||||||
] @storageclass
|
] @storageclass
|
||||||
|
|
||||||
[
|
[
|
||||||
"for"
|
"for"
|
||||||
"while"
|
"while"
|
||||||
"do"
|
"do"
|
||||||
|
"break"
|
||||||
|
"continue"
|
||||||
] @repeat
|
] @repeat
|
||||||
|
|
||||||
[
|
[
|
||||||
"break"
|
"if"
|
||||||
"continue"
|
"else"
|
||||||
"if"
|
"switch"
|
||||||
"else"
|
"case"
|
||||||
"switch"
|
"default"
|
||||||
"case"
|
|
||||||
"default"
|
|
||||||
] @conditional
|
] @conditional
|
||||||
|
|
||||||
|
(ternary_expression
|
||||||
|
"?" @conditional.ternary
|
||||||
|
":" @conditional.ternary)
|
||||||
|
|
||||||
[
|
[
|
||||||
"try"
|
"try"
|
||||||
"catch"
|
"catch"
|
||||||
|
"revert"
|
||||||
] @exception
|
] @exception
|
||||||
|
|
||||||
[
|
[
|
||||||
"return"
|
"return"
|
||||||
"returns"
|
"returns"
|
||||||
(yul_leave)
|
(yul_leave)
|
||||||
] @keyword.return
|
] @keyword.return
|
||||||
|
|
||||||
"function" @keyword.function
|
"function" @keyword.function
|
||||||
|
|
||||||
"pragma" @preproc
|
[
|
||||||
|
"import"
|
||||||
["import" "using"] @include
|
"using"
|
||||||
|
] @include
|
||||||
(import_directive "as" @include)
|
(import_directive "as" @include)
|
||||||
(import_directive "from" @include)
|
(import_directive "from" @include)
|
||||||
|
(import_directive "*" @character.special)
|
||||||
(event_paramater "indexed" @keyword)
|
|
||||||
|
|
||||||
; Punctuation
|
; Punctuation
|
||||||
|
|
||||||
[
|
[ "{" "}" ] @punctuation.bracket
|
||||||
"("
|
|
||||||
")"
|
|
||||||
"["
|
|
||||||
"]"
|
|
||||||
"{"
|
|
||||||
"}"
|
|
||||||
] @punctuation.bracket
|
|
||||||
|
|
||||||
|
[ "[" "]" ] @punctuation.bracket
|
||||||
|
|
||||||
|
[ "(" ")" ] @punctuation.bracket
|
||||||
|
|
||||||
[
|
[
|
||||||
"."
|
"."
|
||||||
","
|
","
|
||||||
|
; FIXME: update grammar
|
||||||
|
; (semicolon)
|
||||||
|
"->"
|
||||||
|
"=>"
|
||||||
] @punctuation.delimiter
|
] @punctuation.delimiter
|
||||||
|
|
||||||
|
(call_struct_argument
|
||||||
|
":" @punctuation.delimiter)
|
||||||
|
(slice_access
|
||||||
|
":" @punctuation.delimiter)
|
||||||
|
(struct_field_assignment
|
||||||
|
":" @punctuation.delimiter)
|
||||||
|
(yul_label
|
||||||
|
":" @punctuation.delimiter)
|
||||||
|
|
||||||
; Operators
|
; Operators
|
||||||
|
|
||||||
|
|
@ -206,12 +231,27 @@
|
||||||
"+"
|
"+"
|
||||||
"++"
|
"++"
|
||||||
"--"
|
"--"
|
||||||
|
":="
|
||||||
] @operator
|
] @operator
|
||||||
|
|
||||||
|
(yul_assignment
|
||||||
|
":" @operator
|
||||||
|
"=" @operator)
|
||||||
|
|
||||||
[
|
[
|
||||||
"delete"
|
"delete"
|
||||||
"new"
|
"new"
|
||||||
] @keyword.operator
|
] @keyword.operator
|
||||||
|
|
||||||
(identifier) @variable
|
[
|
||||||
(yul_identifier) @variable
|
(identifier)
|
||||||
|
(yul_identifier)
|
||||||
|
] @variable
|
||||||
|
|
||||||
|
; Comments
|
||||||
|
|
||||||
|
(comment) @comment @spell
|
||||||
|
|
||||||
|
; Errors
|
||||||
|
|
||||||
|
(ERROR) @error
|
||||||
|
|
|
||||||
|
|
@ -4,13 +4,13 @@
|
||||||
// ^ comment
|
// ^ comment
|
||||||
pragma solidity >=0.7.0 <0.9.0;
|
pragma solidity >=0.7.0 <0.9.0;
|
||||||
// ^ preproc
|
// ^ preproc
|
||||||
// ^ attribute
|
// ^ preproc
|
||||||
|
|
||||||
import * as something from "anotherFile";
|
import * as something from "anotherFile";
|
||||||
// ^ ^ ^ include
|
// ^ ^ ^ include
|
||||||
|
|
||||||
/// @title Voting with delegation.
|
/// @title Voting with delegation.
|
||||||
// ^ preproc
|
// <- comment
|
||||||
contract Ballot {
|
contract Ballot {
|
||||||
// ^keyword
|
// ^keyword
|
||||||
// ^ type
|
// ^ type
|
||||||
|
|
@ -20,7 +20,7 @@ contract Ballot {
|
||||||
struct Voter {
|
struct Voter {
|
||||||
// ^ type
|
// ^ type
|
||||||
uint weight; // weight is accumulated by delegation
|
uint weight; // weight is accumulated by delegation
|
||||||
// ^ type
|
// ^ type.builtin
|
||||||
// ^ field
|
// ^ field
|
||||||
bool voted; // if true, that person already voted
|
bool voted; // if true, that person already voted
|
||||||
address delegate; // person delegated to
|
address delegate; // person delegated to
|
||||||
|
|
@ -34,7 +34,7 @@ contract Ballot {
|
||||||
}
|
}
|
||||||
|
|
||||||
address public chairperson;
|
address public chairperson;
|
||||||
// ^ type
|
// ^ type.builtin
|
||||||
|
|
||||||
// This declares a state variable that
|
// This declares a state variable that
|
||||||
// stores a `Voter` struct for each possible address.
|
// stores a `Voter` struct for each possible address.
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue