Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/marteinn/lua-to-python
Lua to python compiler
https://github.com/marteinn/lua-to-python
ast lua python
Last synced: about 1 month ago
JSON representation
Lua to python compiler
- Host: GitHub
- URL: https://github.com/marteinn/lua-to-python
- Owner: marteinn
- Created: 2019-08-07T13:58:13.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2022-05-23T16:56:34.000Z (over 2 years ago)
- Last Synced: 2023-04-26T15:41:00.999Z (over 1 year ago)
- Topics: ast, lua, python
- Language: Python
- Homepage:
- Size: 82 KB
- Stars: 15
- Watchers: 3
- Forks: 3
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Lua to Python
This is a project where I attempt to convert Lua to Python, by transforming Lua into Python AST and then running it.
## Current status
- Variable assignments, basic datatypes and comparisons, if statements, while loops and functions are working.## Getting started
- `pip install -r requirements.txt`
```
Usage: compile.py [OPTIONS] SOURCE_FILEOptions:
--strip_comments INTEGER Remove comments from tokens
--tokens INTEGER Show tokens generated by lexer
--ast INTEGER Show the internal AST (later transformed to Python
AST
--py_ast INTEGER Show Python AST
--py_code INTEGER Show generated Python code
--help Show this message and exit.
```Example: `./compile.py --strip-comments=1 examples/functions.lua`
## Roadmap
- [x] Single line comments
- [x] Multiline comments
- [x] Numbers
- [x] Strings
- [x] Nil types
- [x] Variable assignments
- [x] Addition
- [x] Multiplication
- [x] If statements
- [x] Nested if statements
- [x] `~=` operator
- [x] `==` operator
- [x] `while` keyword
- [x] Concat strings with `..`
- [x] Subtract values
- [x] `>=` operator
- [x] `<=` operator
- [x] Boolean types
- [x] `function` declarations
- [x] `return`
- [x] `not` logical operator
- [x] `bool` expression in comparison
- [x] `%` operator
- [x] `/` operator
- [x] `or` logical operator
- [x] `and` logical operator
- [x] Assign function return to variable
- [x] Double number support
- [x] Negative values
- [x] Anonymous functions
- [x] Variables with numbers in name
- [x] Table datatype
- [x] Support for accessing Table properties
- [x] Support for lteral notation (`['@!#']`) in Table
- [x] List as argument to Table constructor
- [x] `#` operator for retrieving Table/String length
- [x] Iterator for Table using `pairs`/`ipairs`
- [x] `_G` for globals access
- [x] `for` keyword
- [x] Add multiple assignment support (`x, y, z = 1, 2, 3`)
- [x] Add multiple assignment support in for loop target+iterator
- [x] Add multiline line support to anonymous functions
- [ ] `repeat` keyword
- [ ] Short circuit / tenary operator
- [ ] `local` variables
- [ ] Numbers beginning with `.` (ex `.123`)
- [ ] Undefined variables should return nil
- [ ] Dot property syntax in Table for string keys
- [ ] Function calls with single params should not require parens
- [ ] Metatable support for tables
- [ ] BUG: Function cannot call itself
- [ ] BUG: Function declaration in nested Table
- [ ] BUG: Nested attribute retrival with `["random"]["random2"]`
- [ ] BUG: Decimal type key in Table
- [ ] BUG: Table construct in function (ex: `pairs({a=1, b=2, c=3})`## References
- https://drew.ltd/blog/posts/2020-7-18.html - Many thanks for Drew and his excellent articles on how to build a programming language
- https://greentreesnakes.readthedocs.io/en/latest/
- https://github.com/python/cpython/blob/master/Lib/ast.py
- https://learnxinyminutes.com/docs/lua/