Code Monkey home page Code Monkey logo

solparse's Introduction

Solparse

Pegjs-based Parser for the Solidity Programming language.

It was originally a fork of Consensys' solidity-parser by Tim Coulter. @cgewecke, @duaraghav8 and @federicobond are co-authors.

Note

Solparse is primarily meant for Ethlint. Because its sole purpose is to make life easier for the linter, we do not guarantee that there won't be any breaking changes, although we work hard to keep it friendly.

If you use solparse in your production systems, use it as a fixed dependency.

License

MIT

solparse's People

Contributors

davesag avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

solparse's Issues

Failed to parse alias in inheritance

I think the following contract has valid solidity syntax:

pragma solidity ^0.4.18;

import './TestImport.sol' as Test;

contract Contract is Test.TestImport {}

But solparse fails to parse it with the following error:

Expected "(", ",", "{", comment, end of line, or whitespace but "." found

I can compile that file with solc, and remix doesn't report any errors either.

solidity-parser bugs (as of this writing)

List of lurking bugs in solidity-parser

  1. No 'name' field in StructDeclaration - this means we never get to know the name of the struct from the StructDeclaration Node object. (I made a PR for this but no response even after 2 weeks :()
  2. IsStatement malfunctioning - When using inheritance with Contract or Library, the syntax is:
contract Car is Vehicle, Engine {
        //definition
}

Solidity parser doesn't parse the 'is' section properly. the is Array's first object is fine (vehicle), but subsequent element is just a comma, not another object for Engine.

  1. Exponentiation operator (double asterisk) not being parsed by solidity parser
  2. A statement like uint x = 2 days; doesn't get parsed. It gives error at start of 'days'. (though SP parses the other tokens: "2 wei / 2 szabo / 2 finny, etc.", "days" is a valid suffix too but doesn't have support.
  3. Parse of var (x) = 100; failing because x is surrounded by brackets (which is legal in solidity).

Support all version literal patterns

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 version literals must be supported

assembly block 'if' support

Please consider adding something like this to the grammar:

--- solidity.pegjs.old	2018-02-21 16:53:26.000000000 +0100
+++ solidity.pegjs	2018-02-21 16:53:29.000000000 +0100
@@ -1722,6 +1722,7 @@
   / InlineAssemblyBlock
   / AssemblyLocalBinding
   / AssemblyAssignment
+  / AssemblyConditional
   / AssemblyLabel
   / AssemblyFor
   / NumericLiteral
@@ -1768,6 +1769,18 @@
     }
   }
 
+AssemblyConditional
+  = 'if' __ expression:AssemblyExpression __ body:InlineAssemblyBlock {
+    return {
+      type: "AssemblyConditional",
+      name: 'if',
+      expression: expression,
+      body: body,
+      start: location().start.offset,
+      end: location().end.offset
+    }
+  }
+
 ReturnOpCode
   = 'return' {
     return {

Status of the project

Hi, @duaraghav8. I am having trouble deciding whether to open issues and pull requests here or in ConsenSys/solidity-parser. What are your plans for this repo?

It would be great if you are willing to merge changes from upstream solidity-parser periodically, so that implementations don't diverge too much. Otherwise, the JS ecosystem around Solidity would suffer from having two different parser implementations. Let me know how can I help.

"calldata" cannot be used as a var name

support for calldata storage location was recently introduced for solidity 0.5.
now, because of this, the following code:

contract foo {
  function f(uint calldata) {}
}

will not be parsed correctly. Anyone not using solidity 0.5 will expect calldata in above example to be parsed as a variable name. But now, the parser always interprets it as a storage location and assigns null to variable name.

"require(class == rrsync);" not being parsed

statement require(class == rrsync); is producing following error:

Expected "!", "!=", "(", ")", "+", "++", "-", "--", "0", "<", "<=", "==", ">", ">=", "[", "^", "delete", "false", "hex", "mapping", "new", "this", "true", "v", "{", "~", [1-9], comment, end of line, number, string, or whitespace but "c" found. Line: 4, Column: 10

wtf? I currently don't know the reason for this. Need to investigate.

EDIT: I know the reason. Solparse is treating class as a solidity keyword, so its not expecting the keyword to be there. fuck

incorrect parsing for FunctionDeclaration node.end when inside contract

code:

contract Visual {

    function foo () {


        var x = 100;

    }

}

Now, get AST using solParse.parse (code)
Notice that FunctionDeclaration Node's end: 60 and ContractStatement's end:61

FD Node inside contract is not showing the correct value for end (should be 58, the index right after '}' closing brace of function fo)

EnumDeclaration shouldn't end with ;

Invalid, and currently parsed as correct:
enum { Test1, Test2 };

Valid:
enum { Test1, Test2 }

This can be seen by simply trying to compile a contract containing an enum with solc.

Incorrect end position in a lot of nodes

A lot of definitions in the grammar are similar to

id:Identifier __ params:("(" __ InformalParameterList? __ ")")?

Notice that the first whitespace directive __ should exist inside params rather than before it. here, it exists before it. This means in a code construct like

contract Foo is bar, baz                         {
}

the end position of the Modifier baz actually covers al the whitespace after baz instead of just covering till z. This is a problem with lot of node definitions where everything after the whitespace __ is optional.

Parse new Array error

contract ArrayTest {
    function test() {
        address[] memory addresses = new address[](2);
    }
}

Can not Parse new address[](2).

tests need to be corrected

tests are currently failing because they haven't been written properly since solparse was forked from solidity-parser!!!

TODO

  • Parse Comments
  • Provide tokens through tokenize () function

inaccurate node.end offset for FunctionDeclaration

and also for ModifierDeclarations

code = contract Foo {\n\tmodifier bar () returns (string) {\n\t\treturn "Hello";\n\t}\n\n\n\tfunction baz () {}\n}

a = sp.parse (code).body [0]

code.slice (0,a.body [0].end)

returns

contract Foo {\n\tmodifier bar () returns (string) {\n\t\treturn "Hello";\n\t}\n\n\n\t

should've stopped at "}" but also included the whitespace

Upgrade Mocha to remove deprecation warnings

Running npm install on any project that includes the solium package, (and thus this package) gives the following deprecation warnings

npm WARN deprecated [email protected]: Jade has been renamed to pug, please install the latest version of pug instead of jade
npm WARN deprecated [email protected]: to-iso-string has been deprecated, use @segment/to-iso-string instead.
npm WARN deprecated [email protected]: Please update to minimatch 3.0.2 or higher to avoid a RegExp DoS issue

Upgrading mocha to the latest version will fix that.

pragma solidity statement parsing error

only pragma solidity ^A.B.C patters are being parsed correctly, not when we have only A.b or A
eg -

pragma solidity 0;
pragma solidity 0.4;
pragma solidity ^0.4;

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.