Registry / llm-agents / solidity-parser-sc

solidity-parser-sc

JSON →
library0.4.12jsnpmunverified

solidity-parser-sc is an unmaintained JavaScript parser for Solidity, built using PEG.js. Last published in June 2018 with version 0.4.12, it is based on an older version of the `consensys/solidity-parser` with specific grammar rules, notably adding support for Gnosis-style interpolation (e.g., `{{Variable}}`) to defer address assignments. Due to its age and lack of maintenance (last update over 8 years ago), it does not support modern Solidity syntax or language features, and its parsing behavior may not conform to the current official Solidity specification. There is no active release cadence, and it is considered abandoned. For any current or new projects requiring robust and up-to-date Solidity parsing, developers are strongly advised to use `@solidity-parser/parser` (latest version 0.20.2), which is an actively maintained ANTLR4-based parser that provides comprehensive support for the evolving Solidity language.

npm install solidity-parser-sc
INSTALL
IMPORT
SIG · SOLIDITY-PARSER-SC
S
solidity-parser-sc
llm-agentsjavascriptv0.4.12
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

parse
const parser = require('solidity-parser-sc'); const ast = parser.parse(solidityCode);
import { parse } from 'solidity-parser-sc';
This package predates widespread ESM adoption and primarily uses CommonJS `require()`. It exports a default object containing the `parse` method.
ParserError
const { ParserError } = require('solidity-parser-sc'); // ... catch (e) { if (e instanceof ParserError) { ... } }
A ParserError class is typically exported for custom error handling. This is an assumed export pattern based on similar parser libraries from the era.

This quickstart demonstrates how to parse a simple Solidity contract using `solidity-parser-sc` and extract a contract definition from the resulting Abstract Syntax Tree (AST).

const parser = require('solidity-parser-sc'); const solidityCode = ` pragma solidity ^0.4.0; contract SimpleStorage { uint256 public storedData; event DataStored(uint256 indexed oldValue, uint256 indexed newValue); function set(uint256 x) public { emit DataStored(storedData, x); storedData = x; } function get() public view returns (uint256) { return storedData; } } `; try { const ast = parser.parse(solidityCode, { tolerant: true, loc: true }); console.log('Successfully parsed Solidity code.'); // console.log(JSON.stringify(ast, null, 2)); // Uncomment to see the full AST // Example: Find contract names const contractDefinitions = ast.children.filter(node => node.type === 'ContractDefinition'); if (contractDefinitions.length > 0) { console.log(`Found contract: ${contractDefinitions[0].name}`); } else { console.log('No contract definition found.'); } } catch (e) { if (e instanceof parser.ParserError) { console.error('Solidity Parsing Error:'); e.errors.forEach(err => console.error(` - ${err.message} (Line: ${err.line}, Column: ${err.column})`)); } else { console.error('An unexpected error occurred:', e.message); } }
Debug
Known issues
breakingThis package is effectively abandoned. Its last update was in June 2018 (v0.4.12), meaning it does not support any Solidity syntax or features introduced since Solidity 0.4.x. Attempting to parse modern Solidity code (e.g., Solidity 0.5.x and above) will likely result in parsing errors or an incorrect AST.
fix
Migrate to an actively maintained Solidity parser such as `@solidity-parser/parser`. Install it via `npm install @solidity-parser/parser` and update your import statements and parsing logic accordingly.
affects: >=0.4.13
gotchaThe package's primary differentiating feature was support for Gnosis-specific `{{Variable}}` interpolation syntax. If your project relies on this specific syntax, migrating away might require pre-processing your Solidity code or finding an alternative solution, as standard Solidity parsers do not support this non-standard syntax natively.
fix
Evaluate if the Gnosis interpolation is still critical. If so, consider a pre-parsing step to resolve these interpolations before feeding the code to a standard Solidity parser. If not, remove the non-standard syntax from your contracts.
affects: All versions
deprecatedThis library uses PEG.js, an older parser generator. Modern Solidity parsers like `@solidity-parser/parser` utilize ANTLR4, which is generally more robust and easier to maintain for complex, evolving grammars like Solidity. Using this outdated technology stack means it's highly unlikely to receive updates for new Solidity versions.
fix
Transition to a parser based on a modern grammar parsing framework like ANTLR4 to ensure compatibility and ongoing support with Solidity language evolution. `@solidity-parser/parser` is the recommended successor.
affects: All versions
Errors
Common errors & fixes
SyntaxError: Expected "}", "\n", "\r", or end of input but "p" found.
This error often indicates that the Solidity code contains syntax that is not recognized by the parser's outdated grammar, or there's a malformed token. It's highly probable with Solidity versions >0.4.x.
fix
Ensure the Solidity code adheres to a very old Solidity standard (e.g., 0.4.x). For modern Solidity, this parser is inadequate; switch to `@solidity-parser/parser`.
TypeError: Cannot read property 'parse' of undefined
This error typically occurs if the package was incorrectly imported or if the module itself did not export the `parse` function as expected. Given its age, CommonJS `require` is the correct import method.
fix
Verify the import statement is `const parser = require('solidity-parser-sc');` and that `parser.parse()` is being called. If the error persists, the installation might be corrupted or the package structure differs from common patterns.
Upgrade
Version history
0.4.12latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
15 hits · last 30 days
node
14
OpenAI (training)
1
Resources
solidity-parser-sc — npm install solidity-parser-sc · libregistry