Solparse

2.2.8 · maintenance · verified Wed Apr 22

Solparse is a JavaScript library providing a PEG.js-based parser for the Solidity programming language. It is currently at version 2.2.8, with its last major release dating back over seven years, indicating a sporadic and maintenance-driven release cadence. The library was originally a fork of Consensys' `solidity-parser` and is primarily maintained to support `Ethlint`, a Solidity linter. Due to its specific maintenance focus, the developers do not guarantee backward compatibility or new feature support for general use. Users are strongly advised to pin `solparse` as a fixed dependency in production systems. Alternatives like `solparse-exp-jb` (a more recent fork supporting newer Solidity features) or `@solidity-parser/parser` (an ANTLR-based parser) may offer more up-to-date Solidity syntax support.

Common errors

Warnings

Install

Imports

Quickstart

Demonstrates how to parse a basic Solidity contract string using solparse and log the resulting Abstract Syntax Tree (AST), including basic error handling.

import parse from 'solparse';

const solidityCode = `
pragma solidity ^0.8.0;

contract SimpleStorage {
    uint256 public storedData;

    function set(uint256 x) public {
        storedData = x;
    }

    function get() public view returns (uint256) {
        return storedData;
    }
}
`;

try {
    const ast = parse(solidityCode);
    console.log('Successfully parsed Solidity code. AST:', JSON.stringify(ast, null, 2));
    // You can now traverse and analyze the AST
    console.log('Contract name:', ast.body[0].name);
} catch (e) {
    if (e instanceof Error && e.name === 'SyntaxError') {
        console.error('Parsing error:', e.message);
    } else {
        console.error('An unexpected error occurred:', e);
    }
}

view raw JSON →