Skip to content

AscenderTeam/typepy

Repository files navigation

TypePy

TypePy is a small experimental language with a Python‑like runtime and a TypeScript‑style surface syntax. It includes a parser, type checker, transpiler to Python, and an LSP server.

Project Layout

  • src/typepy/ – main implementation package
    • grammar.lark – language grammar
    • parser.py – Lark parser
    • errors.py – error codes + reporter
    • checker/ – type checker core + visitor modules
    • transpiler/ – transpiler core + visitor modules
    • server.py – LSP server
    • compiler.py – CLI (check/build/run)
  • src/*.py – compatibility wrappers that import from src/typepy/
  • tpy/ – sample .tpy files
  • tests/ – ad‑hoc checks

Quick Start

# Type-check
python src/compiler.py check path/to/file.tpy

# Transpile to .py
python src/compiler.py build path/to/file.tpy

# Run (transpile to temp .py and execute)
python src/compiler.py run path/to/file.tpy

Extending the Language

The checker and transpiler use a visitor registry so new grammar features can be implemented as standalone modules without editing core files.

Checker visitors

Create a module in src/typepy/checker/visitors/ that defines a register(checker) function.

# src/typepy/checker/visitors/my_feature.py

def check_my_node(checker, node):
    ...

def register(checker):
    checker.register_visitor("my_node", check_my_node)

Transpiler visitors

Create a module in src/typepy/transpiler/visitors/ that defines a register(transpiler) function.

# src/typepy/transpiler/visitors/my_feature.py

def visit_my_node(transpiler, node):
    return "..."

def register(transpiler):
    transpiler.register_visitor("my_node", visit_my_node)

The registries auto‑discover and load all modules in their visitors/ folders.

LSP

The LSP server is src/typepy/server.py (wrapper at src/server.py). It provides diagnostics, hover, go‑to‑definition, and references for .tpy files.

About

An experimental specified typing language for python, it uses typescript/python style surface syntax.

Resources

Contributing

Stars

1 star

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors