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.
src/typepy/– main implementation packagegrammar.lark– language grammarparser.py– Lark parsererrors.py– error codes + reporterchecker/– type checker core + visitor modulestranspiler/– transpiler core + visitor modulesserver.py– LSP servercompiler.py– CLI (check/build/run)
src/*.py– compatibility wrappers that import fromsrc/typepy/tpy/– sample.tpyfilestests/– ad‑hoc checks
# 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.tpyThe checker and transpiler use a visitor registry so new grammar features can be implemented as standalone modules without editing core files.
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)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.
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.