# solidity-parser-antlr

> A Solidity parser built from a robust ANTLR 4 grammar

Latest version **0.4.11** (published 2019-08-29) · MIT license · 0 weekly downloads

## Install

```sh
npm install solidity-parser-antlr
pnpm add solidity-parser-antlr
yarn add solidity-parser-antlr
bun add solidity-parser-antlr
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.4.11 |
| Published | 2019-08-29 |
| First published | 2017-06-16 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 879.8 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 155 |
| Author | Federico Bond |
| Maintainers | federicobond |

## Links

- npm: https://www.npmjs.com/package/solidity-parser-antlr
- Repository: https://github.com/federicobond/solidity-parser-antlr
- Issues: https://github.com/federicobond/solidity-parser-antlr/issues
- npm.io page: https://npm.io/package/solidity-parser-antlr

## Recent versions

- 0.4.11 (latest) — 2019-08-29
- 0.4.10 — 2019-08-29
- 0.4.9 — 2019-08-29
- 0.4.8 — 2019-08-03
- 0.4.7 — 2019-07-16
- 0.4.6 — 2019-07-11
- 0.4.5 — 2019-06-21
- 0.4.4 — 2019-06-14
- 0.4.3 — 2019-05-29
- 0.4.2 — 2019-03-08
- 0.4.1 — 2019-02-20
- 0.4.0 — 2019-01-11
- 0.3.3 — 2018-12-22
- 0.3.2 — 2018-09-02
- 0.3.1 — 2018-07-24
- … 23 more at https://npm.io/package/solidity-parser-antlr/versions

## README

solidity-parser-antlr
=====================

[![npm](https://img.shields.io/npm/v/solidity-parser-antlr.svg)](https://www.npmjs.com/package/solidity-parser-antlr)
[![Build Status](https://travis-ci.org/federicobond/solidity-parser-antlr.svg?branch=master)](https://travis-ci.org/federicobond/solidity-parser-antlr)

A Solidity parser built on top of a robust [ANTLR4 grammar](https://github.com/solidityj/solidity-antlr4).

### Usage

```javascript
import parser from 'solidity-parser-antlr';

var input = `
    contract test {
        uint256 a;
        function f() {}
    }
`
try {
    parser.parse(input)
} catch (e) {
    if (e instanceof parser.ParserError) {
        console.log(e.errors)
    }
}
```

The `parse` method also accepts a second argument which lets you specify the
following options, in a style similar to the _esprima_ API:

| Key      | Type    | Default | Description                                                                                                                                                                                          |
|----------|---------|---------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| tolerant | Boolean | false   | When set to `true` it will collect syntax errors and place them in a list under the key `errors` inside the root node of the returned AST. Otherwise, it will raise a `parser.ParserError`.          |
| loc      | Boolean | false   | When set to `true`, it will add location information to each node, with start and stop keys that contain the corresponding line and column numbers. Column numbers start from 0, lines start from 1. |
| range    | Boolean | false   | When set to `true`, it will add range information to each node, which consists of a two-element array with start and stop character indexes in the input.                                            |


#### Example with location information

```javascript
parser.parse('contract test { uint a; }', { loc: true })

// { type: 'SourceUnit',
//   children:
//    [ { type: 'ContractDefinition',
//        name: 'test',
//        baseContracts: [],
//        subNodes: [Array],
//        kind: 'contract',
//        loc: [Object] } ],
//   loc: { start: { line: 1, column: 0 }, end: { line: 1, column: 24 } } }

```

#### Example using a visitor to walk over the AST

```javascript
var ast = parser.parse('contract test { uint a; }')

// output the path of each import found
parser.visit(ast, {
  ImportDirective: function(node) {
    console.log(node.path)
  }
})
```

### Author

Federico Bond ([@federicobond](https://github.com/federicobond))

### License

MIT

---
_Source: https://npm.io/package/solidity-parser-antlr · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
