Git repo: https://soniex2.autistic.space/git-repos/cratera.git (yes it
says forbidden, that's just because you can't view it on a web
browser. works fine with git.)
Bittorrent:
magnet:?xt=urn:btih:4633253f7c1861af2ee30e6ca9b9d964557104b9&dn=cratera-compiler-1.0.0.tar
SHA256:
6b9ee22b8b143af445582e399d6610c571c034b18e0f7655bb33b1dbdfe347ae
cratera-compiler-1.0.0.tar
SHA512:
6156f34cc9c4af55552e2b56ce12e2fcfd498814ae11f984074b7ba5ed30fd90050c2d8a86877c5ce278a96437d1710081325bcd1b60ca32cbdd5acb288479ca
cratera-compiler-1.0.0.tar
(checksums are necessary due to bittorrent being vulnerable to
SHAttered attack)
About 2 months ago I tried to make a pure-Lua Cratera to Lua compiler.
Things didn't go very well at the time and the best I could do was
report a perceived bug with how Lua handles numeric literals (namely,
x=1print(x) not requiring a space between the 1 and the print). This
monday I had the idea to do it completely differently and rather than
reimplement the Lua parser in pure-Lua I decided to use a bit of an
uh, unorthodox method. The Lua parser parses things eagerly, using
what I believe is a hand-written recursive descent parser. However, it
was much easier to just tokenize the whole source and store the tokens
in a table, and then it's just a simple matter of lightly massaging
the source as needed. Yes, it's quite slow, but it works quite nicely!
Additionally, no debug mappings are necessary, as it does its best to
adjust line numbers!
It should support Lua 5.1, Lua 5.2, Lua 5.3 and, for the most part,
LuaJIT. That is, you should be able to pass any Lua 5.1, Lua 5.2, Lua
5.3 and LuaJIT-compatible source code through it. It might have
trouble with LuaJIT-specific extensions tho, such as "ULL" literals.
$ cat README.md
The Cratera Programming Language (and support components)
=========================================================
This repo contains the Cratera to Lua compiler, as well as support
components for the Cratera to Lua compiler, namely a pure-Lua Lua
tokenizer and a table-based parser thing.
Cratera is a language very similar to Lua, and as such most of the Lua
manual applies to it. Additionally, it supports the following syntax
sugar, called "traits":
mytable:[mytrait].myfunction(myargument)
which is equivalent to:
mytable[mytrait].myfunction(mytable, myargument)
This syntax sugar is similar to the "methods" syntax sugar ([Lua 5.3
§3.4.10](http://www.lua.org/manual/5.3/manual.html#3.4.10),
[Lua 5.2 §3.4.9](http://www.lua.org/manual/5.2/manual.html#3.4.9),
[Lua 5.1 §2.5.8](http://www.lua.org/manual/5.1/manual.html#2.5.8)),
and, indeed, `mytable` is only evaluated once.
Why not use LPeg?
-----------------
The use of a custom parsing library boils down to two reasons:
1. LPeg can't stream or produce partial outputs. This just makes it
difficult to use for making a compiler.
2. LPeg can't process tables. It's still possible to use LPeg to parse
table-based structures, but one must serialize them beforehand, which
is... far from ideal, to say the least.