ConsenSysMesh / solidity-parser

Solidity Parser in Javascript
138 stars 54 forks source link

Cannot parse a simple smart contract #98

Closed yimin-yang closed 6 years ago

yimin-yang commented 6 years ago

JavaScript code:

const SolidityParser = require('solidity-parser');
let ast = SolidityParser.parseFile('Coin.sol');

Coin.sol:

pragma solidity ^0.4.21;

contract Coin {
    // The keyword "public" makes those variables
    // readable from outside.
    address public minter;
    mapping (address => uint) public balances;

    // Events allow light clients to react to
    // changes efficiently.
    event Sent(address from, address to, uint amount);

    // This is the constructor whose code is
    // run only when the contract is created.
    function Coin() public {
        minter = msg.sender;
    }

    function mint(address receiver, uint amount) public {
        if (msg.sender != minter) return;
        balances[receiver] += amount;
    }

    function send(address receiver, uint amount) public {
        if (balances[msg.sender] < amount) return;
        balances[msg.sender] -= amount;
        balances[receiver] += amount;
        emit Sent(msg.sender, receiver, amount);
    }
}

This smart contract is from Solidity official document: https://solidity.readthedocs.io/en/develop/introduction-to-smart-contracts.html. But the solidity parser cannot parse it. A SyntaxError is raised.

cgewecke commented 6 years ago

Hi @Yimin-Yang - Apologies, this project is deprecated. There's a really nice, actively maintained JS solidity parser located here.

yimin-yang commented 6 years ago

@cgewecke Thanks!