mirror of
https://github.com/Reuh/candran.git
synced 2025-10-27 17:59:30 +00:00
Candran 0.2
Changed a LOT. Notable changes: * Removed decorators, as they're not that useful, unless rewriting most Lua libraries API. * Added functions parameters default values. * Added Lua 5.3 stuff and building to Lua 5.1. * Remplaced the LuaMinify parser by lua-parser. It now requires some non-Lua dependencies (LPeg) unfortunately, but it's waaaaaay easier to handle. Code should be adaptable to any Metalua-like AST generator anyway. * The generated code now look like shit, and comment are stripped, because the parser ignore them. Oh well. * Changed a few things in the preprocessor environment. * Nobody will read this commit message I guess. If you did, create an issue saying "I love pineapple flavored bread".
This commit is contained in:
parent
1875ea31de
commit
2a1e293aa5
45 changed files with 3899 additions and 11569 deletions
44
canc.lua
Normal file
44
canc.lua
Normal file
|
|
@ -0,0 +1,44 @@
|
|||
#!/bin/lua
|
||||
local candran = require("candran")
|
||||
local cmdline = require("cmdline")
|
||||
|
||||
if #arg < 1 then
|
||||
print("Candran compiler version "..candran.VERSION.." by Reuh")
|
||||
print("Usage: "..arg[0].." [target=<target>] [dest=<destination directory>] [-print] [preprocessor arguments] 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()
|
||||
|
||||
local out = candran.make(input, args)
|
||||
|
||||
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
|
||||
Loading…
Add table
Add a link
Reference in a new issue