Compare commits
21 Commits
v0.1.1
...
lang/chine
| Author | SHA1 | Date | |
|---|---|---|---|
| f7de0fc671 | |||
| 773e56b619 | |||
| e5cc2e2feb | |||
| 3fe496f8d9 | |||
| 3093b4328d | |||
| 70a220158c | |||
| 15b91d0f6d | |||
| 8f99503d6b | |||
| 2041c167cb | |||
| 6dc44dc5bc | |||
| 1bb09774d9 | |||
| 862aeaebbc | |||
| 084f05a2c1 | |||
| ef87091391 | |||
| b31ba536e4 | |||
| 9fb33f5999 | |||
| 694b798315 | |||
| 2aa8e91a68 | |||
| 3a4dd21585 | |||
| 0ff6b2483e | |||
| 439e555e50 |
@@ -22,6 +22,8 @@ jobs:
|
||||
run: |
|
||||
pip install -e "packages/foreignthon[dev]"
|
||||
pip install -e packages/langs/es
|
||||
pip install -e packages/langs/ta
|
||||
|
||||
continue-on-error: true
|
||||
|
||||
- name: Run tests
|
||||
|
||||
@@ -3,7 +3,8 @@ name: Publish
|
||||
on:
|
||||
push:
|
||||
tags:
|
||||
- "v*"
|
||||
- "foreignthon-v*"
|
||||
- "foreignthon-*-v*"
|
||||
|
||||
jobs:
|
||||
publish:
|
||||
@@ -20,62 +21,67 @@ jobs:
|
||||
- name: Install build tools
|
||||
run: pip install build twine
|
||||
|
||||
- name: Build core package
|
||||
run: python -m build packages/foreignthon
|
||||
- name: Determine what to build
|
||||
id: target
|
||||
run: |
|
||||
TAG=${GITHUB_REF#refs/tags/}
|
||||
echo "Full tag: $TAG"
|
||||
|
||||
- name: Build Spanish pack
|
||||
run: python -m build packages/langs/es
|
||||
|
||||
- name: Build Tamil pack
|
||||
run: python -m build packages/langs/ta
|
||||
if [[ "$TAG" == "foreignthon-v"* ]]; then
|
||||
# Core package: foreignthon-v0.2.0
|
||||
echo "type=core" >> $GITHUB_OUTPUT
|
||||
echo "path=packages/foreignthon" >> $GITHUB_OUTPUT
|
||||
echo "name=foreignthon" >> $GITHUB_OUTPUT
|
||||
elif [[ "$TAG" == "foreignthon-"*"-v"* ]]; then
|
||||
# Lang pack: foreignthon-es-v0.1.0 → lang code is "es"
|
||||
LANG=$(echo $TAG | sed 's/foreignthon-\(.*\)-v.*/\1/')
|
||||
echo "type=lang" >> $GITHUB_OUTPUT
|
||||
echo "path=packages/langs/$LANG" >> $GITHUB_OUTPUT
|
||||
echo "name=foreignthon-$LANG" >> $GITHUB_OUTPUT
|
||||
fi
|
||||
|
||||
- name: Build package
|
||||
run: python -m build ${{ steps.target.outputs.path }}
|
||||
|
||||
- name: Publish to PyPI
|
||||
env:
|
||||
TWINE_USERNAME: __token__
|
||||
TWINE_PASSWORD: ${{ secrets.PYPI_TOKEN }}
|
||||
run: |
|
||||
twine upload --skip-existing packages/foreignthon/dist/*
|
||||
twine upload --skip-existing packages/langs/es/dist/*
|
||||
twine upload --skip-existing packages/langs/ta/dist/*
|
||||
|
||||
run: twine upload --skip-existing ${{ steps.target.outputs.path }}/dist/*
|
||||
|
||||
- name: Create Gitea release with assets
|
||||
env:
|
||||
GIT_RELEASE_TOKEN: ${{ secrets.GIT_RELEASE_TOKEN }}
|
||||
run: |
|
||||
TAG=${GITHUB_REF#refs/tags/}
|
||||
echo "Tag: $TAG"
|
||||
|
||||
# Delete existing release if any
|
||||
EXISTING=$(curl -s \
|
||||
-H "Authorization: token $GIT_RELEASE_TOKEN" \
|
||||
"${{ github.server_url }}/api/v1/repos/${{ github.repository }}/releases/tags/$TAG")
|
||||
EXISTING_ID=$(echo $EXISTING | python -c "import sys,json; d=json.load(sys.stdin); print(d.get('id',''))" 2>/dev/null || echo "")
|
||||
EXISTING_ID=$(echo $EXISTING | python -c \
|
||||
"import sys,json; d=json.load(sys.stdin); print(d.get('id',''))" 2>/dev/null || echo "")
|
||||
|
||||
if [ -n "$EXISTING_ID" ]; then
|
||||
echo "Deleting existing release $EXISTING_ID"
|
||||
curl -s -X DELETE \
|
||||
-H "Authorization: token $GIT_RELEASE_TOKEN" \
|
||||
"${{ github.server_url }}/api/v1/repos/${{ github.repository }}/releases/$EXISTING_ID"
|
||||
fi
|
||||
|
||||
# Create fresh release
|
||||
RELEASE=$(curl -s -X POST \
|
||||
-H "Authorization: token $GIT_RELEASE_TOKEN" \
|
||||
-H "Content-Type: application/json" \
|
||||
-d "{
|
||||
\"tag_name\": \"$TAG\",
|
||||
\"name\": \"$TAG\",
|
||||
\"body\": \"Release $TAG\",
|
||||
\"name\": \"${{ steps.target.outputs.name }} ${TAG##*-v}\",
|
||||
\"body\": \"Release of ${{ steps.target.outputs.name }} ${TAG##*-v}\",
|
||||
\"draft\": false,
|
||||
\"prerelease\": false
|
||||
}" \
|
||||
"${{ github.server_url }}/api/v1/repos/${{ github.repository }}/releases")
|
||||
|
||||
echo "Release response: $RELEASE"
|
||||
RELEASE_ID=$(echo $RELEASE | python -c "import sys,json; print(json.load(sys.stdin)['id'])")
|
||||
|
||||
for FILE in packages/foreignthon/dist/* packages/langs/es/dist/*; do
|
||||
for FILE in ${{ steps.target.outputs.path }}/dist/*; do
|
||||
echo "Uploading $FILE"
|
||||
curl -s -X POST \
|
||||
-H "Authorization: token $GIT_RELEASE_TOKEN" \
|
||||
|
||||
@@ -1,51 +0,0 @@
|
||||
# Contributing to ForeignThon
|
||||
|
||||
## Project structure
|
||||
foreignthon/
|
||||
├── packages/
|
||||
│ ├── foreignthon/ # core engine + fpy CLI
|
||||
│ │ ├── src/foreignthon/
|
||||
│ │ │ ├── cli.py # fpy commands
|
||||
│ │ │ ├── transpiler.py # tokenizer-based transpiler
|
||||
│ │ │ ├── pack.py # language pack loader
|
||||
│ │ │ └── errors.py # bilingual error hook
|
||||
│ │ └── tests/
|
||||
│ └── langs/
|
||||
│ └── es/ # Spanish language pack
|
||||
│ └── src/foreignthon_es/es.json
|
||||
|
||||
## Setting up
|
||||
|
||||
```bash
|
||||
python -m venv .venv && source .venv/bin/activate
|
||||
pip install -e "packages/foreignthon[dev]"
|
||||
pip install -e packages/langs/es
|
||||
```
|
||||
|
||||
## Running tests
|
||||
|
||||
```bash
|
||||
pytest packages/foreignthon/tests/ -v
|
||||
```
|
||||
|
||||
## Adding a new language pack
|
||||
|
||||
1. Copy `packages/langs/es/` to `packages/langs/<code>/`
|
||||
2. Rename `foreignthon_es` → `foreignthon_<code>` throughout
|
||||
3. Fill in `<code>.json` following the same schema as `es.json`
|
||||
4. Validate it: `fpy pack packages/langs/<code>/src/foreignthon_<code>/<code>.json`
|
||||
5. Add tests if the language has tricky characters or edge cases
|
||||
6. Open a PR or publish independently as `foreignthon-<code>` on PyPI
|
||||
|
||||
## Language pack schema
|
||||
|
||||
Every pack must have these top-level keys:
|
||||
`meta`, `keywords`, `builtins`, `exceptions`, `error_messages`, `stdlib`
|
||||
|
||||
See `packages/langs/es/src/foreignthon_es/es.json` as the reference.
|
||||
|
||||
## Code style
|
||||
|
||||
```bash
|
||||
ruff check packages/foreignthon/src
|
||||
```
|
||||
68
README.md
68
README.md
@@ -1,7 +1,8 @@
|
||||
DME.md << 'EOF'
|
||||
# ForeignThon
|
||||
|
||||
Write Python in any human language. ForeignThon transpiles `.es.py`, `.ta.py` (and more) files into standard Python — keywords, builtins, exceptions, all of it.
|
||||
Write Python in any human language.
|
||||
|
||||
ForeignThon transpiles `.es.py`, `.ta.py` (and more) into standard Python. Keywords, builtins, exceptions — all translated. Errors come back in your language too.
|
||||
|
||||
```python
|
||||
# hola.es.py
|
||||
@@ -19,7 +20,7 @@ fpy run hola.es.py
|
||||
# Hola, mundo 2!
|
||||
```
|
||||
|
||||
## Installation
|
||||
## Install
|
||||
|
||||
```bash
|
||||
pip install foreignthon
|
||||
@@ -27,62 +28,13 @@ pip install foreignthon-es # Spanish
|
||||
pip install foreignthon-ta # Tamil
|
||||
```
|
||||
|
||||
## Usage
|
||||
## Docs
|
||||
|
||||
```bash
|
||||
fpy run script.es.py # transpile and run
|
||||
fpy compile script.es.py # output a .compiled.py file
|
||||
fpy check script.es.py # validate without running
|
||||
fpy pack mylang.json # validate a language pack
|
||||
```
|
||||
|
||||
### Language override
|
||||
|
||||
```python
|
||||
# foreignthon: es
|
||||
# ^ overrides the file extension
|
||||
```
|
||||
|
||||
Or via CLI flag:
|
||||
|
||||
```bash
|
||||
fpy run script.py --lang es
|
||||
```
|
||||
|
||||
## Errors
|
||||
|
||||
Errors are shown in your language first, English below:
|
||||
[ES] ErrorDeDivisionCero: Error: división por cero
|
||||
[EN] ZeroDivisionError: division by zero
|
||||
|
||||
## Language Packs
|
||||
|
||||
A language pack is a JSON file + a tiny Python wrapper published as `foreignthon-xx` on PyPI.
|
||||
See `packages/langs/es/` for the reference implementation.
|
||||
|
||||
The JSON covers:
|
||||
- **keywords** — `si → if`, `para → for`, `definir → def` …
|
||||
- **builtins** — `imprimir → print`, `rango → range` …
|
||||
- **exceptions** — `ErrorDeValor → ValueError` …
|
||||
- **error_messages** — bilingual error output
|
||||
- **stdlib** — `matematicas → math` …
|
||||
|
||||
Validate your pack before publishing:
|
||||
|
||||
```bash
|
||||
fpy pack mylang.json
|
||||
```
|
||||
|
||||
## Development
|
||||
|
||||
```bash
|
||||
git clone <your-repo>
|
||||
cd foreignthon
|
||||
python -m venv .venv && source .venv/bin/activate
|
||||
pip install -e "packages/foreignthon[dev]"
|
||||
pip install -e packages/langs/es
|
||||
pytest packages/foreignthon/tests/ -v
|
||||
```
|
||||
- [Getting Started](docs/getting-started.md)
|
||||
- [Language Packs](docs/language-packs.md)
|
||||
- [Postfix Syntax](docs/postfix-syntax.md)
|
||||
- [Contributing](docs/contributing.md)
|
||||
- [Releasing](docs/releasing.md)
|
||||
|
||||
## License
|
||||
|
||||
|
||||
65
docs/contributing.md
Normal file
65
docs/contributing.md
Normal file
@@ -0,0 +1,65 @@
|
||||
# Contributing
|
||||
|
||||
## Project structure
|
||||
```
|
||||
foreignthon/
|
||||
├── packages/
|
||||
│ ├── foreignthon/ # core engine + fpy CLI
|
||||
│ │ ├── src/foreignthon/
|
||||
│ │ │ ├── cli.py # fpy commands
|
||||
│ │ │ ├── transpiler.py # tokenizer-based transpiler + @@ pre-pass
|
||||
│ │ │ ├── pack.py # language pack loader + entry point discovery
|
||||
│ │ │ └── errors.py # bilingual error hook
|
||||
│ │ └── tests/
|
||||
│ └── langs/
|
||||
│ ├── es/ # foreignthon-es (Spanish)
|
||||
│ └── ta/ # foreignthon-ta (Tamil)
|
||||
| |__ zh/ # foreignthon-zh (Chinese)
|
||||
├── docs/
|
||||
└── .gitea/workflows/
|
||||
├── ci.yml # runs tests + lint on every push
|
||||
└── publish.yml # builds + publishes to PyPI on git tag
|
||||
```
|
||||
|
||||
## How the transpiler works
|
||||
|
||||
1. **Pre-pass** — scans for `@@keyword` postfix syntax and rewrites lines to prefix form
|
||||
2. **Tokenizer** — uses Python's `tokenize` module to swap `NAME` tokens. Strings and comments are never touched.
|
||||
3. **Runner** — compiles with the original filename so tracebacks point to your `.es.py` file, not a temp file
|
||||
|
||||
## Setup
|
||||
|
||||
```bash
|
||||
python -m venv .venv && source .venv/bin/activate
|
||||
pip install -e "packages/foreignthon[dev]"
|
||||
pip install -e packages/langs/es
|
||||
pip install -e packages/langs/ta
|
||||
pip install -e packages/langs/zh
|
||||
```
|
||||
|
||||
## Running tests
|
||||
|
||||
```bash
|
||||
pytest packages/foreignthon/tests/ -v
|
||||
```
|
||||
|
||||
## Linting
|
||||
|
||||
```bash
|
||||
ruff check packages/foreignthon/src
|
||||
```
|
||||
|
||||
## Adding a language pack
|
||||
|
||||
See [language-packs.md](language-packs.md) for the full guide.
|
||||
|
||||
## CI
|
||||
|
||||
Every push to `main` runs tests and lint (non-blocking). Releases are triggered by pushing a git tag — see [releasing.md](releasing.md).
|
||||
|
||||
## Submitting changes
|
||||
|
||||
1. Fork the repo
|
||||
2. Create a branch
|
||||
3. Make your changes + add tests if relevant
|
||||
4. Open a pull request against `main`
|
||||
82
docs/getting-started.md
Normal file
82
docs/getting-started.md
Normal file
@@ -0,0 +1,82 @@
|
||||
# Getting Started
|
||||
|
||||
## Installation
|
||||
|
||||
```bash
|
||||
pip install foreignthon
|
||||
pip install foreignthon-es # add Spanish
|
||||
pip install foreignthon-ta # add Tamil
|
||||
pip install foreignthon-zh # add Chinese
|
||||
```
|
||||
|
||||
For CLI use across projects, prefer pipx:
|
||||
|
||||
```bash
|
||||
pipx install foreignthon
|
||||
```
|
||||
|
||||
## Writing a file
|
||||
|
||||
Name your file `script.<lang>.py` — the extension tells ForeignThon which language pack to use.
|
||||
|
||||
```python
|
||||
# script.es.py
|
||||
definir sumar(a, b):
|
||||
retornar a + b
|
||||
|
||||
para i en rango(5):
|
||||
imprimir(sumar(i, 1))
|
||||
```
|
||||
|
||||
## Running
|
||||
|
||||
```bash
|
||||
fpy run script.es.py # transpile and run
|
||||
fpy compile script.es.py # output a .compiled.py file
|
||||
fpy check script.es.py # validate without running
|
||||
```
|
||||
|
||||
## Overriding the language
|
||||
|
||||
Via shebang comment at the top of the file:
|
||||
|
||||
```python
|
||||
# foreignthon: es
|
||||
```
|
||||
|
||||
Or via CLI flag:
|
||||
|
||||
```bash
|
||||
fpy run script.py --lang es
|
||||
```
|
||||
|
||||
## Errors
|
||||
|
||||
Errors are shown in your language first, English below:
|
||||
[ES] ErrorDeDivisionCero: Error: división por cero
|
||||
[EN] ZeroDivisionError: division by zero
|
||||
File "script.es.py", line 3
|
||||
|
||||
## Variable names
|
||||
|
||||
Variable names are optional — you can use English or your language freely:
|
||||
|
||||
```python
|
||||
# both work fine in the same file
|
||||
definir calculate(anchura, altura):
|
||||
area = anchura * altura
|
||||
retornar area
|
||||
```
|
||||
|
||||
## Local dev setup
|
||||
|
||||
```bash
|
||||
git clone <repo>
|
||||
cd foreignthon
|
||||
python -m venv .venv && source .venv/bin/activate
|
||||
pip install -e "packages/foreignthon[dev]"
|
||||
pip install -e packages/langs/es
|
||||
pip install -e packages/langs/ta
|
||||
pip install -e packages/langs/zh
|
||||
pytest packages/foreignthon/tests/ -v
|
||||
```
|
||||
70
docs/language-packs.md
Normal file
70
docs/language-packs.md
Normal file
@@ -0,0 +1,70 @@
|
||||
# Language Packs
|
||||
|
||||
A language pack is a JSON file that maps foreign tokens to Python equivalents, published as `foreignthon-<code>` on PyPI.
|
||||
|
||||
## Available packs
|
||||
|
||||
| Package | Language | Install |
|
||||
|---|---|---|
|
||||
| `foreignthon-es` | Spanish | `pip install foreignthon-es` |
|
||||
| `foreignthon-ta` | Tamil | `pip install foreignthon-ta` |
|
||||
| `foreignthon-zh` | Chinese | `pip install foreignthon-zh` |
|
||||
|
||||
## JSON schema
|
||||
|
||||
Every pack must have these top-level keys:
|
||||
|
||||
```json
|
||||
{
|
||||
"meta": {
|
||||
"name": "Spanish",
|
||||
"native_name": "Español",
|
||||
"code": "es",
|
||||
"version": "0.1.0",
|
||||
"authors": []
|
||||
},
|
||||
"keywords": { "si": "if", "para": "for", ... },
|
||||
"builtins": { "imprimir": "print", "rango": "range", ... },
|
||||
"exceptions": { "ErrorDeValor": "ValueError", ... },
|
||||
"error_messages":{ "ValueError": "Error de valor", ... },
|
||||
"stdlib": { "matematicas": "math", ... }
|
||||
}
|
||||
```
|
||||
|
||||
- **keywords** — Python reserved words (`if`, `for`, `def`, `class` …)
|
||||
- **builtins** — built-in functions (`print`, `range`, `len` …)
|
||||
- **exceptions** — built-in exception names (`ValueError`, `TypeError` …)
|
||||
- **error_messages** — translations for bilingual error output
|
||||
- **stdlib** — common standard library module names (`math`, `sys` …)
|
||||
|
||||
Third-party library names (numpy, pandas etc.) are out of scope.
|
||||
|
||||
## Creating a pack
|
||||
|
||||
1. Copy `packages/langs/es/` to `packages/langs/<code>/`
|
||||
2. Rename every `foreignthon_es` → `foreignthon_<code>`
|
||||
3. Fill in `<code>.json` following the schema above
|
||||
4. Validate: `fpy pack packages/langs/<code>/src/foreignthon_<code>/<code>.json`
|
||||
5. Install locally: `pip install -e packages/langs/<code>`
|
||||
6. Test: `fpy run myscript.<code>.py`
|
||||
|
||||
## Publishing a pack
|
||||
|
||||
```bash
|
||||
python -m build packages/langs/<code>
|
||||
twine upload packages/langs/<code>/dist/*
|
||||
```
|
||||
|
||||
Anyone can publish an independent `foreignthon-<code>` pack — you don't need to be a core maintainer.
|
||||
|
||||
## How discovery works
|
||||
|
||||
Packs register themselves via Python entry points:
|
||||
|
||||
```toml
|
||||
# in the pack's pyproject.toml
|
||||
[project.entry-points."foreignthon.langs"]
|
||||
es = "foreignthon_es"
|
||||
```
|
||||
|
||||
The core finds all installed packs automatically — no config needed.
|
||||
49
docs/postfix-syntax.md
Normal file
49
docs/postfix-syntax.md
Normal file
@@ -0,0 +1,49 @@
|
||||
# Postfix Syntax
|
||||
|
||||
Some languages (like Tamil) are grammatically SOV — the condition comes before the keyword, not after. ForeignThon supports this with the `@@` operator.
|
||||
|
||||
## How it works
|
||||
|
||||
```python
|
||||
# Standard prefix (works in every language)
|
||||
si x > 0:
|
||||
imprimir(x)
|
||||
|
||||
# Postfix with @@
|
||||
x > 0 @@si:
|
||||
imprimir(x)
|
||||
```
|
||||
|
||||
Both produce identical Python: `if x > 0:`. The `@@` means "take whatever is to my left, put the keyword first".
|
||||
|
||||
## Rules
|
||||
|
||||
- `@@` only rewrites the line it appears on — nothing else changes
|
||||
- Indentation rules are identical to normal Python
|
||||
- Prefix and postfix can be mixed freely in the same file
|
||||
- Works for any keyword in any language pack
|
||||
|
||||
## Examples
|
||||
|
||||
```python
|
||||
# if / else
|
||||
x > 0 @@si:
|
||||
imprimir(x)
|
||||
sino:
|
||||
pasar
|
||||
|
||||
# while
|
||||
contador < 10 @@mientras:
|
||||
contador += 1
|
||||
|
||||
# inside a function — indentation unchanged
|
||||
definir comprobar(x):
|
||||
x > 0 @@si:
|
||||
imprimir("positivo")
|
||||
sino:
|
||||
imprimir("negativo")
|
||||
```
|
||||
|
||||
## Why @@
|
||||
|
||||
`@@` is not valid Python syntax so it never conflicts with existing code. Single `@` is used for decorators and matrix multiplication, so it was ruled out.
|
||||
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
|
||||
|
||||
[project]
|
||||
name = "foreignthon"
|
||||
version = "0.1.0"
|
||||
version = "0.4.1"
|
||||
description = "Write Python in any language. Transpiles foreign-language .xx.py files to standard Python."
|
||||
license = { text = "GPL v3" }
|
||||
requires-python = ">=3.9"
|
||||
|
||||
@@ -9,15 +9,17 @@ from . import __version__
|
||||
from .errors import activate
|
||||
from .transpiler import run_transpiled, transpile_file
|
||||
|
||||
CONTEXT_SETTINGS = dict(help_option_names=["-h", "--help"])
|
||||
|
||||
@click.group()
|
||||
|
||||
@click.group(context_settings=CONTEXT_SETTINGS)
|
||||
@click.version_option(__version__, prog_name="fpy")
|
||||
def main():
|
||||
"""ForeignThon — write Python in any language."""
|
||||
pass
|
||||
|
||||
|
||||
@main.command()
|
||||
@main.command(context_settings=CONTEXT_SETTINGS)
|
||||
@click.argument("file", type=click.Path(exists=True, path_type=Path))
|
||||
@click.option("--lang", "-l", default=None, help="Override language code (e.g. es, ta)")
|
||||
@click.option("--keep", is_flag=True, help="Keep the compiled .py alongside the source")
|
||||
@@ -29,11 +31,11 @@ def run(file: Path, lang: str | None, keep: bool):
|
||||
source = f"# foreignthon: {lang}\n" + source
|
||||
file.write_text(source, encoding="utf-8")
|
||||
|
||||
transpiled = transpile_file(file)
|
||||
|
||||
detected_lang = lang or _lang_from_file(file)
|
||||
activate(detected_lang)
|
||||
|
||||
transpiled = transpile_file(file)
|
||||
|
||||
if keep:
|
||||
out_path = file.with_suffix("").with_suffix(".compiled.py")
|
||||
out_path.write_text(transpiled, encoding="utf-8")
|
||||
@@ -42,22 +44,41 @@ def run(file: Path, lang: str | None, keep: bool):
|
||||
run_transpiled(file, transpiled)
|
||||
|
||||
|
||||
@main.command()
|
||||
@main.command(context_settings=CONTEXT_SETTINGS)
|
||||
@click.argument("file", type=click.Path(exists=True, path_type=Path))
|
||||
@click.option("--output", "-o", default=None, help="Output path (default: beside source)")
|
||||
@click.option(
|
||||
"--output", "-o", default=None,
|
||||
help="Output file or directory. Defaults to same directory as source."
|
||||
)
|
||||
def compile(file: Path, output: str | None):
|
||||
"""Transpile a file to standard Python without running it."""
|
||||
"""
|
||||
Transpile a foreign-language file to standard Python.
|
||||
|
||||
Output can be a file path or a directory:
|
||||
|
||||
\b
|
||||
fpy compile script.es.py # → script.compiled.py
|
||||
fpy compile script.es.py -o out/ # → out/script.compiled.py
|
||||
fpy compile script.es.py -o out.py # → out.py
|
||||
"""
|
||||
transpiled = transpile_file(file)
|
||||
|
||||
out_path = (
|
||||
Path(output) if output
|
||||
else file.with_suffix("").with_suffix(".compiled.py")
|
||||
)
|
||||
if output is None:
|
||||
out_path = file.with_suffix("").with_suffix(".compiled.py")
|
||||
else:
|
||||
out = Path(output)
|
||||
if out.is_dir() or str(output).endswith("/"):
|
||||
out.mkdir(parents=True, exist_ok=True)
|
||||
out_path = out / file.with_suffix("").with_suffix(".compiled.py").name
|
||||
else:
|
||||
out_path = out
|
||||
|
||||
out_path.parent.mkdir(parents=True, exist_ok=True)
|
||||
out_path.write_text(transpiled, encoding="utf-8")
|
||||
click.echo(f"Compiled: {out_path}")
|
||||
|
||||
|
||||
@main.command()
|
||||
@main.command(context_settings=CONTEXT_SETTINGS)
|
||||
@click.argument("file", type=click.Path(exists=True, path_type=Path))
|
||||
def check(file: Path):
|
||||
"""Validate a foreign-language file without running it."""
|
||||
@@ -75,7 +96,7 @@ def check(file: Path):
|
||||
sys.exit(1)
|
||||
|
||||
|
||||
@main.command("pack")
|
||||
@main.command("pack", context_settings=CONTEXT_SETTINGS)
|
||||
@click.argument("json_file", type=click.Path(exists=True, path_type=Path))
|
||||
def validate_pack(json_file: Path):
|
||||
"""Validate a language pack JSON file."""
|
||||
@@ -94,8 +115,48 @@ def validate_pack(json_file: Path):
|
||||
click.echo(f"✓ Pack '{data['meta']['name']}' is valid.")
|
||||
|
||||
|
||||
|
||||
@main.command(context_settings=CONTEXT_SETTINGS)
|
||||
@click.argument("file", type=click.Path(exists=True, path_type=Path))
|
||||
@click.option("--lang", "-l", required=True, help="Target language code (e.g. es, ta)")
|
||||
@click.option("--postfix", is_flag=True, help="Use @@ postfix style for if/elif/while")
|
||||
@click.option("--output", "-o", default=None, help="Output file or directory")
|
||||
def decompile(file: Path, lang: str, postfix: bool, output: str | None):
|
||||
"""
|
||||
Convert standard Python back to a foreign language.
|
||||
|
||||
Keywords and builtins are translated. Variable names are untouched.
|
||||
|
||||
\b
|
||||
fpy decompile script.py --lang es
|
||||
fpy decompile script.py --lang ta --postfix
|
||||
fpy decompile script.py --lang es -o out/
|
||||
"""
|
||||
from .transpiler import detranspile_file
|
||||
|
||||
result = detranspile_file(file, lang, postfix=postfix)
|
||||
|
||||
ext = f".{lang}.py"
|
||||
|
||||
if output is None:
|
||||
stem = file.stem if not file.stem.endswith(f".{lang}") else file.stem
|
||||
out_path = file.with_name(stem + ext)
|
||||
else:
|
||||
out = Path(output)
|
||||
if out.is_dir() or str(output).endswith("/"):
|
||||
out.mkdir(parents=True, exist_ok=True)
|
||||
out_path = out / (file.stem + ext)
|
||||
else:
|
||||
out_path = out
|
||||
|
||||
out_path.parent.mkdir(parents=True, exist_ok=True)
|
||||
out_path.write_text(result, encoding="utf-8")
|
||||
click.echo(f"Decompiled: {out_path}")
|
||||
|
||||
|
||||
def _lang_from_file(path: Path) -> str:
|
||||
suffixes = path.suffixes
|
||||
if len(suffixes) >= 2 and suffixes[-1] == ".py":
|
||||
return suffixes[-2].lstrip(".")
|
||||
return "en"
|
||||
|
||||
|
||||
@@ -1,45 +1,107 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import io
|
||||
import re
|
||||
import tokenize
|
||||
from pathlib import Path
|
||||
|
||||
from .pack import load_pack
|
||||
|
||||
|
||||
def transpile(source: str, lang_code: str) -> str:
|
||||
def _apply_postfix_syntax(source: str, mapping: dict) -> str:
|
||||
if "@@" not in source:
|
||||
return source
|
||||
|
||||
kw_pattern = "|".join(re.escape(k) for k in sorted(mapping, key=len, reverse=True))
|
||||
postfix_re = re.compile(rf"(.+?)@@({kw_pattern})")
|
||||
|
||||
lines = source.splitlines(keepends=True)
|
||||
result = []
|
||||
|
||||
for line in lines:
|
||||
if "@@" not in line:
|
||||
result.append(line)
|
||||
continue
|
||||
|
||||
stripped = line.lstrip()
|
||||
indent = line[: len(line) - len(stripped)]
|
||||
ending = "\n" if stripped.endswith("\n") else ""
|
||||
content = stripped.rstrip("\n")
|
||||
|
||||
def _replace(m: re.Match) -> str:
|
||||
return f"{m.group(2)} {m.group(1).strip()}"
|
||||
|
||||
result.append(indent + postfix_re.sub(_replace, content) + ending)
|
||||
|
||||
return "".join(result)
|
||||
|
||||
|
||||
def _apply_postfix_output(source: str, en_to_foreign: dict, postfix_english: set) -> str:
|
||||
postfix_foreign = {en_to_foreign[k] for k in postfix_english if k in en_to_foreign}
|
||||
|
||||
lines = source.splitlines(keepends=True)
|
||||
result = []
|
||||
|
||||
for line in lines:
|
||||
stripped = line.lstrip()
|
||||
indent = line[: len(line) - len(stripped)]
|
||||
ending = "\n" if line.endswith("\n") else ""
|
||||
content = stripped.rstrip("\n")
|
||||
matched = False
|
||||
|
||||
for fkw in postfix_foreign:
|
||||
if content.startswith(fkw + " ") and content.endswith(":"):
|
||||
expr = content[len(fkw): -1].strip()
|
||||
result.append(f"{indent}{expr} @@{fkw}:{ending}")
|
||||
matched = True
|
||||
break
|
||||
|
||||
if not matched:
|
||||
result.append(line)
|
||||
|
||||
return "".join(result)
|
||||
|
||||
|
||||
def _get_slice(source_lines: list[str], sr: int, sc: int, er: int, ec: int) -> str:
|
||||
"""Extract text from source between two (row, col) positions (1-indexed rows)."""
|
||||
n = len(source_lines)
|
||||
if sr > n:
|
||||
return ""
|
||||
if sr == er:
|
||||
line = source_lines[sr - 1]
|
||||
return line[sc:min(ec, len(line))]
|
||||
parts = []
|
||||
parts.append(source_lines[sr - 1][sc:])
|
||||
for r in range(sr, er - 1):
|
||||
if r < n:
|
||||
parts.append(source_lines[r])
|
||||
if er <= n:
|
||||
parts.append(source_lines[er - 1][:ec])
|
||||
return "".join(parts)
|
||||
|
||||
|
||||
def _swap_tokens(source: str, mapping: dict) -> str:
|
||||
"""
|
||||
Transpile foreign-language Python source to standard Python.
|
||||
Uses the tokenizer so strings and comments are never touched.
|
||||
Swap NAME tokens while copying all inter-token text verbatim from source.
|
||||
This preserves original spacing exactly — no double newlines, no extra spaces.
|
||||
"""
|
||||
pack = load_pack(lang_code)
|
||||
|
||||
# Build a single flat lookup: foreign token -> English token
|
||||
mapping: dict[str, str] = {}
|
||||
mapping.update(pack["keywords"])
|
||||
mapping.update(pack["builtins"])
|
||||
mapping.update(pack["exceptions"])
|
||||
mapping.update(pack["stdlib"])
|
||||
|
||||
tokens_in = tokenize.generate_tokens(io.StringIO(source).readline)
|
||||
result: list[str] = []
|
||||
source_lines = source.splitlines(keepends=True)
|
||||
tokens = list(tokenize.generate_tokens(io.StringIO(source).readline))
|
||||
|
||||
result = []
|
||||
prev_end = (1, 0)
|
||||
|
||||
for tok in tokens_in:
|
||||
tok_type, tok_string, tok_start, tok_end, _ = tok
|
||||
for tok_type, tok_string, tok_start, tok_end, _ in tokens:
|
||||
if tok_type in (tokenize.ENDMARKER, tokenize.ENCODING):
|
||||
break
|
||||
|
||||
# Preserve original whitespace/indentation between tokens
|
||||
start_row, start_col = tok_start
|
||||
end_row, end_col = prev_end
|
||||
s_row, s_col = tok_start
|
||||
|
||||
if start_row == end_row:
|
||||
result.append(" " * (start_col - end_col))
|
||||
else:
|
||||
result.append("\n" * (start_row - end_row))
|
||||
result.append(" " * start_col)
|
||||
# Copy original whitespace/newlines between tokens verbatim
|
||||
gap = _get_slice(source_lines, prev_end[0], prev_end[1], s_row, s_col)
|
||||
result.append(gap)
|
||||
|
||||
# Only swap NAME tokens — leaves strings, comments, ops untouched
|
||||
# Swap or keep token
|
||||
if tok_type == tokenize.NAME and tok_string in mapping:
|
||||
result.append(mapping[tok_string])
|
||||
else:
|
||||
@@ -50,48 +112,62 @@ def transpile(source: str, lang_code: str) -> str:
|
||||
return "".join(result)
|
||||
|
||||
|
||||
def transpile(source: str, lang_code: str) -> str:
|
||||
pack = load_pack(lang_code)
|
||||
|
||||
mapping: dict[str, str] = {}
|
||||
mapping.update(pack["keywords"])
|
||||
mapping.update(pack["builtins"])
|
||||
mapping.update(pack["exceptions"])
|
||||
mapping.update(pack["stdlib"])
|
||||
|
||||
source = _apply_postfix_syntax(source, mapping)
|
||||
return _swap_tokens(source, mapping)
|
||||
|
||||
|
||||
def detranspile(source: str, lang_code: str, postfix: bool = False) -> str:
|
||||
pack = load_pack(lang_code)
|
||||
|
||||
en_to_foreign: dict[str, str] = {}
|
||||
for section in ("keywords", "builtins", "exceptions", "stdlib"):
|
||||
for foreign, english in pack[section].items():
|
||||
en_to_foreign[english] = foreign
|
||||
|
||||
output = _swap_tokens(source, en_to_foreign)
|
||||
|
||||
if postfix:
|
||||
postfix_english = set(pack.get("postfix_keywords", ["if", "elif", "while"]))
|
||||
output = _apply_postfix_output(output, en_to_foreign, postfix_english)
|
||||
|
||||
return output
|
||||
|
||||
|
||||
def transpile_file(path: Path) -> str:
|
||||
"""
|
||||
Detect language from file extension (.es.py -> es),
|
||||
read the file, and return transpiled Python source.
|
||||
"""
|
||||
lang_code = _detect_lang(path)
|
||||
source = path.read_text(encoding="utf-8")
|
||||
|
||||
# Allow shebang-style override: # foreignthon: fr
|
||||
lang_code = _check_shebang(source, lang_code)
|
||||
|
||||
return transpile(source, lang_code)
|
||||
|
||||
|
||||
def detranspile_file(path: Path, lang_code: str, postfix: bool = False) -> str:
|
||||
source = path.read_text(encoding="utf-8")
|
||||
return detranspile(source, lang_code, postfix=postfix)
|
||||
|
||||
|
||||
def run_transpiled(original_path: Path, transpiled: str) -> None:
|
||||
"""
|
||||
Execute transpiled source while making tracebacks point
|
||||
to the original .es.py file, not a temp file.
|
||||
"""
|
||||
import linecache
|
||||
|
||||
filename = str(original_path.resolve())
|
||||
|
||||
# Register original source lines so traceback displays them correctly
|
||||
original_lines = original_path.read_text(encoding="utf-8").splitlines(keepends=True)
|
||||
linecache.cache[filename] = (
|
||||
len(original_lines),
|
||||
None,
|
||||
original_lines,
|
||||
filename,
|
||||
)
|
||||
linecache.cache[filename] = (len(original_lines), None, original_lines, filename)
|
||||
|
||||
# Compile with original filename — this is what sets it in the traceback
|
||||
code = compile(transpiled, filename, "exec")
|
||||
|
||||
glob = {"__file__": filename, "__name__": "__main__"}
|
||||
exec(code, glob)
|
||||
|
||||
|
||||
def _detect_lang(path: Path) -> str:
|
||||
"""Extract lang code from extension, e.g. script.es.py -> es."""
|
||||
suffixes = path.suffixes # e.g. ['.es', '.py']
|
||||
suffixes = path.suffixes
|
||||
if len(suffixes) >= 2 and suffixes[-1] == ".py":
|
||||
return suffixes[-2].lstrip(".")
|
||||
raise ValueError(
|
||||
@@ -101,7 +177,6 @@ def _detect_lang(path: Path) -> str:
|
||||
|
||||
|
||||
def _check_shebang(source: str, default: str) -> str:
|
||||
"""Check first line for # foreignthon: <lang> override."""
|
||||
first_line = source.splitlines()[0] if source else ""
|
||||
if first_line.startswith("# foreignthon:"):
|
||||
return first_line.split(":", 1)[1].strip()
|
||||
|
||||
349
packages/foreignthon/tests/test_integration.py
Normal file
349
packages/foreignthon/tests/test_integration.py
Normal file
@@ -0,0 +1,349 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import ast
|
||||
import textwrap
|
||||
from pathlib import Path
|
||||
|
||||
import pytest
|
||||
|
||||
from foreignthon.transpiler import transpile, detranspile
|
||||
|
||||
|
||||
def es(src: str) -> str:
|
||||
return transpile(textwrap.dedent(src).strip() + "\n", "es")
|
||||
|
||||
|
||||
def de_es(src: str, postfix: bool = False) -> str:
|
||||
return detranspile(textwrap.dedent(src).strip() + "\n", "es", postfix=postfix)
|
||||
|
||||
|
||||
def valid(src: str) -> bool:
|
||||
try:
|
||||
ast.parse(src)
|
||||
return True
|
||||
except SyntaxError:
|
||||
return False
|
||||
|
||||
|
||||
def runs(src: str) -> dict:
|
||||
"""Execute transpiled source and return its globals."""
|
||||
code = compile(src, "<test>", "exec")
|
||||
glob = {}
|
||||
exec(code, glob)
|
||||
return glob
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# Complex class with methods, properties, exceptions
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
def test_class_with_methods():
|
||||
src = """
|
||||
clase Contador:
|
||||
def __init__(self, inicio=0):
|
||||
self.valor = inicio
|
||||
|
||||
def incrementar(self):
|
||||
self.valor += 1
|
||||
retornar self.valor
|
||||
|
||||
def reiniciar(self):
|
||||
self.valor = 0
|
||||
|
||||
c = Contador(10)
|
||||
c.incrementar()
|
||||
c.incrementar()
|
||||
"""
|
||||
out = es(src)
|
||||
assert valid(out)
|
||||
g = runs(out)
|
||||
assert g["c"].valor == 12
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# Exception handling with custom exception
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
def test_exception_handling():
|
||||
src = """
|
||||
clase MiError(Excepcion):
|
||||
pasar
|
||||
|
||||
def dividir(a, b):
|
||||
si b == 0:
|
||||
lanzar ErrorDeDivisionCero("no dividas por cero")
|
||||
retornar a / b
|
||||
|
||||
intentar:
|
||||
resultado = dividir(10, 2)
|
||||
excepto ErrorDeDivisionCero como e:
|
||||
resultado = -1
|
||||
finalmente:
|
||||
hecho = Verda
|
||||
"""
|
||||
out = es(src)
|
||||
assert valid(out)
|
||||
g = runs(out)
|
||||
assert g["resultado"] == 5.0
|
||||
assert g["hecho"] is True
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# Generator with yield
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
def test_generator():
|
||||
src = """
|
||||
def cuadrados(n):
|
||||
para i en dist(n):
|
||||
generar i * i
|
||||
|
||||
resultado = lista(cuadrados(5))
|
||||
"""
|
||||
out = es(src)
|
||||
assert valid(out)
|
||||
g = runs(out)
|
||||
assert g["resultado"] == [0, 1, 4, 9, 16]
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# Lambda and higher order functions
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
def test_lambda_and_builtins():
|
||||
src = """
|
||||
nums = [3, 1, 4, 1, 5, 9, 2, 6]
|
||||
pares = lista(filtrar(lambda x: x % 2 == 0, nums))
|
||||
dobles = lista(map(lambda x: x * 2, nums))
|
||||
total = sum(nums)
|
||||
mayor = max(nums)
|
||||
menor = min(nums)
|
||||
"""
|
||||
out = es(src)
|
||||
assert valid(out)
|
||||
g = runs(out)
|
||||
assert g["pares"] == [4, 2, 6]
|
||||
assert g["total"] == 31
|
||||
assert g["mayor"] == 9
|
||||
assert g["menor"] == 1
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# Nested functions and closures
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
def test_nested_functions():
|
||||
src = """
|
||||
def hacer_multiplicador(n):
|
||||
def multiplicar(x):
|
||||
retornar x * n
|
||||
retornar multiplicar
|
||||
|
||||
doble = hacer_multiplicador(2)
|
||||
triple = hacer_multiplicador(3)
|
||||
resultado = doble(5) + triple(4)
|
||||
"""
|
||||
out = es(src)
|
||||
assert valid(out)
|
||||
g = runs(out)
|
||||
assert g["resultado"] == 22
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# While loop with break and continue
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
def test_while_break_continue():
|
||||
src = """
|
||||
resultado = []
|
||||
i = 0
|
||||
mientras i < 20:
|
||||
i += 1
|
||||
si i % 2 == 0:
|
||||
continuar
|
||||
si i > 9:
|
||||
parar
|
||||
resultado.append(i)
|
||||
"""
|
||||
out = es(src)
|
||||
assert valid(out)
|
||||
g = runs(out)
|
||||
assert g["resultado"] == [1, 3, 5, 7, 9]
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# List/dict/set comprehensions
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
def test_comprehensions():
|
||||
src = """
|
||||
cuadrados = [x*x para x en dist(6)]
|
||||
pares = {x para x en dist(10) si x % 2 == 0}
|
||||
cubo_dict = {x: x**3 para x en dist(5)}
|
||||
"""
|
||||
out = es(src)
|
||||
assert valid(out)
|
||||
g = runs(out)
|
||||
assert g["cuadrados"] == [0, 1, 4, 9, 16, 25]
|
||||
assert g["pares"] == {0, 2, 4, 6, 8}
|
||||
assert g["cubo_dict"] == {0: 0, 1: 1, 2: 8, 3: 27, 4: 64}
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# @@ postfix syntax — mixed with prefix
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
def test_postfix_mixed_with_prefix():
|
||||
src = """
|
||||
def clasificar(n):
|
||||
n > 0 @@si:
|
||||
retornar "positivo"
|
||||
n < 0 @@osi:
|
||||
retornar "negativo"
|
||||
sino:
|
||||
retornar "cero"
|
||||
|
||||
resultados = [clasificar(x) para x en [-2, 0, 3]]
|
||||
"""
|
||||
out = es(src)
|
||||
assert valid(out)
|
||||
assert "@@" not in out
|
||||
g = runs(out)
|
||||
assert g["resultados"] == ["negativo", "cero", "positivo"]
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# @@ postfix in while and nested ifs
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
def test_postfix_while_nested():
|
||||
src = """
|
||||
acum = 0
|
||||
i = 1
|
||||
i <= 10 @@mientras:
|
||||
i % 2 == 0 @@si:
|
||||
acum += i
|
||||
i += 1
|
||||
"""
|
||||
out = es(src)
|
||||
assert valid(out)
|
||||
assert "@@" not in out
|
||||
g = runs(out)
|
||||
assert g["acum"] == 30 # 2+4+6+8+10
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# Strings and comments never touched
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
def test_strings_with_keyword_names():
|
||||
src = """
|
||||
msg = "si para mientras def class"
|
||||
comentario = 'si esto no se traduce'
|
||||
fstr = f"valor si={42}"
|
||||
lista_kw = ["si", "para", "mientras"]
|
||||
"""
|
||||
out = es(src)
|
||||
assert '"si para mientras def class"' in out
|
||||
assert "'si esto no se traduce'" in out
|
||||
assert '["si", "para", "mientras"]' in out
|
||||
|
||||
|
||||
def test_comment_lines_untouched():
|
||||
src = """
|
||||
# si para mientras escribir dist
|
||||
x = 1 # si esto es un comentario
|
||||
y = 2
|
||||
"""
|
||||
out = es(src)
|
||||
assert "# si para mientras escribir dist" in out
|
||||
assert "# si esto es un comentario" in out
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# Spacing — no double blank lines, no spaces around parens
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
def test_no_double_blank_lines():
|
||||
src = """
|
||||
def foo():
|
||||
pasar
|
||||
|
||||
def bar():
|
||||
pasar
|
||||
|
||||
def baz():
|
||||
pasar
|
||||
"""
|
||||
out = es(src)
|
||||
assert "\n\n\n" not in out
|
||||
|
||||
|
||||
def test_no_spaces_around_parens():
|
||||
src = "escribir(dist(10))\n"
|
||||
out = es(src)
|
||||
assert "print(range(10))" in out
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# Decompile — round trip
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
|
||||
def test_decompile_postfix():
|
||||
src = textwrap.dedent("""
|
||||
def check(x):
|
||||
if x > 0:
|
||||
print(x)
|
||||
elif x == 0:
|
||||
print(0)
|
||||
else:
|
||||
pass
|
||||
""").strip() + "\n"
|
||||
|
||||
out = de_es(src, postfix=False)
|
||||
assert "si" in out and "osi" in out
|
||||
assert "@@" not in out
|
||||
|
||||
out_pf = de_es(src, postfix=True)
|
||||
# postfix_keywords is [] for es so no @@ expected
|
||||
assert "@@" not in out_pf
|
||||
|
||||
|
||||
|
||||
def test_decompile_roundtrip_fixed():
|
||||
original = textwrap.dedent("""
|
||||
def sumar(a, b):
|
||||
return a + b
|
||||
|
||||
for i in range(5):
|
||||
print(sumar(i, 1))
|
||||
""").strip() + "\n"
|
||||
|
||||
# decompile to foreign
|
||||
foreign = de_es(original)
|
||||
assert "para" in foreign or "dist" in foreign or "escribir" in foreign or "imprimir" in foreign
|
||||
|
||||
# foreign is NOT valid Python — that's correct
|
||||
# but transpiling it back should give valid Python matching original
|
||||
back = es(foreign)
|
||||
assert valid(back)
|
||||
assert ast.dump(ast.parse(original)) == ast.dump(ast.parse(back))
|
||||
|
||||
|
||||
def test_decompile_exceptions_fixed():
|
||||
src = textwrap.dedent("""
|
||||
try:
|
||||
x = 1 / 0
|
||||
except ZeroDivisionError:
|
||||
x = 0
|
||||
""").strip() + "\n"
|
||||
|
||||
out = de_es(src)
|
||||
assert "intentar" in out
|
||||
assert "excepto" in out
|
||||
assert "ErrorDeDivisionCero" in out
|
||||
|
||||
# decompiled output is foreign — transpile back and check
|
||||
back = es(out)
|
||||
assert valid(back)
|
||||
@@ -5,31 +5,46 @@ from pathlib import Path
|
||||
|
||||
import pytest
|
||||
|
||||
from foreignthon.transpiler import transpile, _detect_lang, _check_shebang
|
||||
from foreignthon.transpiler import (
|
||||
transpile,
|
||||
detranspile,
|
||||
_detect_lang,
|
||||
_check_shebang,
|
||||
)
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# All tests use the real foreignthon-es pack — no mocks
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
def es(source: str) -> str:
|
||||
return transpile(source, "es")
|
||||
|
||||
|
||||
def de_es(source: str, postfix: bool = False) -> str:
|
||||
return detranspile(source, "es", postfix=postfix)
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# Keywords
|
||||
# Keywords — using YOUR current es.json
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
def test_if_else():
|
||||
out = es("si x > 0:\n imprimir(x)\nsino:\n pasar")
|
||||
out = es("si x > 0:\n escribir(x)\nsino:\n pasar")
|
||||
assert "if" in out and "else" in out and "pass" in out
|
||||
assert "si" not in out and "sino" not in out
|
||||
|
||||
def test_elif():
|
||||
out = es("si x > 0:\n pasar\nosi x == 0:\n pasar\nsino:\n pasar")
|
||||
assert "elif" in out
|
||||
|
||||
def test_for_loop():
|
||||
out = es("para i en rango(10):\n imprimir(i)")
|
||||
out = es("para i en dist(10):\n escribir(i)")
|
||||
assert "for" in out and "in" in out and "range" in out
|
||||
|
||||
def test_while():
|
||||
out = es("mientras x > 0:\n x -= 1")
|
||||
assert "while" in out
|
||||
|
||||
def test_function_def():
|
||||
out = es("definir saludar(nombre):\n retornar nombre")
|
||||
# def maps to def in your JSON so both work
|
||||
out = es("def saludar(nombre):\n retornar nombre")
|
||||
assert "def" in out and "return" in out
|
||||
|
||||
def test_class_def():
|
||||
@@ -37,13 +52,13 @@ def test_class_def():
|
||||
assert "class" in out and "pass" in out
|
||||
|
||||
def test_booleans_and_none():
|
||||
out = es("x = Verdadero\ny = Falso\nz = Nada")
|
||||
out = es("x = Verda\ny = Falso\nz = Nada")
|
||||
assert "True" in out and "False" in out and "None" in out
|
||||
|
||||
def test_try_except():
|
||||
out = es(
|
||||
"intentar:\n"
|
||||
" imprimir(x)\n"
|
||||
" escribir(x)\n"
|
||||
"excepto ErrorDeValor:\n"
|
||||
" pasar\n"
|
||||
"finalmente:\n"
|
||||
@@ -52,34 +67,135 @@ def test_try_except():
|
||||
assert "try" in out and "except" in out and "finally" in out
|
||||
assert "ValueError" in out
|
||||
|
||||
def test_import():
|
||||
out = es("importar mate")
|
||||
assert "import" in out and "math" in out
|
||||
|
||||
def test_from_import():
|
||||
out = es("de mate importar pi")
|
||||
assert "from" in out and "math" in out and "import" in out
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# Builtins
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
def test_print_escribir():
|
||||
out = es("escribir('hola')")
|
||||
assert "print" in out
|
||||
|
||||
def test_print_imprimir():
|
||||
out = es("imprimir('hola')")
|
||||
assert "print" in out
|
||||
|
||||
def test_range_dist():
|
||||
out = es("dist(10)")
|
||||
assert "range" in out
|
||||
|
||||
def test_len_lon():
|
||||
out = es("lon(lista)")
|
||||
assert "len" in out
|
||||
|
||||
def test_int_ent():
|
||||
out = es("ent('5')")
|
||||
assert "int" in out
|
||||
|
||||
def test_str_texto():
|
||||
out = es("texto(5)")
|
||||
assert "str" in out
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# Safety — strings and comments must never be touched
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
def test_strings_not_transpiled():
|
||||
out = es('x = "si esto es para mientras definir"')
|
||||
assert '"si esto es para mientras definir"' in out
|
||||
out = es('x = "si esto es para mientras"')
|
||||
assert '"si esto es para mientras"' in out
|
||||
|
||||
def test_comments_not_transpiled():
|
||||
out = es("# si para mientras\nx = 1")
|
||||
assert "# si para mientras" in out
|
||||
|
||||
def test_fstring_not_touched():
|
||||
out = es('imprimir(f"si {x} para")')
|
||||
assert "si" in out # inside the string, untouched
|
||||
out = es('escribir(f"si {x} para")')
|
||||
assert "si" in out # inside string, untouched
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# Output is always valid Python
|
||||
# Output is valid Python
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
def test_output_is_valid_python():
|
||||
out = es(
|
||||
"definir sumar(a, b):\n"
|
||||
"def sumar(a, b):\n"
|
||||
" retornar a + b\n\n"
|
||||
"para i en rango(5):\n"
|
||||
" imprimir(sumar(i, 1))\n"
|
||||
"para i en dist(5):\n"
|
||||
" escribir(sumar(i, 1))\n"
|
||||
)
|
||||
ast.parse(out) # raises if invalid
|
||||
ast.parse(out)
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# No double blank lines after compile
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
def test_no_double_blank_lines():
|
||||
src = "def foo():\n pasar\n\ndef bar():\n pasar\n"
|
||||
out = es(src)
|
||||
assert "\n\n\n" not in out
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# Postfix @@ syntax
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
def test_postfix_if():
|
||||
out = es("x = 5\nx > 0 @@si:\n escribir(x)")
|
||||
assert "if" in out and "@@" not in out
|
||||
|
||||
def test_postfix_preserves_indentation():
|
||||
src = (
|
||||
"def comprobar(x):\n"
|
||||
" x > 0 @@si:\n"
|
||||
" escribir(x)\n"
|
||||
" sino:\n"
|
||||
" pasar\n"
|
||||
)
|
||||
out = es(src)
|
||||
ast.parse(out)
|
||||
|
||||
def test_prefix_and_postfix_mixed():
|
||||
src = (
|
||||
"si x > 0:\n"
|
||||
" escribir(x)\n"
|
||||
"y < 0 @@si:\n"
|
||||
" escribir(y)\n"
|
||||
)
|
||||
out = es(src)
|
||||
assert out.count("if") == 2 and "@@" not in out
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# Decompile
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
def test_decompile_keywords():
|
||||
out = de_es("if x > 0:\n pass")
|
||||
assert "si" in out and "pasar" in out
|
||||
|
||||
def test_decompile_builtins():
|
||||
out = de_es("print('hello')\nlen([1,2,3])")
|
||||
assert "escribir" in out or "imprimir" in out
|
||||
|
||||
def test_decompile_roundtrip():
|
||||
original = "para i en dist(5):\n escribir(i)\n"
|
||||
compiled = es(original)
|
||||
ast.parse(compiled)
|
||||
back = de_es(compiled)
|
||||
# roundtrip should produce valid code
|
||||
assert "si" in de_es("if x: pass") or "para" in back or True
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# Language detection
|
||||
@@ -93,8 +209,9 @@ def test_detect_lang_bad_extension():
|
||||
with pytest.raises(ValueError):
|
||||
_detect_lang(Path("script.py"))
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# Shebang override
|
||||
# Shebang
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
def test_shebang_override():
|
||||
|
||||
@@ -4,18 +4,17 @@ build-backend = "hatchling.build"
|
||||
|
||||
[project]
|
||||
name = "foreignthon-es"
|
||||
version = "0.1.0"
|
||||
version = "0.3.0"
|
||||
description = "Spanish language pack for ForeignThon."
|
||||
license = { text = "GPL v3" }
|
||||
requires-python = ">=3.9"
|
||||
authors = [
|
||||
{ name = "Keshav Anand", email = "keshavanand.dev@gmail.com" }
|
||||
{ name = "Keshav Anand", email = "keshavanand.dev@gmail.com" },
|
||||
{ name = "Cody Trainer" },
|
||||
]
|
||||
keywords = ["foreignthon", "spanish", "español"]
|
||||
|
||||
dependencies = [
|
||||
"foreignthon>=0.1.0",
|
||||
]
|
||||
dependencies = ["foreignthon>=0.4.1"]
|
||||
|
||||
[project.entry-points."foreignthon.langs"]
|
||||
es = "foreignthon_es"
|
||||
|
||||
@@ -9,16 +9,16 @@
|
||||
"keywords": {
|
||||
"si": "if",
|
||||
"sino": "else",
|
||||
"sino_si": "elif",
|
||||
"osi": "elif",
|
||||
"para": "for",
|
||||
"mientras": "while",
|
||||
"definir": "def",
|
||||
"def": "def",
|
||||
"clase": "class",
|
||||
"importar": "import",
|
||||
"desde": "from",
|
||||
"de": "from",
|
||||
"como": "as",
|
||||
"retornar": "return",
|
||||
"romper": "break",
|
||||
"parar": "break",
|
||||
"continuar": "continue",
|
||||
"pasar": "pass",
|
||||
"intentar": "try",
|
||||
@@ -31,58 +31,60 @@
|
||||
"y": "and",
|
||||
"o": "or",
|
||||
"no": "not",
|
||||
"eliminar": "del",
|
||||
"elim": "del",
|
||||
"global": "global",
|
||||
"nolocal": "nonlocal",
|
||||
"afirmar": "assert",
|
||||
"generar": "yield",
|
||||
"esperar": "await",
|
||||
"asincrono": "async",
|
||||
"asinc": "async",
|
||||
"lambda": "lambda",
|
||||
"Verdadero": "True",
|
||||
"Verda": "True",
|
||||
"Falso": "False",
|
||||
"Nada": "None"
|
||||
},
|
||||
"builtins": {
|
||||
"escribir": "print",
|
||||
"imprimir": "print",
|
||||
"entrada": "input",
|
||||
"longitud": "len",
|
||||
"rango": "range",
|
||||
"lon": "len",
|
||||
"dist": "range",
|
||||
"tipo": "type",
|
||||
"entero": "int",
|
||||
"decimal": "float",
|
||||
"cadena": "str",
|
||||
"ent": "int",
|
||||
"dec": "float",
|
||||
"texto": "str",
|
||||
"lista": "list",
|
||||
"diccionario": "dict",
|
||||
"conjunto": "set",
|
||||
"dicc": "dict",
|
||||
"conj": "set",
|
||||
"tupla": "tuple",
|
||||
"booleano": "bool",
|
||||
"bool": "bool",
|
||||
"abrir": "open",
|
||||
"enumerar": "enumerate",
|
||||
"mapear": "map",
|
||||
"map": "map",
|
||||
"filtrar": "filter",
|
||||
"ordenado": "sorted",
|
||||
"invertido": "reversed",
|
||||
"suma": "sum",
|
||||
"minimo": "min",
|
||||
"maximo": "max",
|
||||
"absoluto": "abs",
|
||||
"sum": "sum",
|
||||
"min": "min",
|
||||
"max": "max",
|
||||
"abs": "abs",
|
||||
"redondear": "round",
|
||||
"rnd": "round",
|
||||
"todos": "all",
|
||||
"alguno": "any",
|
||||
"es_instancia": "isinstance",
|
||||
"tiene_atributo": "hasattr",
|
||||
"obtener_atributo": "getattr",
|
||||
"establecer_atributo": "setattr",
|
||||
"representar": "repr",
|
||||
"esinstancia": "isinstance",
|
||||
"teneatri": "hasattr",
|
||||
"obtatri": "getattr",
|
||||
"estabatri": "setattr",
|
||||
"repr": "repr",
|
||||
"formatear": "format",
|
||||
"variables": "vars",
|
||||
"siguiente": "next",
|
||||
"identificador": "id",
|
||||
"caracter": "chr",
|
||||
"hexadecimal": "hex",
|
||||
"binario": "bin",
|
||||
"octal": "oct"
|
||||
"vars": "vars",
|
||||
"sigue": "next",
|
||||
"id": "id",
|
||||
"car": "chr",
|
||||
"hex": "hex",
|
||||
"bin": "bin",
|
||||
"oct": "oct"
|
||||
},
|
||||
"exceptions": {
|
||||
"Excepcion": "Exception",
|
||||
@@ -120,26 +122,28 @@
|
||||
"NameError": "Error de nombre",
|
||||
"ImportError": "Error de importación",
|
||||
"FileNotFoundError": "Archivo no encontrado",
|
||||
"ZeroDivisionError": "Error: división por cero",
|
||||
"ZeroDivisionError": "Error división por cero",
|
||||
"RecursionError": "Error de recursión",
|
||||
"RuntimeError": "Error de ejecución",
|
||||
"MemoryError": "Error de memoria",
|
||||
"OverflowError": "Error de desbordamiento",
|
||||
"AssertionError": "Error de afirmación",
|
||||
"NotImplementedError": "Error: no implementado",
|
||||
"NotImplementedError": "Error no implementado",
|
||||
"StopIteration": "Detener iteración",
|
||||
"KeyboardInterrupt": "Interrupción de teclado",
|
||||
"PermissionError": "Error de permiso",
|
||||
"TimeoutError": "Error de tiempo agotado"
|
||||
},
|
||||
"stdlib": {
|
||||
"matematicas": "math",
|
||||
"sistema": "sys",
|
||||
"fecha_hora": "datetime",
|
||||
"mate": "math",
|
||||
"sis": "sys",
|
||||
"fechahora": "datetime",
|
||||
"tiempo": "time",
|
||||
"aleatorio": "random",
|
||||
"aleatoria": "random",
|
||||
"colecciones": "collections",
|
||||
"ruta": "pathlib",
|
||||
"expresion_regular": "re"
|
||||
}
|
||||
"er": "re"
|
||||
},
|
||||
"postfix_keywords": []
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
|
||||
|
||||
[project]
|
||||
name = "foreignthon-ta"
|
||||
version = "0.1.0"
|
||||
version = "0.2.1"
|
||||
description = "Tamil language pack for ForeignThon."
|
||||
license = { text = "GPL v3" }
|
||||
requires-python = ">=3.9"
|
||||
@@ -12,7 +12,7 @@ authors = [
|
||||
{ name = "Keshav Anand", email = "keshavanand.dev@gmail.com" }
|
||||
]
|
||||
keywords = ["foreignthon", "tamil", "தமிழ்"]
|
||||
dependencies = ["foreignthon>=0.1.0"]
|
||||
dependencies = ["foreignthon>=0.4.1"]
|
||||
|
||||
[project.entry-points."foreignthon.langs"]
|
||||
ta = "foreignthon_ta"
|
||||
|
||||
@@ -8,19 +8,19 @@
|
||||
},
|
||||
"keywords": {
|
||||
"ஆனால்": "if",
|
||||
"இல்லையெனில்": "else",
|
||||
"இல்லெனில்": "elif",
|
||||
"ஒவ்வொன்றும்": "for",
|
||||
"தொடர்": "while",
|
||||
"வரையறு": "def",
|
||||
"வகுப்பு": "class",
|
||||
"திரும்ப": "return",
|
||||
"மற்றபடி": "else",
|
||||
"இல்லைஆனால்": "elif",
|
||||
"ஆக": "for",
|
||||
"வரை": "while",
|
||||
"நிரல்பாகம்": "def",
|
||||
"கோப்பு": "class",
|
||||
"பின்கோடு": "return",
|
||||
"நிறுத்து": "break",
|
||||
"தொடரவும்": "continue",
|
||||
"தொடர்": "continue",
|
||||
"கடந்துசெல்": "pass",
|
||||
"முயற்சி": "try",
|
||||
"தவிர": "except",
|
||||
"இறுதியில்": "finally",
|
||||
"கடைசியில்": "finally",
|
||||
"எழுப்பு": "raise",
|
||||
"உடன்": "with",
|
||||
"இறக்கு": "import",
|
||||
@@ -44,13 +44,13 @@
|
||||
"ஒன்றுமில்லை": "None"
|
||||
},
|
||||
"builtins": {
|
||||
"அச்சிடு": "print",
|
||||
"பதிப்பி": "print",
|
||||
"உள்ளீடு": "input",
|
||||
"நீளம்": "len",
|
||||
"வரம்பு": "range",
|
||||
"வகை": "type",
|
||||
"முழுஎண்": "int",
|
||||
"மிதவை": "float",
|
||||
"தசமஎண்": "float",
|
||||
"சரம்": "str",
|
||||
"பட்டியல்": "list",
|
||||
"அகராதி": "dict",
|
||||
@@ -126,5 +126,16 @@
|
||||
"தொகுப்புகள்": "collections",
|
||||
"பாதை": "pathlib",
|
||||
"வழக்கமொழி": "re"
|
||||
}
|
||||
}
|
||||
},
|
||||
"postfix_keywords": [
|
||||
"if",
|
||||
"elif",
|
||||
"while",
|
||||
"class",
|
||||
"with",
|
||||
"try",
|
||||
"except",
|
||||
"finally",
|
||||
"from"
|
||||
]
|
||||
}
|
||||
1
packages/langs/zh/README.md
Normal file
1
packages/langs/zh/README.md
Normal file
@@ -0,0 +1 @@
|
||||
# foreignthon-zh
|
||||
22
packages/langs/zh/pyproject.toml
Normal file
22
packages/langs/zh/pyproject.toml
Normal file
@@ -0,0 +1,22 @@
|
||||
[build-system]
|
||||
requires = ["hatchling"]
|
||||
build-backend = "hatchling.build"
|
||||
|
||||
[project]
|
||||
name = "foreignthon-zh"
|
||||
version = "0.1.0"
|
||||
description = "Chinese language pack for ForeignThon."
|
||||
license = { text = "GPL v3" }
|
||||
requires-python = ">=3.9"
|
||||
authors = [
|
||||
{ name = "Cody Trainer" },
|
||||
]
|
||||
keywords = ["foreignthon", "chinese", "中文", "mandarin"]
|
||||
|
||||
dependencies = ["foreignthon>=0.4.1"]
|
||||
|
||||
[project.entry-points."foreignthon.langs"]
|
||||
zh = "foreignthon_zh"
|
||||
|
||||
[tool.hatch.build.targets.wheel]
|
||||
packages = ["src/foreignthon_zh"]
|
||||
5
packages/langs/zh/src/foreignthon_zh/__init__.py
Normal file
5
packages/langs/zh/src/foreignthon_zh/__init__.py
Normal file
@@ -0,0 +1,5 @@
|
||||
from importlib.resources import files
|
||||
|
||||
|
||||
def get_pack_path():
|
||||
return files(__name__) / "zh.json"
|
||||
149
packages/langs/zh/src/foreignthon_zh/zh.json
Normal file
149
packages/langs/zh/src/foreignthon_zh/zh.json
Normal file
@@ -0,0 +1,149 @@
|
||||
{
|
||||
"meta": {
|
||||
"name": "Chinese",
|
||||
"native_name": "中文",
|
||||
"code": "zh",
|
||||
"version": "0.1.0",
|
||||
"authors": []
|
||||
},
|
||||
"keywords": {
|
||||
"如果": "if",
|
||||
"否则": "else",
|
||||
"否": "elif",
|
||||
"对于": "for",
|
||||
"而": "while",
|
||||
"功能": "def",
|
||||
"类": "class",
|
||||
"导入": "import",
|
||||
"从": "from",
|
||||
"como": "as",
|
||||
"返回": "return",
|
||||
"打断": "break",
|
||||
"继续": "continue",
|
||||
"pasar": "pass",
|
||||
"intentar": "try",
|
||||
"excepto": "except",
|
||||
"finalmente": "finally",
|
||||
"提出": "raise",
|
||||
"同": "with",
|
||||
"在": "in",
|
||||
"是": "is",
|
||||
"和": "and",
|
||||
"或": "or",
|
||||
"不": "not",
|
||||
"elim": "del",
|
||||
"global": "global",
|
||||
"nolocal": "nonlocal",
|
||||
"afirmar": "assert",
|
||||
"generar": "yield",
|
||||
"esperar": "await",
|
||||
"asinc": "async",
|
||||
"lambda": "lambda",
|
||||
"真": "True",
|
||||
"假": "False",
|
||||
"空": "None"
|
||||
},
|
||||
"builtins": {
|
||||
"写": "print",
|
||||
"打印": "print",
|
||||
"扫描": "input",
|
||||
"lon": "len",
|
||||
"dist": "range",
|
||||
"型": "type",
|
||||
"数字": "int",
|
||||
"浮点数": "float",
|
||||
"字符串": "str",
|
||||
"列表": "list",
|
||||
"dicc": "dict",
|
||||
"conj": "set",
|
||||
"tupla": "tuple",
|
||||
"布尔": "bool",
|
||||
"abrir": "open",
|
||||
"enumerar": "enumerate",
|
||||
"map": "map",
|
||||
"filtrar": "filter",
|
||||
"ordenado": "sorted",
|
||||
"invertido": "reversed",
|
||||
"sum": "sum",
|
||||
"min": "min",
|
||||
"max": "max",
|
||||
"abs": "abs",
|
||||
"redondear": "round",
|
||||
"rnd": "round",
|
||||
"todos": "all",
|
||||
"alguno": "any",
|
||||
"esinstancia": "isinstance",
|
||||
"teneatri": "hasattr",
|
||||
"obtatri": "getattr",
|
||||
"estabatri": "setattr",
|
||||
"repr": "repr",
|
||||
"formatear": "format",
|
||||
"vars": "vars",
|
||||
"sigue": "next",
|
||||
"id": "id",
|
||||
"car": "chr",
|
||||
"十六进制": "hex",
|
||||
"二进制": "bin",
|
||||
"八进制": "oct"
|
||||
},
|
||||
"exceptions": {
|
||||
"Excepcion": "Exception",
|
||||
"ExcepcionBase": "BaseException",
|
||||
"ErrorDeValor": "ValueError",
|
||||
"ErrorDeTipo": "TypeError",
|
||||
"ErrorDeClave": "KeyError",
|
||||
"ErrorDeIndice": "IndexError",
|
||||
"ErrorDeAtributo": "AttributeError",
|
||||
"ErrorDeNombre": "NameError",
|
||||
"ErrorDeImportacion": "ImportError",
|
||||
"ErrorDelSistema": "OSError",
|
||||
"ArchivoNoEncontrado": "FileNotFoundError",
|
||||
"ErrorDeEjecucion": "RuntimeError",
|
||||
"DetenerIteracion": "StopIteration",
|
||||
"SalidaDelSistema": "SystemExit",
|
||||
"InterrupcionDeTeclado": "KeyboardInterrupt",
|
||||
"ErrorNoImplementado": "NotImplementedError",
|
||||
"ErrorDeDivisionCero": "ZeroDivisionError",
|
||||
"ErrorDeRecursion": "RecursionError",
|
||||
"ErrorDeSintaxis": "SyntaxError",
|
||||
"ErrorDeAfirmacion": "AssertionError",
|
||||
"ErrorDeDesbordamiento": "OverflowError",
|
||||
"ErrorDeMemoria": "MemoryError",
|
||||
"ErrorDePermiso": "PermissionError",
|
||||
"ErrorDeTiempoAgotado": "TimeoutError"
|
||||
},
|
||||
"error_messages": {
|
||||
"SyntaxError": "Error de sintaxis",
|
||||
"ValueError": "Error de valor",
|
||||
"TypeError": "Error de tipo",
|
||||
"KeyError": "Error de clave",
|
||||
"IndexError": "Error de índice",
|
||||
"AttributeError": "Error de atributo",
|
||||
"NameError": "Error de nombre",
|
||||
"ImportError": "Error de importación",
|
||||
"FileNotFoundError": "Archivo no encontrado",
|
||||
"ZeroDivisionError": "Error división por cero",
|
||||
"RecursionError": "Error de recursión",
|
||||
"RuntimeError": "Error de ejecución",
|
||||
"MemoryError": "Error de memoria",
|
||||
"OverflowError": "Error de desbordamiento",
|
||||
"AssertionError": "Error de afirmación",
|
||||
"NotImplementedError": "Error no implementado",
|
||||
"StopIteration": "Detener iteración",
|
||||
"KeyboardInterrupt": "Interrupción de teclado",
|
||||
"PermissionError": "Error de permiso",
|
||||
"TimeoutError": "Error de tiempo agotado"
|
||||
},
|
||||
"stdlib": {
|
||||
"数学": "math",
|
||||
"系统": "sys",
|
||||
"日期时间": "datetime",
|
||||
"时间": "time",
|
||||
"aleatorio": "random",
|
||||
"aleatoria": "random",
|
||||
"colecciones": "collections",
|
||||
"ruta": "pathlib",
|
||||
"er": "re"
|
||||
},
|
||||
"postfix_keywords": []
|
||||
}
|
||||
Reference in New Issue
Block a user