ConsenSysMesh / solidity-parser

Solidity Parser in Javascript
138 stars 54 forks source link

Struct instantiation pattern "MyStruct ({...})" doesn't get parsed #76

Closed duaraghav8 closed 7 years ago

duaraghav8 commented 7 years ago

According to solidity struct doc, this should get compiled:

contract foo {
  struct fs { uint x; }
  function b () {
    if (true)
      fs ({ x: 100 });
  }
}

(compiles in solc)

However, SP throws a parse error

Error: An error occured while parsing the source code:
SyntaxError: Expected "!", "!=", "(", ")", "+", "++", "-", "--", "0", "<", "<=", "==", ">", ">=", "[", "^", "delete", "false", "hex", "mapping", "new", "this", "true", "v", "~", [1-9], comment, end of line, identifier, number, string, or whitespace but "{" found.

this is because it doesn't recognise patterns like:

foo ({ x: 100 });

where foo is:

struct foo {
  uint x;
}
cgewecke commented 7 years ago

Hi @duaraghav8! Are you using latest master? Rules to parse these cases were added only very recently. Are you going to try to plug SP into Solium?

duaraghav8 commented 7 years ago

hey @cgewecke let me update my module and re-try. I AM currently working on moving to SP and deprecating solparse

duaraghav8 commented 7 years ago

it works in 0.3.0, my bad :)

duaraghav8 commented 7 years ago

@cgewecke IDK I might be doing something stupid here, but I still can't get it to work.

screen shot 2017-06-16 at 1 42 12 pm

when I remove the { x: 100 } from inside fs (), it gets parsed with no trouble.

using latest version screen shot 2017-06-16 at 1 44 36 pm

Can you please use the below code and see if SP parses it without any problems for you?

contract foo {\n  struct fs { uint x; }\n  function b () {\n    if (true) fs ({ x: 100 });\n  }\n}\n
cgewecke commented 7 years ago

@duaraghav8 I'm sorry I should have been clearer above - these changes are in master but haven't been published to npm yet. That segment should parse when the version gets bumped. . .

duaraghav8 commented 7 years ago

oh cool. Just let me know when you guys are planning to make the next release.