Skip to content

Commit 0eb1244

Browse files
sambachacassc
andauthored
combined updates (Consensys#1) (#1)
Co-authored-by: cl <chencassc@gmail.com>
1 parent 5b0977c commit 0eb1244

15 files changed

+3510
-3169
lines changed

.github/workflows/python.yml

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
name: Python package
2+
3+
on: [push]
4+
5+
jobs:
6+
build:
7+
8+
runs-on: ubuntu-latest
9+
strategy:
10+
matrix:
11+
python-version: ["3.7", "3.8", "3.9", "3.10", "3.11"]
12+
13+
steps:
14+
- uses: actions/checkout@v3
15+
- name: Set up Python ${{ matrix.python-version }}
16+
uses: actions/setup-python@v4
17+
with:
18+
python-version: ${{ matrix.python-version }}
19+
- name: Install dependencies
20+
run: |
21+
python -m pip install --upgrade pip
22+
pip install ruff pytest
23+
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
24+
- name: Lint with ruff
25+
run: |
26+
# stop the build if there are Python syntax errors or undefined names
27+
ruff --format=github --select=E9,F63,F7,F82 --target-version=py37 .
28+
# default set of ruff rules with GitHub Annotations
29+
ruff --format=github --target-version=py37 .
30+
- name: Test with pytest
31+
run: |
32+
pytest

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,3 +114,5 @@ dmypy.json
114114

115115
# Pyre type checker
116116
.pyre/
117+
.DS_Store
118+
.env

LICENSE.txt

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
MIT License
2+
3+
Copyright (c) 2020 Consensys, Inc.
4+
Copyright (c) 2023 Manifold Finance, Inc.
5+
6+
Permission is hereby granted, free of charge, to any person obtaining a copy
7+
of this software and associated documentation files (the "Software"), to deal
8+
in the Software without restriction, including without limitation the rights
9+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
copies of the Software, and to permit persons to whom the Software is
11+
furnished to do so, subject to the following conditions:
12+
13+
The above copyright notice and this permission notice shall be included in all
14+
copies or substantial portions of the Software.
15+
16+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
SOFTWARE.

scripts/antlr4.sh

100644100755
Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,26 @@
1-
#!/usr/bin/env sh
2-
1+
#!/usr/bin/env bash
32
set -o errexit
43

5-
antlr -Dlanguage=Python3 solidity-antlr4/Solidity.g4 -o src -visitor
4+
# antlr -Dlanguage=Python3 solidity-antlr4/Solidity.g4 -o src -visitor
5+
6+
7+
git submodule sync --recursive && git submodule update --init --recursive
8+
git submodule foreach --recursive git clean -ffdx
9+
git submodule update --remote --rebase solidity-antlr4
10+
11+
12+
bash solidity-antlr4/build.sh
13+
sleep 1
14+
15+
[ ! -f ./solidity-antlr4/antlr4.jar ] && { echo "ANTLR4 Jar does not exist."; exit 1; }
16+
17+
chmod +x ./solidity-antlr4/antlr4.jar
18+
java -jar ./solidity-antlr4/antlr4.jar -Dlanguage=Python3 solidity-antlr4/Solidity.g4 -o src -visitor || exit 1
619

720
mv src/solidity-antlr4/* solidity_parser/solidity_antlr4
821
rm -rf src/solidity-antlr4
922

1023
touch solidity_parser/solidity_antlr4/__init__.py
1124
touch solidity_parser/solidity_antlr4/__AUTOGENERATED__
25+
echo "Autogeneration and update FINISHED"
26+
exit 0

setup.py

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
1-
#!/usr/bin/env python
1+
#!/usr/bin/env python3
22
# -*- coding: utf-8 -*-
33

4-
'''
4+
"""
55
66
deps (requires up2date version):
77
*) pip install --upgrade pip wheel setuptools twine
88
publish to pypi w/o having to convert Readme.md to RST:
99
1) #> python setup.py sdist bdist_wheel
1010
2) #> twine upload dist/* #<specify bdist_wheel version to upload>; #optional --repository <testpypi> or --repository-url <testpypi-url>
1111
12-
'''
12+
"""
1313
import os
1414
from setuptools import setup, find_packages
1515

@@ -18,8 +18,8 @@ def read(fname):
1818
return open(os.path.join(os.path.dirname(__file__), fname)).read()
1919

2020

21-
version = "0.1.1"
22-
name = "solidity-parser"
21+
version = "0.1.3"
22+
name = "python-solidity-parser"
2323

2424
setup(
2525
name=name,
@@ -28,15 +28,16 @@ def read(fname):
2828
author="tintinweb",
2929
author_email="tintinweb@oststrom.com",
3030
description=(
31-
"A Solidity parser for Python built on top of a robust ANTLR4 grammar"),
31+
"A Solidity parser for Python built on top of a robust ANTLR4 grammar"
32+
),
3233
license="MIT",
33-
keywords=["solidity","parser","antlr"],
34-
url="https://github.com/consensys/python-%s/"%name,
35-
download_url="https://github.com/consensys/python-%s/tarball/v%s"%(name, version),
34+
keywords=["solidity", "parser", "antlr"],
35+
url="https://github.com/consensys/python-%s/" % name,
36+
download_url="https://github.com/consensys/python-%s/tarball/v%s" % (name, version),
3637
long_description=read("README.md") if os.path.isfile("README.md") else "",
37-
long_description_content_type='text/markdown',
38-
#python setup.py register -r https://testpypi.python.org/pypi
38+
long_description_content_type="text/markdown",
39+
# python setup.py register -r https://testpypi.python.org/pypi
3940
install_requires=["antlr4-python3-runtime==4.9.3"],
40-
#test_suite="nose.collector",
41-
#tests_require=["nose"],
41+
# test_suite="nose.collector",
42+
# tests_require=["nose"],
4243
)

solidity_parser/parser.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,8 @@ def visitFunctionDefinition(self, ctx: SolidityParser.FunctionDefinitionContext)
181181
elif fd.identifier():
182182
name = fd.identifier().getText()
183183
else:
184-
name = ctx.getText()
184+
name = '' # handle old style fallback function: function(){ ... }
185+
isFallback = True
185186

186187
parameters = self.visit(ctx.parameterList())
187188
returnParameters = self.visit(ctx.returnParameters()) if ctx.returnParameters() else []
@@ -744,9 +745,11 @@ def visitVariableDeclarationList(self, ctx: SolidityParser.VariableDeclarationLi
744745
if decl == None:
745746
return None
746747

748+
ident = decl.identifier()
749+
name = ident and ident.getText() or '_'
747750
result.append(self._createNode(ctx=ctx,
748751
type='VariableDeclaration',
749-
name=decl.identifier().getText(),
752+
name=name,
750753
typeName=self.visit(decl.typeName()),
751754
isStateVar=False,
752755
isIndexed=False,
@@ -845,9 +848,14 @@ def visitAssemblyExpression(self, ctx):
845848
return self.visit(ctx.getChild(0))
846849

847850
def visitAssemblyMember(self, ctx):
851+
if type(ctx.identifier()) == list:
852+
# handle the case, eg. x.slot
853+
name = ctx.identifier()[0].getText()
854+
else:
855+
name = ctx.identifier().getText()
848856
return Node(ctx=ctx,
849857
type='AssemblyMember',
850-
name=ctx.identifier().getText())
858+
name=name)
851859

852860
def visitAssemblyCall(self, ctx):
853861
functionName = ctx.getChild(0).getText()

solidity_parser/solidity_antlr4/Solidity.interp

Lines changed: 18 additions & 14 deletions
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)