Registry / serialization / solidity-parser-antlr

solidity-parser-antlr

JSON →
library0.4.11jsnpmunverified

solidity-parser-antlr is an unmaintained JavaScript package designed to parse Solidity source code into an Abstract Syntax Tree (AST) using an ANTLR 4 grammar. Its last published version, 0.4.11, was released over seven years ago, rendering it incompatible with modern Solidity language features and breaking changes introduced in versions 0.5.x and newer. While it served as the foundational parser for many tools in the past, its lack of updates means it does not support current Solidity syntax, semantics, or security requirements. Developers needing an active Solidity parser should consider the `@solidity-parser/parser` package, which is a continuously maintained fork of this original repository. This package does ship with TypeScript type definitions, but its utility is severely limited by its outdated Solidity grammar support.

npm install solidity-parser-antlr
INSTALL
IMPORT
SIG · SOLIDITY-PARSER-AN
S
solidity-parser-antlr
serializationjavascriptv0.4.11
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.

parser
import parser from 'solidity-parser-antlr';
import { parse } from 'solidity-parser-antlr';
This package uses a default export for the main parser object. Named imports like `{ parse }` will not work directly.
ParserError
import parser from 'solidity-parser-antlr'; // ... then use parser.ParserError
import { ParserError } from 'solidity-parser-antlr';
ParserError is exposed as a property of the default-exported `parser` object, not as a top-level named export. Direct named imports for sub-components are not supported.
AST types
import type { SourceUnit, ContractDefinition } from 'solidity-parser-antlr';
Type declarations are shipped with the package and can be imported directly as named types for structural typing of the AST nodes.
parser (CommonJS)
const parser = require('solidity-parser-antlr');
For CommonJS environments, the entire parser module is imported as a single object.

Demonstrates parsing a simple Solidity contract, enabling location and range options, and walking the AST using the visitor pattern to log contract and function definitions. It also includes error handling for parsing failures.

import parser from 'solidity-parser-antlr'; const input = ` pragma solidity ^0.4.0; contract SimpleStorage { uint256 public data; function set(uint256 _data) public { data = _data; } } `; try { const ast = parser.parse(input, { loc: true, range: true }); console.log('Successfully parsed Solidity code. Root node type:', ast.type); console.log('AST contains location and range info:', ast.loc, ast.range); // Example of visiting a node (e.g., ContractDefinition) parser.visit(ast, { ContractDefinition: function(node) { console.log('Found contract:', node.name); }, FunctionDefinition: function(node) { console.log('Found function:', node.name, 'visibility:', node.visibility); } }); } catch (e) { if (e instanceof parser.ParserError) { console.error('Parsing error:', e.errors); } else { console.error('An unexpected error occurred:', e); } }
Debug
Known issues
breakingThis package (solidity-parser-antlr@0.4.11) is abandoned and has not been updated in over seven years. It does not support Solidity versions 0.5.0 or newer, which introduced significant breaking changes to the language. Using it with modern Solidity code will result in parsing errors and incomplete ASTs.
fix
Migrate to an actively maintained Solidity parser such as `@solidity-parser/parser`. This fork directly continues the work and supports newer Solidity versions. Uninstall `solidity-parser-antlr` and install `@solidity-parser/parser` instead. Update import paths from `solidity-parser-antlr` to `@solidity-parser/parser`.
affects: >=0.5.0
deprecatedThe entire `solidity-parser-antlr` package should be considered deprecated due to its age and lack of maintenance. Continuing to use it poses risks of incompatibility with new Solidity features and potential unpatched parsing vulnerabilities.
fix
Switch to the actively maintained fork, `@solidity-parser/parser`, which provides ongoing support for the latest Solidity language versions and includes fixes and enhancements.
affects: >=0.4.11
gotchaWhen using `webpack` to bundle applications that include this parser, minimizing the bundle can mangle internal function names, leading to parsing failures. This is explicitly mentioned in the documentation for its fork, and likely applies to this version as well given their shared origin.
fix
If encountering issues with minified bundles, try disabling minification for the parser or configuring webpack's `optimization.minimize` to `false` specifically for this module. The long-term fix is to upgrade to `@solidity-parser/parser` and consult its documentation for bundling best practices.
affects: <=0.4.11
Errors
Common errors & fixes
Error: Parsing failed: Line X:Y Some unexpected token found.
The Solidity code being parsed contains syntax or features introduced in Solidity versions newer than 0.4.x, which this parser does not support.
fix
Review your Solidity code's `pragma` directive. If it's above `^0.4.x`, you must upgrade to an actively maintained parser like `@solidity-parser/parser`. If it's indeed `^0.4.x`, check for any subtle syntax that might have been interpreted differently in early Solidity versions.
TypeError: Cannot read properties of undefined (reading 'ParserError')
Attempting to access `ParserError` as a named import (e.g., `import { ParserError } from 'solidity-parser-antlr';`) when it is exposed as a property of the default-exported `parser` object.
fix
Ensure `ParserError` is accessed via the default import: `import parser from 'solidity-parser-antlr'; ... if (e instanceof parser.ParserError) { ... }`.
Upgrade
Version history
0.4.11latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
4 hits · last 30 days
node
4
Resources
solidity-parser-antlr — npm install solidity-parser-antlr · libregistry