1
0
Fork 0
mirror of https://github.com/Reuh/candran.git synced 2025-10-27 09:59:29 +00:00

Candran 0.3.0

* Added @ self alias
* Added short anonymous functions declaration
* Made assignment operators works in every direction, except up, down,
behind and below, because this would be hard to visualize.
* Moved files around.
* Error rewriting.
* Discover the amazing can commandline tool, which includes a fantastic°
REPL and program running abilities.
* Added functions which plagiarize Lua.
* Added 0.1.0 to the version number.
* If you still love pineapple flavored bread, don't hesitate to show
your feelings.

Also, the tests are out of date. Sad.

°: not really.
This commit is contained in:
Étienne Fildadut 2017-08-16 22:33:44 +02:00
parent 2a1e293aa5
commit 4af2b41a0d
17 changed files with 2413 additions and 1865 deletions

43
bin/can Normal file
View file

@ -0,0 +1,43 @@
#!/bin/lua
local candran = require("candran")
local cmdline = require("lib.cmdline")
local args = cmdline(arg)
if args.help or args.h then
print("Candran interpreter version "..candran.VERSION.." by Reuh")
print("Usage: "..arg[0].." [target=<target>] [options] filename")
return
end
if #args >= 1 then
candran.dofile(args[1], args)
else -- REPL
print("Candran " .. candran.VERSION)
candran.setup()
while true do
io.write("> ")
local line = io.read()
if line:match("^=") then
line = line:gsub("^=", "return tostring(") .. ")"
end
local p = dofile("lib/lua-parser/parser.lua")
local d = dofile("lib/lua-parser/pp.lua")
print(p.parse(line))
print(d.dump(p.parse(line)))
print(require"compiler.lua53"(p.parse(line)))
local t = { pcall(candran.load, line, "stdin") }
if t[1] == false then
print(t[2])
else
t = { pcall(t[2]) }
if t[1] == false then
print(t[2])
elseif #t > 1 then
print(unpack(t, 2))
end
end
end
end

57
bin/canc Normal file
View file

@ -0,0 +1,57 @@
#!/bin/lua
local candran = require("candran")
local cmdline = require("lib.cmdline")
if #arg < 1 then
print("Candran compiler version "..candran.VERSION.." by Reuh")
print("Usage: "..arg[0].." [target=<target>] [dest=<destination directory>] [-print] [-preprocess] [-compile] [options] filename...")
return
end
local args = cmdline(arg)
for _, file in ipairs(args) do
local dest = file:gsub("%.can$", "")..".lua"
if args.dest then
dest = args.dest .. "/" .. dest
end
if not args.print then
print("Compiling "..file.." in "..dest)
end
local inputFile, err = io.open(file, "r")
if not inputFile then error("Error while opening input file: "..err) end
local input = inputFile:read("*a")
inputFile:close()
if args.chunkname == nil then
args.chunkname = file
end
local out = input
if args.preprocess then
out = candran.preprocess(out, args)
end
if args.compile then
out = candran.compile(out, args)
end
if args.compile == nil and args.preprocess == nil then
out = candran.make(input, args)
end
if args.print then
print(out)
else
local outFile = io.open(dest, "w")
if not outFile then
os.execute("mkdir -p "..dest:gsub("[^/]+%.lua$", ""))
outFile, err = io.open(dest, "w")
if not outFile then
error("Error while writing output file: "..err)
end
end
outFile:write(out)
outFile:close()
end
end