From a8e51967ed3df466fa146623ff306c51ce3195d2 Mon Sep 17 00:00:00 2001 From: KeshavAnandCode Date: Fri, 1 May 2026 23:32:25 -0500 Subject: [PATCH] Add transpiler with keywords and tests --- .gitignore | 17 +++++++++++++++++ pyproject.toml | 11 +++++++++++ src/tampy/cli.py | 26 ++++++++++++++++++++++++++ src/tampy/keywords.json | 1 + src/tampy/transpiler.py | 11 +++++++++++ tests/test.generated.py | 1 + tests/test.tampy | 1 + uv.lock | 7 +------ 8 files changed, 69 insertions(+), 6 deletions(-) create mode 100644 .gitignore create mode 100644 tests/test.generated.py create mode 100644 tests/test.tampy diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..5ddc541 --- /dev/null +++ b/.gitignore @@ -0,0 +1,17 @@ +# Python +__pycache__/ +*.py[cod] +*$py.class +*.so +.Python +venv/ +.venv/ + +# Build +*.egg-info/ +*.egg +dist/ +build/ + +# uv +*.egg diff --git a/pyproject.toml b/pyproject.toml index 8b13789..7de6c78 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -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" diff --git a/src/tampy/cli.py b/src/tampy/cli.py index e69de29..cfb9e21 100644 --- a/src/tampy/cli.py +++ b/src/tampy/cli.py @@ -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() diff --git a/src/tampy/keywords.json b/src/tampy/keywords.json index e69de29..21a119c 100644 --- a/src/tampy/keywords.json +++ b/src/tampy/keywords.json @@ -0,0 +1 @@ +{"காட்டு": "print"} \ No newline at end of file diff --git a/src/tampy/transpiler.py b/src/tampy/transpiler.py index e69de29..c56c517 100644 --- a/src/tampy/transpiler.py +++ b/src/tampy/transpiler.py @@ -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 diff --git a/tests/test.generated.py b/tests/test.generated.py new file mode 100644 index 0000000..a3ea3c6 --- /dev/null +++ b/tests/test.generated.py @@ -0,0 +1 @@ +print("Hello") \ No newline at end of file diff --git a/tests/test.tampy b/tests/test.tampy new file mode 100644 index 0000000..ead5d0f --- /dev/null +++ b/tests/test.tampy @@ -0,0 +1 @@ +காட்டு("Hello") \ No newline at end of file diff --git a/uv.lock b/uv.lock index e872565..a5bc514 100644 --- a/uv.lock +++ b/uv.lock @@ -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"