-
Notifications
You must be signed in to change notification settings - Fork 3.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Split and update Solidity grammar #4257
Conversation
d86a458
to
89e6f3a
Compare
/** | ||
* Solidity is a statically typed, contract-oriented, high-level language for implementing smart contracts on the Ethereum platform. | ||
*/ | ||
parser grammar SolidityParser; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
At some point, it might be best to add an entirely new version of the grammar, e.g., root of repo/solidity/v0.8/SolidityParser.g4 (etc), root of repo/solidity/v0.9/SolidityParser.g4 (etc).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For now i just updated to the last version, since previous was added in 2017, and most of breaking changes added before 2021 and there is no back compatibility between versions. For the future breaking changes it makes sense to have separate grammars
; | ||
|
||
//@doc:inline | ||
variableDeclarationList |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
variableDeclarationList
is unused, and it is not in the "specification" at https://docs.soliditylang.org/en/latest/grammar.html.
$ bash /c/Users/Kenne/Documents/GitHub/g4-scripts/find-unused-parser-symbols.sh
No arguments were provided.
Finding unused parser symbols in grammars...
./desc.xml
SolidityParser.g4:L713: variableDeclarationList
^
09/24-06:54:01 ~/issues/g4-4257/solidity
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's keep it, since it is in the original spec.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will create an Issue in the originating repo for this and other issues. There are many useless parentheses, which don't add anything to the clarity of the grammar.
Also, there is ambiguity in expression,
etc. Ambiguity is concerning because it means this grammar was not thoroughly debugged.
solidity/SolidityParser.g4
Outdated
* Definition of the special receive function. | ||
*/ | ||
receiveFunctionDefinition | ||
locals[ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All these locals and semantic predicates seem to force single usage of some syntax. This doesn't seem to be a large "positive" given that the checks are for a specific target, and we've been saying that semantic checking should be done post parse. Perhaps we can just remove these at this point? That said, one can easily remove all these via a single Trash command that edits the grammar prior to generating a parser.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also though about it, will remove a semantics related locals and predicates
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
removed local predicates and rewrote parameterized rules to remove parameters
OK, it makes sense to match the grammar here with that at https://github.com/ethereum/solidity/tree/develop/docs/grammar. That is why |
Yeah, i added a comment that grammar is copied from docs repo |
As mentioned above, there seems to be ambiguity in
On line 91, |
Let's leave it like this until antlr/antlr4#4480 will not be merged. Also i want to improve the grammar in next iterations, probably we can avoid non-left recursion in |
I'll test the grammar as is with #4257 to see if, indeed, it fixes the ambiguity. |
The Antlr PR didn't fix the ambiguity. Will try restructuring the grammar slightly. |
The fix is to simply unfold the symbol With this change, the grammar has no ambiguity with regards to this particular issue.
That said, it does not take care of all the ambiguity, which was discovered in examples/test.sol.
|
I added an Issue in this repo to note the ambiguities in the grammar. #4261 This PR looks fine for merging. |
@codeFather2 thanks |
This PR updates the Solidity grammar to match the latest version of the official documentation.
Link to official grammar: https://github.com/ethereum/solidity/tree/develop/docs/grammar