Skip to content
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
32 changes: 32 additions & 0 deletions .github/workflows/python.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: Python package

on: [push]

jobs:
build:

runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.7", "3.8", "3.9", "3.10", "3.11"]

steps:
- uses: actions/checkout@v3
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install ruff pytest
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
- name: Lint with ruff
run: |
# stop the build if there are Python syntax errors or undefined names
ruff --format=github --select=E9,F63,F7,F82 --target-version=py37 .
# default set of ruff rules with GitHub Annotations
ruff --format=github --target-version=py37 .
- name: Test with pytest
run: |
pytest
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -114,3 +114,5 @@ dmypy.json

# Pyre type checker
.pyre/
.DS_Store
.env
22 changes: 22 additions & 0 deletions LICENSE.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
MIT License

Copyright (c) 2020 Consensys, Inc.
Copyright (c) 2023 Manifold Finance, Inc.

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
21 changes: 18 additions & 3 deletions scripts/antlr4.sh
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,11 +1,26 @@
#!/usr/bin/env sh

#!/usr/bin/env bash
set -o errexit

antlr -Dlanguage=Python3 solidity-antlr4/Solidity.g4 -o src -visitor
# antlr -Dlanguage=Python3 solidity-antlr4/Solidity.g4 -o src -visitor


git submodule sync --recursive && git submodule update --init --recursive
git submodule foreach --recursive git clean -ffdx
git submodule update --remote --rebase solidity-antlr4


bash solidity-antlr4/build.sh
sleep 1

[ ! -f ./solidity-antlr4/antlr4.jar ] && { echo "ANTLR4 Jar does not exist."; exit 1; }

chmod +x ./solidity-antlr4/antlr4.jar
java -jar ./solidity-antlr4/antlr4.jar -Dlanguage=Python3 solidity-antlr4/Solidity.g4 -o src -visitor || exit 1

mv src/solidity-antlr4/* solidity_parser/solidity_antlr4
rm -rf src/solidity-antlr4

touch solidity_parser/solidity_antlr4/__init__.py
touch solidity_parser/solidity_antlr4/__AUTOGENERATED__
echo "Autogeneration and update FINISHED"
exit 0
27 changes: 14 additions & 13 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
#!/usr/bin/env python
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

'''
"""

deps (requires up2date version):
*) pip install --upgrade pip wheel setuptools twine
publish to pypi w/o having to convert Readme.md to RST:
1) #> python setup.py sdist bdist_wheel
2) #> twine upload dist/* #<specify bdist_wheel version to upload>; #optional --repository <testpypi> or --repository-url <testpypi-url>

'''
"""
import os
from setuptools import setup, find_packages

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


version = "0.1.1"
name = "solidity-parser"
version = "0.1.3"
name = "python-solidity-parser"

setup(
name=name,
Expand All @@ -28,15 +28,16 @@ def read(fname):
author="tintinweb",
author_email="tintinweb@oststrom.com",
description=(
"A Solidity parser for Python built on top of a robust ANTLR4 grammar"),
"A Solidity parser for Python built on top of a robust ANTLR4 grammar"
),
license="MIT",
keywords=["solidity","parser","antlr"],
url="https://github.com/consensys/python-%s/"%name,
download_url="https://github.com/consensys/python-%s/tarball/v%s"%(name, version),
keywords=["solidity", "parser", "antlr"],
url="https://github.com/consensys/python-%s/" % name,
download_url="https://github.com/consensys/python-%s/tarball/v%s" % (name, version),
long_description=read("README.md") if os.path.isfile("README.md") else "",
long_description_content_type='text/markdown',
#python setup.py register -r https://testpypi.python.org/pypi
long_description_content_type="text/markdown",
# python setup.py register -r https://testpypi.python.org/pypi
install_requires=["antlr4-python3-runtime==4.9.3"],
#test_suite="nose.collector",
#tests_require=["nose"],
# test_suite="nose.collector",
# tests_require=["nose"],
)
2 changes: 1 addition & 1 deletion solidity-antlr4
Submodule solidity-antlr4 updated 2 files
+33 −20 Solidity.g4
+300 −120 test.sol
14 changes: 11 additions & 3 deletions solidity_parser/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,8 @@ def visitFunctionDefinition(self, ctx: SolidityParser.FunctionDefinitionContext)
elif fd.identifier():
name = fd.identifier().getText()
else:
name = ctx.getText()
name = '' # handle old style fallback function: function(){ ... }
isFallback = True

parameters = self.visit(ctx.parameterList())
returnParameters = self.visit(ctx.returnParameters()) if ctx.returnParameters() else []
Expand Down Expand Up @@ -744,9 +745,11 @@ def visitVariableDeclarationList(self, ctx: SolidityParser.VariableDeclarationLi
if decl == None:
return None

ident = decl.identifier()
name = ident and ident.getText() or '_'
result.append(self._createNode(ctx=ctx,
type='VariableDeclaration',
name=decl.identifier().getText(),
name=name,
typeName=self.visit(decl.typeName()),
isStateVar=False,
isIndexed=False,
Expand Down Expand Up @@ -845,9 +848,14 @@ def visitAssemblyExpression(self, ctx):
return self.visit(ctx.getChild(0))

def visitAssemblyMember(self, ctx):
if type(ctx.identifier()) == list:
# handle the case, eg. x.slot
name = ctx.identifier()[0].getText()
else:
name = ctx.identifier().getText()
return Node(ctx=ctx,
type='AssemblyMember',
name=ctx.identifier().getText())
name=name)

def visitAssemblyCall(self, ctx):
functionName = ctx.getChild(0).getText()
Expand Down
32 changes: 18 additions & 14 deletions solidity_parser/solidity_antlr4/Solidity.interp

Large diffs are not rendered by default.

Loading