Open Philogy opened 2 years ago
Do you have an example that's parsed incorrectly?
bonus points if you have it in the test case format:
https://github.com/JoranHonig/tree-sitter-solidity/blob/master/test/corpus/constructor.txt
(whoof only seeing now that this response is a bit late 😅 )
Don't really have that much experience with tree-sitter, are there any good resources you could point to that could help me debug this locally? Is syntax highlighting working for you around / within unchecked
blocks?
What are you using for syntax highlighting?
I'm not sure if nvim uses the latest version of this parser.
I use nvim-treesitter
with the config option ensure_installed
. Running :TSUpdate
tells me that "all parsers are up-to-date!"
I can reproduce this:
function absOZ(int256 n) pure returns (uint256) {
unchecked {
return uint256(0);
}
}
Produces:
source_file (0, 0) - (6, 0)
function_definition (0, 0) - (4, 1)
function (0, 0) - (0, 8) "function"
identifier (0, 9) - (0, 14) "absOZ"
( (0, 14) - (0, 15) "("
parameter (0, 15) - (0, 23)
type_name (0, 15) - (0, 21)
primitive_type (0, 15) - (0, 21)
int256 (0, 15) - (0, 21) "int256"
identifier (0, 22) - (0, 23) "n"
) (0, 23) - (0, 24) ")"
state_mutability (0, 25) - (0, 29)
pure (0, 25) - (0, 29) "pure"
return_type_definition (0, 30) - (0, 47)
returns (0, 30) - (0, 37) "returns"
( (0, 38) - (0, 39) "("
parameter (0, 39) - (0, 46)
type_name (0, 39) - (0, 46)
primitive_type (0, 39) - (0, 46)
uint256 (0, 39) - (0, 46) "uint256"
) (0, 46) - (0, 47) ")"
function_body (0, 48) - (4, 1)
{ (0, 48) - (0, 49) "{"
block_statement (1, 4) - (3, 5)
{ (1, 14) - (1, 15) "{"
return_statement (2, 8) - (2, 26)
return (2, 8) - (2, 14) "return"
type_cast_expression (2, 15) - (2, 25)
primitive_type (2, 15) - (2, 22)
uint256 (2, 15) - (2, 22) "uint256"
( (2, 22) - (2, 23) "("
number_literal (2, 23) - (2, 24) "0"
) (2, 24) - (2, 25) ")"
} (3, 4) - (3, 5) "}"
} (4, 0) - (4, 1) "}"
Note that neither unchecked
nor the semicolons are included here, which limits what I can do in difftastic.
I guess we could fix this by either transforming the "unchecked" rule to a non-hidden rule or by creating 2 different rules to capture "unchecked" and "normal" block statements and wrapping those rules in an anonymous rule. Not sure what's the best solution.
_unchecked: $ => "unchecked",
unchecked_block_statement: $ => seq($._unchecked, '{', repeat($._statement), "}"),
block_statement: $ => seq('{', repeat($._statement), "}"),
//anonymous rule to either match unchecked or normal block statement
_block_statement: $ => choice($.block_statement, $.unchecked_block_statement),
slow response 😅
fixed the parser end of things: https://github.com/JoranHonig/tree-sitter-solidity/pull/55
Unsure what's incorrect with the grammar, probably something to do with the "optional" unchecked on L485 but the first few lines in the block are not recognized properly and neither are the blocks after.
Don't really know how to test / debug this but wanted to note it here, thx.