You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Though parsing incorrect syntax usefully is an exercise in futility in the general case, it should still be feasible to recognize the function definition, even if it's impossible to say objectively whether the if statement is missing a closing brace, or the function is.
In practical terms this impacts detecting indent level based on the parse tree, as the function body no longer exists to provide the outer indent level. I'm sure there are other consequences.
It is also strange that the parse tree does not include any ERRORs, even though the parse tree itself could not possibly represent valid Rust code; how can an identifier or parameters exist at the root of the parse tree?
For comparison, the C parser produces this parse tree for a similar function definition and if statement:
Removing the closing brace of the if statement's block causes the parser to reinterpret the function block's closing brace as the closing brace of the if statement's block, but otherwise leaves the parse tree unchanged:
There are no ERRORs, which I suppose makes some sense (what region represents the closing brace that doesn't exist?), but the function is still parsed usefully.
The text was updated successfully, but these errors were encountered:
The following Rust code
produces the following parse tree (as formatted by nvim-treesitter/playground):
If the closing brace of the
if
block is removed, the parser no longer recognizes the enclosingfunction_item
at all:Though parsing incorrect syntax usefully is an exercise in futility in the general case, it should still be feasible to recognize the function definition, even if it's impossible to say objectively whether the
if
statement is missing a closing brace, or the function is.In practical terms this impacts detecting indent level based on the parse tree, as the function
body
no longer exists to provide the outer indent level. I'm sure there are other consequences.It is also strange that the parse tree does not include any
ERROR
s, even though the parse tree itself could not possibly represent valid Rust code; how can anidentifier
orparameters
exist at the root of the parse tree?For comparison, the
C
parser produces this parse tree for a similar function definition andif
statement:Removing the closing brace of the
if
statement's block causes the parser to reinterpret the function block's closing brace as the closing brace of theif
statement's block, but otherwise leaves the parse tree unchanged:There are no
ERROR
s, which I suppose makes some sense (what region represents the closing brace that doesn't exist?), but the function is still parsed usefully.The text was updated successfully, but these errors were encountered: