Skip to content

Commit b6a9602

Browse files
authoredMar 6, 2019
Update README.md
1 parent 908b7b0 commit b6a9602

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
lines changed
 

‎README.md

+18-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ A Solidity parser for Python built on top of a robust ANTLR4 grammar
77

88
```
99
#> pip3 install solidity_parser
10-
#> python3 -m solidity_parser <path_to_contract.sol> # prettyprints tree
10+
#> python3 -m solidity_parser <parse|outline> <path_to_contract.sol> # print parse tree or sourceUnit outline
1111
```
1212

1313
## HowTo
@@ -20,7 +20,9 @@ import pprint
2020
from solidity_parser import parser
2121

2222
sourceUnit = parser.parse_file(sys.argv[1])
23-
pprint.pprint(sourceUnit)
23+
pprint.pprint(sourceUnit)
24+
# see output below
25+
2426
```
2527

2628
output:
@@ -51,7 +53,21 @@ output:
5153

5254
Parse-tree nodes can be accessed both like dictionaries or via object attributes. Nodes always carry a `type` field to hint the type of AST node. The start node is always of type `sourceUnit`.
5355

56+
## Accessing AST items in an Object Oriented fashion
57+
58+
```python
59+
# ... continuing from previous snippet
5460

61+
# subparse into objects for nicer interfaces:
62+
# create a nested object structure from AST
63+
sourceUnitObject = parser.objectify(sourceUnit)
64+
65+
# access imports, contracts, functions, ... (see outline example in __main__.py)
66+
sourceUnitObject.imports # []
67+
sourceUnitObject.pragmas # []
68+
sourceUnitObject.contracts.keys() # get all contract names
69+
sourceUnitObject.contracts["contractName"].functions.keys() # get all functions in contract: "contractName"
70+
```
5571

5672

5773
## Generate the parser

0 commit comments

Comments
 (0)
Failed to load comments.