ConsenSysMesh / solidity-parser

Solidity Parser in Javascript
138 stars 54 forks source link

Separate top-level statements in grammar #17

Closed federicobond closed 8 years ago

federicobond commented 8 years ago

Right now, the grammar allows pragma directives, imports and contracts to be declared inside the contract. These should trigger a syntax error:

contract MyContract {
    function() {
        pragma solidity ^0.4.4;
    }
}
contract MyContract {
    function() {
        contract OtherContract {

        }
    }
}

The solc compiler grammar singles these out in the SourceUnit rule. See here.

duaraghav8 commented 8 years ago

I'm not that experienced with PegJs so don't mind my being naive, but wouldn't this become significantly more complex? To specify which nodes are allowed inside for every node?

federicobond commented 8 years ago

It shouldn't be difficult, just a matter of separating that big statement list into two rules.