Skip to main content

A Solidity parser for Python built on top of a robust ANTLR4 grammar

Project description

python-solidity-parser

A Solidity parser for Python built on top of a robust ANTLR4 grammar

This is a python3 port of the javascript antlr parser maintained by @federicobond. Interfaces are intentionally following the javascript impelementation and therefore not pep8 compliant.

Install

#> pip3 install solidity_parser
#> python3 -m solidity_parser <path_to_contract.sol>   # prettyprints tree

HowTo

import sys
import pprint

from solidity_parser import parser

sourceUnit = parser.parse_file(sys.argv[1])
pprint.pprint(sourceUnit)

output:

{'type': 'SourceUnit',
 'children': [{'type': 'PragmaDirective',
               'name': 'solidity',
               'value': '^0.4.22'},
              {'type': 'ContractDefinition'},
               'baseContracts': [],
               'kind': 'contract',
               'name': 'SimpleAuction',
               'subNodes': [{'initialValue': None,
                             'type': 'StateVariableDeclaration',
                             'variables': [{'expression': None,
                                            'isDeclaredConst': False,
                                            'isIndexed': False,
                                            'isStateVar': True,
                                            'name': 'beneficiary',
                                            'type': 'VariableDeclaration',
                                            'typeName': {'name': 'address',
                                                         'type': 'ElementaryTypeName'},
                                            'visibility': 'public'}]},
...

Nodes

parse nodes can be accessed like dictionaries or object attributes. Nodes always carry a type field to denote the type of information provided. The first node is of type sourceUnit.

Generate the parser

Update the grammar in ./solidity-antlr4/Solidity.g4 and run the antlr generator script to create the parser classes in solidity_parser/solidity_antlr4.

#> bash script/antlr4.sh

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

solidity-parser-0.0.1.tar.gz (55.9 kB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

solidity_parser-0.0.1-py3.7.egg (18.7 kB view details)

Uploaded Egg

solidity_parser-0.0.1-py3-none-any.whl (67.2 kB view details)

Uploaded Python 3

File details

Details for the file solidity-parser-0.0.1.tar.gz.

File metadata

  • Download URL: solidity-parser-0.0.1.tar.gz
  • Upload date:
  • Size: 55.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.7.2

File hashes

Hashes for solidity-parser-0.0.1.tar.gz
Algorithm Hash digest
SHA256 996463678c7442321f6a4ee50c60d9c12b8fcc31af0d2aaf50050775d00f91e0
MD5 c7f64a030f6bbec81a73b97e341f903a
BLAKE2b-256 0c45257f2bcd6d7852ca25c501bbc0f55aff7b537373a0492c0e34e4308e876d

See more details on using hashes here.

File details

Details for the file solidity_parser-0.0.1-py3.7.egg.

File metadata

  • Download URL: solidity_parser-0.0.1-py3.7.egg
  • Upload date:
  • Size: 18.7 kB
  • Tags: Egg
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.7.2

File hashes

Hashes for solidity_parser-0.0.1-py3.7.egg
Algorithm Hash digest
SHA256 23e4852fc36898ed6b59d526e59de91316b1df7f22b680b42d453fbf668cc218
MD5 e3cc4b3f068eba09585b2ecd03062168
BLAKE2b-256 d02a950ce2f5fe45fdc821e76be0e3c0eb9b419f94be91f261378b384c935e06

See more details on using hashes here.

File details

Details for the file solidity_parser-0.0.1-py3-none-any.whl.

File metadata

  • Download URL: solidity_parser-0.0.1-py3-none-any.whl
  • Upload date:
  • Size: 67.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.7.2

File hashes

Hashes for solidity_parser-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 f24ac3380562d9bb4f2266a8a607ff8d48bd8c234193cab16ede1be24681402e
MD5 3f3b54c9740d2699c05be09418a3ed86
BLAKE2b-256 19730725ef1e23f354e2742d54a8eddc54eb3f7bfa0503022ac681a04b61e09b

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page