Chelodina
Chelodina is a transpiler that converts LOGO:
TO triangle :length
REPEAT 3 [ FORWARD :length RIGHT 120 ]
END
TO flower :length :count
REPEAT 150 [
triangle :length
RIGHT 360 / :count
]
END
TO web
REPEAT 6 [ flower 150 18 ]
END
web
Into Python:
import turtle
def triangle(p_length):
for _ in range(3):
turtle.forward(p_length)
turtle.right(120.0)
def flower(p_length, p_count):
for _ in range(150):
triangle(p_length)
turtle.right(360.0 / p_count)
def web():
for _ in range(6):
flower(150.0, 18.0)
web()
turtle.done()
Installation
pip install chelodina
Usage
usage: chelodina [-h] --input INPUT [--run]
arguments:
-h, --help show this help message and exit
--input INPUT Logo source file
--run Run the transpiled code
There's some ready examples to try if you clone the repository:
chelodina --input examples/example1.logo
You can also trigger the program to run in a GUI:
chelodina --input examples/example1.logo --run
Status
- Implemented:
- Motion functions:
FORWARD,BACK,LEFT,RIGHT,SETPOS,SETX,SETY,SETHEADING,SETH,HOME - Screen functions:
DONE,CLEARSCREEN - Control structures:
REPEAT - Function calls and definitions with optional parameters
- Binary operations
- Motion functions:
This is still on an early stage, I focused on making some examples work. Functions with similar structure are trivial to implement, but I want to focus on improving the tests first.
For grammar reference look at grammar.bnf.
Known quirks
- Validations for a valid AST (e.g. to make sure a function parameter exists before trying to use it on a statement) are not user friendly yet. I suggest double-checking your programs elsewhere first.
- Only tested on Python 3.6+ so far.
Development
Use pipenv to install dependencies:
pipenv install --dev
Running tests
Run tests with:
pipenv run tests
Automatically run tests after detecting changes with:
pipenv run tests-watch
Debug
- The easy way is to write tests to debug your code. Feel free to use
assert Falsewhere necessary. - If you need to run tests along anything that sends to or needs the standard output (a debugger like pdb or pudb), you'll need to run
pytestdirectly:pytest --capture=no. - There's a library to pretty-print your AST in the
utilspackage. Usage example:
from chelodina import compiler
from chelodina.utils.debug import parseprint
logo_code = """
to myfunction
forward 51.0
left 91
end
"""
parsed_ast = compiler.get_ast(logo_code)
parseprint(parsed)
And you'll see the resulting AST:
Module(body=[
Import(names=[
alias(name='turtle', asname=None),
]),
FunctionDef(name='myfunction', args=arguments(args=[], vararg=None, kwonlyargs=[], kw_defaults=[], kwarg=None, defaults=[]), body=[
Expr(value=Call(func=Attribute(value=Name(id='turtle', ctx=Load()), attr='forward', ctx=Load()), args=[
Num(n=51.0),
], keywords=[])),
Expr(value=Call(func=Attribute(value=Name(id='turtle', ctx=Load()), attr='left', ctx=Load()), args=[
Num(n=91.0),
], keywords=[])),
], decorator_list=[], returns=None),
Expr(value=Call(func=Attribute(value=Name(id='turtle', ctx=Load()), attr='done', ctx=Load()), args=[], keywords=[])),
])
Code style
I use black for code formatting, please install the pre-commit hook before doing a PR. This will be enforced with a linter check in the future.
You can run the command manually too:
black .
Not required, but if you install EditorConfig in your editor of choice it will make your life easier.
Metadata
Release files for chelodina 0.5.5
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| chelodina-0.5.5.tar.gz | 8.1 kB | Without provenance | Details for chelodina-0.5.5.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| chelodina-0.5.5-py3-none-any.whl | Python 3 | none | any | Details for chelodina-0.5.5-py3-none-any.whl |
Total release size: 18.3 kB
Release files / chelodina-0.5.5.tar.gz
| Download URL | chelodina-0.5.5.tar.gz |
|---|---|
| Size | 8.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
70876bec3e3dad992450dadfc19a1a4d170c05d6eadeb63815b5abb370325dfe
|
|
BLAKE2b-256 checksum How to use checksums |
582547b62cae278dc56c4c130659966ebe6980fcebb9f7939478156e54cde324
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/1.12.1 pkginfo/1.4.2 requests/2.19.1 setuptools/40.4.3 requests-toolbelt/0.8.0 tqdm/4.26.0 CPython/3.7.0
|
Release files / chelodina-0.5.5-py3-none-any.whl
| Download URL | chelodina-0.5.5-py3-none-any.whl |
|---|---|
| Size | 10.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
4b87542a300e87ea7c1dc24193d576cd6053dd991bef1cb2c8b7b84addfb4673
|
|
BLAKE2b-256 checksum How to use checksums |
3ba7568195ab5165ee450fafcb6e405491d1b9aec4d09fa855e96c5f52c30afe
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/1.12.1 pkginfo/1.4.2 requests/2.19.1 setuptools/40.4.3 requests-toolbelt/0.8.0 tqdm/4.26.0 CPython/3.7.0
|
Security for chelodina 0.5.5
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.