federicobond / solidity-parser-antlr

A Solidity parser for JS built on top of a robust ANTLR4 grammar
MIT License
155 stars 56 forks source link

Should the loop expression of a ForStatement be an ExpressionStatement? #39

Open fvictorio opened 6 years ago

fvictorio commented 6 years ago

The loop expression of the for statement gest the type ExpressionStatement added:

https://github.com/federicobond/solidity-parser-antlr/blob/ded9c7032a20b4d17eb3363ed6f5542e8e976024/src/ASTBuilder.js#L690-L693

This is causing issues in prettier-solidity, where is difficult to know if an ExpressionStatement should have a semicolon or not (see https://github.com/prettier-solidity/prettier-plugin-solidity/issues/46 and https://github.com/prettier-solidity/prettier-plugin-solidity/issues/64 for the details). Since the loop expression of a for doesn't have a semicolon, calling it an ExpressionStatement feels wrong.

My question is if there's a good reason to do this, and if there's a chance of modifying it.

Thanks!

federicobond commented 6 years ago

Internally, the reference implementation of Solidity uses an ExpressionStatement, so I would approach this change carefully.

The definition of ExpressionStatement is an expression followed by a semicolon though. If it’s difficult to special case this in prettier then I’m open to accepting a pull request to update the parser. Make sure you include the change in the changelog too.