Add transpiler with keywords and tests

This commit is contained in:
2026-05-01 23:32:25 -05:00
parent 23af363dfb
commit a8e51967ed
8 changed files with 69 additions and 6 deletions

17
.gitignore vendored Normal file
View File

@@ -0,0 +1,17 @@
# Python
__pycache__/
*.py[cod]
*$py.class
*.so
.Python
venv/
.venv/
# Build
*.egg-info/
*.egg
dist/
build/
# uv
*.egg

View File

@@ -1 +1,12 @@
[project]
name = "tampy"
version = "0.1.0"
description = "Tamil Python transpiler"
requires-python = ">=3.8"
[project.scripts]
tampy = "tampy.cli:main"
[build-system]
requires = ["hatchling"]
build-backend = "hatchling.build"

View File

@@ -0,0 +1,26 @@
import argparse
import subprocess
import sys
from pathlib import Path
from .transpiler import transpile
def main():
parser = argparse.ArgumentParser(description="Tamil Python compiler")
parser.add_argument("file", help="Tamil Python file")
parser.add_argument("--build", action="store_true", help="Build only")
args = parser.parse_args()
code = Path(args.file).read_text(encoding="utf-8")
generated = transpile(code)
out = Path(args.file).with_suffix(".generated.py")
out.write_text(generated, encoding="utf-8")
print(f"Generated: {out.name}")
if not args.build:
subprocess.run([sys.executable, str(out)], capture_output=True)
if __name__ == "__main__":
main()

View File

@@ -0,0 +1 @@
{"காட்டு": "print"}

View File

@@ -0,0 +1,11 @@
import json
from pathlib import Path
KEYWORDS_PATH = Path(__file__).parent / "keywords.json"
with open(KEYWORDS_PATH, "r", encoding="utf-8") as f:
KEYWORDS = json.load(f)
def transpile(code: str) -> str:
for tamil, python in KEYWORDS.items():
code = code.replace(tamil, python)
return code

1
tests/test.generated.py Normal file
View File

@@ -0,0 +1 @@
print("Hello")

1
tests/test.tampy Normal file
View File

@@ -0,0 +1 @@
காட்டு("Hello")

7
uv.lock generated
View File

@@ -1,8 +1,3 @@
version = 1
revision = 3
requires-python = ">=3.8"
[[package]]
name = "tampy"
version = "0.1.0"
source = { editable = "." }
requires-python = ">=3.14"