ConsenSysMesh / solidity-parser

Solidity Parser in Javascript
137 stars 53 forks source link

using a Library 'for' causes SyntaxError #8

Closed duaraghav8 closed 8 years ago

duaraghav8 commented 8 years ago

Reproducing https://github.com/duaraghav8/Solium/issues/10 (reported by @elenadimitrova)


Having a

using LibraryContract **for** someDataType;

As described here http://solidity.readthedocs.io/en/latest/contracts.html?#using-for

causes a SyntaxError:

Error: An error occured while parsing the source code:
SyntaxError: Expected "!=", "!==", "%", "%=", "&", "&&", "&=", "*", "*=", "+", "++", "+=", ",", "-", "--", "-=", "/", "/*", "//", "/=", ";", "<", "<<", "<<=", "<=", "=", "==", "===", ">", ">=", ">>", ">>=", ">>>", ">>>=", "?", "^", "^=", "in", "instanceof", "|", "|=", "||", comment, end of line or whitespace but "f" found. Line: 25, Column: 21
An error occured while running the linter on /MyContract.sol:

using is not yet recognised in solidity-parser. Need to decide on how to construct the AST Node for UsingStatement

duaraghav8 commented 8 years ago

Update: I have added support for UsingStatement in my local module. Here's a sample:

For a statement like:

using Foo for Bar;

The Node looks like:

{ 
  type: 'UsingStatement',
  library: 'Foo',
  for: 'Bar',
  start: 0,
  end: 18
}

For a statement like:

using Foo for *;

The Node looks like:

{ 
  type: 'UsingStatement',
  library: 'Foo',
  for: '*',
  start: 0,
  end: 16
}

I felt this was a suitable structure. Let me know if you need any changes or if its fine, I'll make a PR.

tcoulter commented 8 years ago

Thanks @duaraghav8. When you say local module, you mean on your forked branch? Any chance you can submit pull requests from your fork into the main project? That'll make it much easier to import changes.

I'm happy to take all changes in one PR instead of many.

duaraghav8 commented 8 years ago

@tcoulter yes, on my fork (, i.e., solparse). Just also have a look at #10 and if you feel the fix I've made for it is fine, let me know.

Then I'll make a single PR with both the changes.

tcoulter commented 8 years ago

Made my comments on #10. Looks great!