Skip to content

Ditching antlr4ts #103

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Dec 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .eslintignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
src/lib
src/antlr
scripts/tokens-string.js
scripts
2 changes: 2 additions & 0 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ jobs:
cache: 'npm'
- name: Install
run: npm install
- name: Install ANTLR4
run: pip install antlr4-tools
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you mind updating the https://github.com/solidity-parser/parser/blob/master/DEVELOPING.md document? I know it wasn't up to date to begin with, but I think it would be a good idea to do it now that we (again) use something other than npm.

Also, I think we can remove the scripts/antlr.sh file (mentioned in that outdated document).

- name: Build
run: npm run build
- name: Run integration
Expand Down
40 changes: 23 additions & 17 deletions CHANGES.md → CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,75 +1,81 @@
### 0.5.0 (Unreleased)
# 0.17.0

- Using the official typescript target for antlr4. (#103)
- Exponentiation is right associative. `a ** (b ** c)` (#99)
- Conditional expression is right associative. `a ? (b ? c : d) : (e ? f : g)` (#99)

# 0.5.0

- Remove `ParameterList` and `Parameter` node types. Parameters are now always
of type `VariableDeclaration` and lists of parameters are represented as
lists of nodes of type `VariableDeclaration`. This is a breaking change.

### 0.4.12 (Unreleased)
# 0.4.12

- Fix type name expressions to also support user-defined type names.

### 0.4.11
# 0.4.11

- Bugfix release

### 0.4.9
# 0.4.9

- Fix parsing of inheritance specifier with no arguments.

### 0.4.8
# 0.4.8

- Fix parsing of string literals with escaped characters.

### 0.4.7
# 0.4.7

- Fix parsing of underscores in number literals.

### 0.4.6
# 0.4.6

- Add support for the `type` keyword.
- Add support for underscores in number literals.

### 0.4.5
# 0.4.5

- Improve TypeScript type definitions.

### 0.4.4
# 0.4.4

- Add missing `storageLocation` to variables in VariableDeclarationStatement.
- Return `null` for `arguments` instead of `[]` when `ModifierInvocation`
contains no arguments and no parentheses to distinguish the two cases.
- Improve TypeScript type definitions.

### 0.4.3
# 0.4.3

- Improve TypeScript type definitions, thanks @Leeleo3x and @yxliang01.

### 0.4.2
# 0.4.2

- Fix parsing of assembly function definitions with no args or return args.

### 0.4.1
# 0.4.1

- Fix parsing of for loops with missing initial and condition statements.

### 0.4.0
# 0.4.0

- Correctly handle non-existent tuple components. Thanks @maxsam4
- Accept calldata as identifier

### 0.3.3
# 0.3.3

- Add support for `address payable` typename.

### 0.3.2
# 0.3.2

- Fix parsing of hex numbers with uppercase X.

### 0.3.1
# 0.3.1

- Fix parsing of zero-component tuples.

### 0.3.0
# 0.3.0

- Use `components` for all `TupleExpression` nodes. Earlier versions
incorrectly stored tuple components under the `elements` key.
Expand Down
22 changes: 18 additions & 4 deletions DEVELOPING.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,19 +27,33 @@ git submodule update --init

## Updating the grammar

The [`scripts/antlr.sh`](scripts/antlr.sh) script should download ANTLR and generate the grammar. For this to work, you
need Java (1.6 or higher) installed.
If you want to try changes made to the `antlr/Solidity.g4` file you need to generate the typescript files to reflect the changes.

To accomplish that, we rely on [antlr4-tools](https://github.com/antlr/antlr4-tools) to generate the grammar.

```bash
# it requires Python 3 but doesn't require Java.
# install antlr4-tools
pip install antlr4-tools
```

Once it is installed you just need to run the following `npm` script to generate the new grammar files.

```bash
# generate the grammar Typescript files
npm run antlr
```

## Updating the parser

Run `yarn build` to build the parser.
Run `npm run build` to build the parser.

## Quick testing

Right now the easier way to test something is to start the node REPL and import the project:

```
yarn build
npm run build
node
> parser = require('.')
> ast = parser.parse('contract Foo {}')
Expand Down
Loading