Closed duaraghav8 closed 6 years ago
@duaraghav8 What did you change in solidity-parser to get the solparse output?
OK, the problem is caused by this rule:
SourceElement
= AssignmentExpression __ EOS
/ DeclarativeExpression __ EOS
/ EnumDeclaration
...
Those first two rules do not parse to AssignmentExpression or DeclarativeExpression nodes but to arrays with the whitespace and EOS result as items too.
I propose to define StateVariableDeclaration as this:
StateVariableDeclaration
= declaration:(AssignmentExpression / DeclarativeExpression) __ EOS
{
// Do some node manipulation here
}
And replace it in the SourceElement
rule, which would also bring the parser more in line with the official grammar.
The problem is that the layout for the AssignmentExpression and DeclarativeExpression are very different. AssignmentExpression has left, right and operator keys, where left is a DeclarativeExpression. StateVariableDeclaration should return a node with a consistent layout.
Since operator does not make sense in this context, perhaps value
should be the key containing the right-hand side expression for this node.
What do you think?
Code:
sp.parse (code).body [0]
yields:Observer the
body
of the ContractStatement (first object isDeclarativeExpression
, which is fine. But what's happening after this?). Its taking semicolon as a separate entity, whereas the semicolon, together with an expression before that, makeExpressionStatement
.My fix in solparse creates the following structure:
@cgewecke is working on moving all fixes in solparse to solidity-parser. Please comment on the structure elicited by solparse above, so we can finalize.