A library for programmatic software modification
Project description
Generic Tree-Sitter AST API
The ASTs package provides a Python API into GrammaTech's Software Evolution Library (SEL) for source code manipulation. SEL generalizes over GitHub's tree-sitter parsing libraries providing a uniform interface over multiple programming languages (primarily Python, JavaScript/TypeScript, C, C++, and Java; with lesser support for Bash, CSS, Go HTML, and Rust), and providing additional functionality for software inspection and modification.
See the methods provided by asts.py for more information.
Example usage:
$ python3
Python 3.8.5
Type "help", "copyright", "credits" or "license" for more information.
>>> import asts
>>> it = asts.AST("python", "x + 88")
>>> it.children()
[<asts.asts.AST object at 0x7f8e91fb52b0>]
>>> it.children()[0].children()
[<asts.asts.AST object at 0x7f8e918b7100>]
>>> it.children()[0].children()[0].children()
[<asts.asts.AST object at 0x7f8e918b7490>, <asts.asts.AST object at 0x7f8e918b73a0>, <asts.asts.AST object at 0x7f8e918b73d0>]
>>> it.children()[0].children()[0].children()[0].source_text()
'x'
>>> it.children()[0].children()[0].children()[1].source_text()
'+'
>>> it.children()[0].children()[0].children()[2].source_text()
'88'
>>> it.children()[0].children()[0].source_text()
'x + 88'
>>> it.children()[0].children()[0].child_slots()
[['PYTHON-LEFT', 1], ['PYTHON-OPERATOR', 1], ['PYTHON-RIGHT', 1], ['CHILDREN', 0]]
>>> list(map(lambda x:x.source_text(), it.children()[0].children()[0].children()))
['x', '+', '88']
>>> list(map(lambda x:x.ast_type(), it.children()[0].children()[0].children()))
['PYTHON-IDENTIFIER', 'PYTHON-+', 'PYTHON-INTEGER']
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
No source distribution files available for this release.See tutorial on generating distribution archives.
Built Distribution
asts-0.1.7.dev1-py3-none-any.whl
(24.7 MB
view hashes)
Close
Hashes for asts-0.1.7.dev1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a15c1784bd048c6727af09a1da5f28c33a86b5835cf5694d881cfcc46992b550 |
|
MD5 | d17f2fc1edb42fa8a557763f8315ea76 |
|
BLAKE2b-256 | 1addf9ad46ff223f7695929469b188219f49f1b02545b2ae2c28bb4b6879c470 |