Skip to main content

Python bindings for tree-sitter parsers with Delphi-inspired architecture

Project description

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

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

tree_sitter_delphi-0.1.0.tar.gz (63.1 kB view details)

Uploaded Source

Built Distribution

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

tree_sitter_delphi-0.1.0-py3-none-any.whl (46.3 kB view details)

Uploaded Python 3

File details

Details for the file tree_sitter_delphi-0.1.0.tar.gz.

File metadata

  • Download URL: tree_sitter_delphi-0.1.0.tar.gz
  • Upload date:
  • Size: 63.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.3

File hashes

Hashes for tree_sitter_delphi-0.1.0.tar.gz
Algorithm Hash digest
SHA256 6384b68e43f503c2e3b82b63def5cb01be9656dffddd23a2a7084380b7e263fb
MD5 33693854e2ff6c6f2cf47ad71cf8b3d5
BLAKE2b-256 6bc8d96a56e95175d98c48f72c254b9bd601cbd7b6e245dcdb255f8bed9eac8e

See more details on using hashes here.

File details

Details for the file tree_sitter_delphi-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for tree_sitter_delphi-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 b0fac769106f220f6b47770a5a766219b19761c158b05cc764d85030901de4cb
MD5 5dbc283a6877253c7a9b1bc5e1ea48a1
BLAKE2b-256 3fa1ec492c47c41740532872c79f6434439af3cfdcd544056cb2f92a81f655ba

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