Closed siraben closed 2 years ago
This could result from the one_decl
rule being too highly prioritized. The partial parse tree reads something like <type> x = 3;
@nimble-code are semicolons optional at the end of if blocks? In the grammar it seems that if there are 2 or more statements there must be a semicolon separating them (the last being optional.)
interesting case -- it does look like the parser expects a semi-colon after the fi, but it shouldn't
As far as I can tell from the Spin examples, there isn't an instance where the if block has a semicolon omitted, so I think this code is invalid:
init {
if
:: y = 3;
fi
x = 3;
}
I'll see if I can fix it, to make semi-colons optional there, but for the time being this will have to be the work-around
@nimble-code Ok, thanks. Please note that this repository is a re-implementation of the Promela grammar in tree-sitter and I'm taking the YACC grammar as the source of ground truth to replicate. Is there a way to only run the parser in Spin?
FWIW it seems fine if the semicolon after the if block is intentional, as written in the sequence rule
I just tried this example, but it parses correctly on my system (Spin version 6.5.1 from 3 june 2021) int x, y init { if :: y = 3; fi x = 3; }
same result if the remaining two semi-colons are also deleted
by the way, in the spin parser, "missing" semi-colons are reinserted into the token stream in the lexer, so that the parser (following the yacc grammar) doesn't need to worry about it
@nimble-code I see, under what conditions is the semicolon inserted?
at the end of a line, if the preceding statement didn't have a semi-colon (tricky in conditions that are split across multiple lines...)
The following correctly parses
but this does not
It appears that the
if
node did not succeed, and the partial parse for the last statement is incorrectly parsed as a variable declaration instead of an assignment.