Skip to main content

Delphi Tree Sitter Python Library

A Python library providing bindings for tree-sitter parsers, enabling powerful syntax analysis and code manipulation capabilities.

Features

  • Parser: Parse source code into syntax trees
  • Language Support: Work with different programming languages
  • Tree Navigation: Traverse and analyze syntax trees
  • Query System: Find patterns in code using tree-sitter queries
  • Node Inspection: Access detailed information about syntax nodes

Installation

From Source

git clone https://github.com/yourusername/delphi-tree-sitter.git
cd delphi-tree-sitter/python
pip install -e .

Development Installation

git clone https://github.com/yourusername/delphi-tree-sitter.git
cd delphi-tree-sitter/python
pip install -e ".[dev]"

Quick Start

from delphi_tree_sitter import Parser, Language

# Create a parser
parser = Parser()

# Set the language (you'll need to load a language library)
# language = Language.from_library("path/to/language.so")
# parser.set_language(language)

# Parse some code
source_code = """
def hello_world():
    print("Hello, World!")
"""

# tree = parser.parse(source_code)
# root = tree.root_node
# print(f"Root node type: {root.type}")

API Reference

Parser

The Parser class is the main entry point for parsing source code.

from delphi_tree_sitter import Parser

parser = Parser()
parser.set_language(language)
tree = parser.parse(source_code)

Tree and Node

Work with syntax trees and their nodes:

tree = parser.parse(source_code)
root = tree.root_node

# Navigate the tree
for child in root.children():
    print(f"Child type: {child.type}")
    print(f"Child text: {child.text}")

Query System

Find patterns in code using tree-sitter queries:

from delphi_tree_sitter import Query, QueryCursor

query = Query(language, """
(function_definition
  name: (identifier) @function_name
  body: (block) @function_body)
""")

cursor = QueryCursor()
cursor.execute(query, tree.root_node)

while True:
    match = cursor.next_match()
    if match is None:
        break
    
    function_name = match.captures.get("function_name")
    function_body = match.captures.get("function_body")
    print(f"Found function: {function_name.text}")

Language Support

This library supports any language that has a tree-sitter grammar. Popular languages include:

  • Python
  • JavaScript/TypeScript
  • C/C++
  • Java
  • Go
  • Rust
  • And many more...

To use a language, you need to load its tree-sitter grammar library.

Development

Running Tests

pytest

Code Formatting

black delphi_tree_sitter/

Type Checking

mypy delphi_tree_sitter/

Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Add tests
  5. Submit a pull request

License

This project is licensed under the MIT License - see the LICENSE file for details.

Related Projects

Metadata

Release files for tree-sitter-delphi 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for tree-sitter-delphi 0.1.0
File Size Uploaded
tree_sitter_delphi-0.1.0.tar.gz 63.1 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for tree-sitter-delphi 0.1.0
File Interpreter ABI Platform
tree_sitter_delphi-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 109.4 kB

Release files / tree_sitter_delphi-0.1.0.tar.gz

Download URL tree_sitter_delphi-0.1.0.tar.gz
Size 63.1 kB
Tags Source
SHA-256 checksum
How to use checksums
6384b68e43f503c2e3b82b63def5cb01be9656dffddd23a2a7084380b7e263fb
BLAKE2b-256 checksum
How to use checksums
6bc8d96a56e95175d98c48f72c254b9bd601cbd7b6e245dcdb255f8bed9eac8e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.3

Release files / tree_sitter_delphi-0.1.0-py3-none-any.whl

Download URL tree_sitter_delphi-0.1.0-py3-none-any.whl
Size 46.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
b0fac769106f220f6b47770a5a766219b19761c158b05cc764d85030901de4cb
BLAKE2b-256 checksum
How to use checksums
3fa1ec492c47c41740532872c79f6434439af3cfdcd544056cb2f92a81f655ba
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.3

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page