Compare commits
8 Commits
foreigntho
...
develop
| Author | SHA1 | Date | |
|---|---|---|---|
| 92b2a59f95 | |||
| bc9e73ef88 | |||
| 393b947953 | |||
| 85e3837117 | |||
| 15f367131e | |||
| 83d8552977 | |||
| 606501d654 | |||
| d9c5042ec7 |
@@ -6,10 +6,10 @@ ForeignThon transpiles `.es.py`, `.ta.py` (and more) into standard Python. Keywo
|
|||||||
|
|
||||||
```python
|
```python
|
||||||
# hola.es.py
|
# hola.es.py
|
||||||
definir saludar(nombre):
|
def saludar(nombre):
|
||||||
retornar f"Hola, {nombre}!"
|
retornar f"Hola, {nombre}!"
|
||||||
|
|
||||||
para i en rango(3):
|
para i en dist(3):
|
||||||
imprimir(saludar(f"mundo {i}"))
|
imprimir(saludar(f"mundo {i}"))
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
|
|||||||
|
|
||||||
[project]
|
[project]
|
||||||
name = "foreignthon"
|
name = "foreignthon"
|
||||||
version = "0.5.0"
|
version = "0.5.2"
|
||||||
description = "Write Python in any language. Transpiles foreign-language .xx.py files to standard Python."
|
description = "Write Python in any language. Transpiles foreign-language .xx.py files to standard Python."
|
||||||
license = { text = "GPL v3" }
|
license = { text = "GPL v3" }
|
||||||
requires-python = ">=3.9"
|
requires-python = ">=3.9"
|
||||||
|
|||||||
@@ -253,28 +253,60 @@ def compile(file: Path, output: str | None):
|
|||||||
out_path.parent.mkdir(parents=True, exist_ok=True)
|
out_path.parent.mkdir(parents=True, exist_ok=True)
|
||||||
out_path.write_text(transpiled, encoding="utf-8")
|
out_path.write_text(transpiled, encoding="utf-8")
|
||||||
click.echo(f"Compiled: {out_path}")
|
click.echo(f"Compiled: {out_path}")
|
||||||
|
|
||||||
|
@main.command(context_settings=CONTEXT_SETTINGS)
|
||||||
|
@click.argument("files", nargs=-1, required=True, type=click.Path(exists=True, path_type=Path))
|
||||||
|
def check(files: tuple):
|
||||||
|
"""Validate one or more foreign-language files without running them."""
|
||||||
|
import ast
|
||||||
|
import io
|
||||||
|
import tokenize as _tokenize
|
||||||
|
|
||||||
|
from .transpiler import _build_mapping, transpile_file
|
||||||
|
|
||||||
|
failed = False
|
||||||
|
for file in files:
|
||||||
|
detected_lang = _lang_from_file(file)
|
||||||
|
try:
|
||||||
|
pack = _load_effective_pack(file, detected_lang)
|
||||||
|
transpiled = transpile_file(file, pack=pack)
|
||||||
|
ast.parse(transpiled)
|
||||||
|
|
||||||
|
source = file.read_text(encoding="utf-8")
|
||||||
|
mapping = _build_mapping(pack)
|
||||||
|
tokens = list(_tokenize.generate_tokens(io.StringIO(source).readline))
|
||||||
|
count = sum(1 for t in tokens if t.type == _tokenize.NAME and t.string in mapping)
|
||||||
|
|
||||||
|
click.echo(f"✓ {file.name} looks good. ({count} tokens translated)")
|
||||||
|
except SyntaxError as e:
|
||||||
|
click.echo(f"✗ {file.name}: Syntax error: {e}", err=True)
|
||||||
|
failed = True
|
||||||
|
except Exception as e:
|
||||||
|
click.echo(f"✗ {file.name}: {e}", err=True)
|
||||||
|
failed = True
|
||||||
|
|
||||||
|
if failed:
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
@main.command(context_settings=CONTEXT_SETTINGS)
|
@main.command(context_settings=CONTEXT_SETTINGS)
|
||||||
@click.argument("file", type=click.Path(exists=True, path_type=Path))
|
def langs():
|
||||||
def check(file: Path):
|
"""List all installed language packs."""
|
||||||
"""Validate a foreign-language file without running it."""
|
from .pack import _discover_packs
|
||||||
import ast
|
|
||||||
|
|
||||||
detected_lang = _lang_from_file(file)
|
|
||||||
try:
|
|
||||||
pack = _load_effective_pack(file, detected_lang)
|
|
||||||
transpiled = transpile_file(file, pack=pack)
|
|
||||||
ast.parse(transpiled)
|
|
||||||
click.echo(f"✓ {file.name} looks good.")
|
|
||||||
except SyntaxError as e:
|
|
||||||
click.echo(f"✗ Syntax error: {e}", err=True)
|
|
||||||
sys.exit(1)
|
|
||||||
except Exception as e:
|
|
||||||
click.echo(f"✗ {e}", err=True)
|
|
||||||
sys.exit(1)
|
|
||||||
|
|
||||||
|
packs = _discover_packs()
|
||||||
|
if not packs:
|
||||||
|
click.echo("No language packs installed.")
|
||||||
|
click.echo("Try: pip install foreignthon-es")
|
||||||
|
return
|
||||||
|
|
||||||
|
click.echo("Installed language packs:")
|
||||||
|
for code, module in sorted(packs.items()):
|
||||||
|
import json
|
||||||
|
data = json.loads(module.get_pack_path().read_text(encoding="utf-8"))
|
||||||
|
name = data["meta"].get("name", code)
|
||||||
|
native = data["meta"].get("native_name", "")
|
||||||
|
click.echo(f" {code:<6} {name} ({native})")
|
||||||
|
|
||||||
@main.command("pack", context_settings=CONTEXT_SETTINGS)
|
@main.command("pack", context_settings=CONTEXT_SETTINGS)
|
||||||
@click.argument("json_file", type=click.Path(exists=True, path_type=Path))
|
@click.argument("json_file", type=click.Path(exists=True, path_type=Path))
|
||||||
def validate_pack(json_file: Path):
|
def validate_pack(json_file: Path):
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ authors = [
|
|||||||
]
|
]
|
||||||
keywords = ["foreignthon", "spanish", "español"]
|
keywords = ["foreignthon", "spanish", "español"]
|
||||||
|
|
||||||
dependencies = ["foreignthon>=0.5.0"]
|
dependencies = ["foreignthon>=0.5.2"]
|
||||||
|
|
||||||
[project.entry-points."foreignthon.langs"]
|
[project.entry-points."foreignthon.langs"]
|
||||||
es = "foreignthon_es"
|
es = "foreignthon_es"
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ authors = [
|
|||||||
{ name = "Keshav Anand", email = "keshavanand.dev@gmail.com" }
|
{ name = "Keshav Anand", email = "keshavanand.dev@gmail.com" }
|
||||||
]
|
]
|
||||||
keywords = ["foreignthon", "tamil", "தமிழ்"]
|
keywords = ["foreignthon", "tamil", "தமிழ்"]
|
||||||
dependencies = ["foreignthon>=0.5.0"]
|
dependencies = ["foreignthon>=0.5.2"]
|
||||||
|
|
||||||
[project.entry-points."foreignthon.langs"]
|
[project.entry-points."foreignthon.langs"]
|
||||||
ta = "foreignthon_ta"
|
ta = "foreignthon_ta"
|
||||||
|
|||||||
Reference in New Issue
Block a user