Syntax tree printer utility
Project description
Python Syntax Tree Printer
This project is a Python-based syntax tree printer utility that reads a source code file, guesses the language based on the file extension, and prints the syntax tree using tree-sitter.
Features
- Supports Rust and Python source files
- Prints detailed syntax tree nodes
- Uses Tree-sitter for parsing
- Syntax highlighting for parse trees
- Lists all node IDs and their corresponding names for a language
Requirements
- Python 3.10+
- pip
Installation
-
Clone this repository:
git clone https://github.com/yourusername/python-syntax-tree-printer.git cd python-syntax-tree-printer
-
Install the required dependencies:
pip install .
Usage
-
Run the program with a file path as an argument to print the syntax tree:
tsutil <file-path>
-
Run the program with the
--highlight
flag to print the syntax tree with syntax highlighting:tsutil <file-path> --highlight
-
Run the program with the
--list-ids
flag to list all node IDs and their corresponding names for the language:tsutil <file-path> --list-ids
Example
To print the syntax tree of a Python source file:
tsutil example/simple_addition.py
To print the syntax tree with syntax highlighting:
tsutil example/simple_addition.py --highlight
To list all node IDs and their corresponding names for a Python source file:
tsutil example/simple_addition.py --list-ids
License
This project is licensed under the MIT License. See the LICENSE file for details.
Contributing
Contributions are welcome! Please open an issue or submit a pull request for any improvements or bug fixes.
Acknowledgements
- Tree-sitter for the parsing library
- py-tree-sitter for the Python bindings
- termcolor for terminal colorization
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 Distribution
Built Distribution
File details
Details for the file tsutil_py-0.1.0.tar.gz
.
File metadata
- Download URL: tsutil_py-0.1.0.tar.gz
- Upload date:
- Size: 2.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: pdm/2.16.1 CPython/3.11.5 Linux/5.15.0-91-generic
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 76f9daf3786317a7c03c34825c1e9db5f5225d1e966f4c6b643ae7eb86695909 |
|
MD5 | 373ad2882ca0757d2dabc6433e0b7a86 |
|
BLAKE2b-256 | cd8ba0ef35391cddc110b67268a78688df4c6e93da38c04ad25dbc7c01b8ac22 |
File details
Details for the file tsutil_py-0.1.0-py3-none-any.whl
.
File metadata
- Download URL: tsutil_py-0.1.0-py3-none-any.whl
- Upload date:
- Size: 3.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: pdm/2.16.1 CPython/3.11.5 Linux/5.15.0-91-generic
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | c05a8a5808b8ca2a76269c228154a4de26e7d8ea44e4ec831a8b13fa676d1c86 |
|
MD5 | 99fe479686e534a1cb4d98786908a4b7 |
|
BLAKE2b-256 | 20f1829f1b96bf448aa0c659c1e07da18ef68288cd063f12dcbcf1be8bc8da7f |