federicobond / solidity-parser-antlr

A Solidity parser for JS built on top of a robust ANTLR4 grammar
MIT License
154 stars 55 forks source link

pragma statement parse error when verison doesn't follow A.B.C pattern #15

Open duaraghav8 opened 6 years ago

duaraghav8 commented 6 years ago
pragma solidity 0.4.0;
pragma solidity ^0.4.0;
pragma solidity >= 0.4.0;
pragma solidity <= 0.4.0;
pragma solidity < 0.4.0;
pragma solidity > 0.4.0;
pragma solidity != 0.4.0;
pragma solidity >=0.4.0 <0.4.8; // from https://github.com/ethereum/solidity/releases/tag/v0.4.0

pragma solidity 0.4;
pragma solidity ^0.4;
pragma solidity >= 0.4;
pragma solidity <= 0.4;
pragma solidity < 0.5;
pragma solidity > 0.4;
pragma solidity != 0.4;
pragma solidity >=0.4 <=0.4;

pragma solidity 0;
pragma solidity v0;
pragma solidity ^0;
pragma solidity >= 0;
pragma solidity <= 0;
pragma solidity < 1;
pragma solidity > 0;
pragma solidity != 0;
pragma solidity >=0 <=1;

All of the above are syntactically correct pragma statements (feel free to test in remix). But parser only recognises version a.b.c. We need to make the b & c part optional, not mandatory.

federicobond commented 6 years ago

Thanks for the report @duaraghav8! I wasn't aware of the optional version parts. Looks like supporting some of these would require a split of the parser and lexer and the introduction of lexer modes, which I am not sure I want to do right now.

Is there any particular example that is giving you trouble? Perhaps we can handle that case first and then worry about the rest.

duaraghav8 commented 6 years ago

@federicobond no prob, actually none of them trouble me. I happened to come across a codebase that was using ^0.4 in pragma statement and was wondering if it gets parsed. But this version literal is being used very rarely, so not a high priority issue IMO. most people are using a.b.c only. Let's keep the issue open though? So we have a record for the future.

federicobond commented 6 years ago

Sure! I’ll keep it open, no worries 😊

LogvinovLeon commented 6 years ago

This is causing me some troubles. I have a contract that has the version string ~0.4.10 and the parser can't parse that. I've created an issue at a grammar repo: https://github.com/solidityj/solidity-antlr4/issues/15