ConsenSysMesh / solidity-parser

Solidity Parser in Javascript
137 stars 53 forks source link

Draft fix for #26 #44

Closed cgewecke closed 7 years ago

cgewecke commented 7 years ago

This PR rewrites the declarative expression rule to allow descriptors like constant and internal to appear in any order.

It

Also adds example to doc_examples and has rebuild.

federicobond commented 7 years ago

This is a step in the good direction, but I would prefer to separate state variable specifiers from local ones, and also replace all those boolean keys in AST nodes with visibility and storage string enum keys.

Local variables, as far as I understand, only accept a StorageLocation (see grammar.txt) while state variables can be either constant or not and also have a visibility specifier.

cgewecke commented 7 years ago

@federicobond I'd like to move this PR forward but I could use a little design help if that's ok.

In your view

federicobond commented 7 years ago

Thank you for your time @cgewecke, I am happy to help.

As a general rule, whenever in doubt, check the result of the official solidity compiler AST or the grammar.txt document I linked above. While we are not aiming for an exact match at the moment, sticking as close as possible to it should minimize errors.

Regarding your questions:

For state variables, I believe you can do ( StorageLocation __ ConstantToken? ) / ( ConstantToken __ StorageLocation ) or something similar to guarantee exclusivity in any order.

cgewecke commented 7 years ago

Great, thanks so much @federicobond. Will revise as you suggest.

cgewecke commented 7 years ago

@federicobond Sorry for letting this languish for weeks. One reason has been that while I agree the parser should have the precision of the grammar, the proposed changes to DeclarativeExpression will likely affect downstream projects (specifically Solcover and Solium)

I'm wondering if you would consider the following:

  1. Accept this PR as a temporary fix (it stops solidity-parser from crashing on legal code).
  2. Get a PR from @duaraghav8 for issue #9 (tuples) (also a crasher).
  3. Help @duaraghav8 implement Solium's issue #58 (SP transition)
  4. Help Solium (and others) integrate breaking changes in SP. (They're not complicated - but if types are added Solium needs to handle them).

I realize this is some insane hopscotching around but it might help knit some of the core utilities to a common parser base and prevent further drift.

I'd be very happy to help with the above. I also understand if it's too complicated or should be done in a different order . . .

federicobond commented 7 years ago

@cgewecke that sounds great. I thought about asking you for an update earlier today, but it realized it was too early in the year to bother volunteers :)

Your plan sounds good, and you have my full support for that. As long as every change is documented in the changelog, the worst that can happen is that some downstream project must fix their declared dependency versions until they migrate.

cc/ @tcoulter

federicobond commented 7 years ago

For reference, my Solidity ANTLR4 grammar is much more conformant with the reference implementation at this point and uncovered several errors in the official grammar as published in the docs.

You can use it as a reference when making changes.

cgewecke commented 7 years ago

@federicobond Awesome. Thanks for the grammar link.

federicobond commented 7 years ago

@cgewecke can you rebase and remove the built parser so it merges cleanly?

federicobond commented 7 years ago

While you are there, please rewrite your commit as "Allow declarative..."

cgewecke commented 7 years ago

@federicobond Would it be ok if I close this, refork and resubmit. The odds of me rebasing correctly are 0%. Also should I include a build or not?

cgewecke commented 7 years ago

@federicobond On second thought I'm actually in favor of closing this period and just not merging. You've proposed a much better set of changes that should be their own thing. I apologize for this whole mess.

federicobond commented 7 years ago

I think it's best to not include a build. Otherwise, any two simultaneous pull requests will most likely generate a merge conflict.

federicobond commented 7 years ago

OK, let me know if you need any help. I am a bit overworked at the moment but I would love to move this forward by next week.

cgewecke commented 7 years ago

Great - I'll write up your idea over the weekend and I think there will be some small PRs coming out of an analysis of the difference between solparse and solidity parser early next week too.