Add transpiler with keywords and tests
This commit is contained in:
17
.gitignore
vendored
Normal file
17
.gitignore
vendored
Normal file
@@ -0,0 +1,17 @@
|
||||
# Python
|
||||
__pycache__/
|
||||
*.py[cod]
|
||||
*$py.class
|
||||
*.so
|
||||
.Python
|
||||
venv/
|
||||
.venv/
|
||||
|
||||
# Build
|
||||
*.egg-info/
|
||||
*.egg
|
||||
dist/
|
||||
build/
|
||||
|
||||
# uv
|
||||
*.egg
|
||||
@@ -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"
|
||||
|
||||
@@ -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()
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
{"காட்டு": "print"}
|
||||
@@ -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
1
tests/test.generated.py
Normal file
@@ -0,0 +1 @@
|
||||
print("Hello")
|
||||
1
tests/test.tampy
Normal file
1
tests/test.tampy
Normal file
@@ -0,0 +1 @@
|
||||
காட்டு("Hello")
|
||||
Reference in New Issue
Block a user