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:
parent
2a1e293aa5
commit
4af2b41a0d
17 changed files with 2413 additions and 1865 deletions
|
|
@ -1,13 +1,30 @@
|
|||
return function(ast, opts)
|
||||
local options = {
|
||||
indentation = "\t",
|
||||
newline = "\n",
|
||||
requirePrefix = "CANDRAN_"
|
||||
}
|
||||
return function(code, ast, options)
|
||||
local lastInputPos = 1
|
||||
local prevLinePos = 1
|
||||
local lastSource = "nil"
|
||||
local lastLine = 1
|
||||
|
||||
local indentLevel = 0
|
||||
local function newline()
|
||||
return options.newline .. string.rep(options.indentation, indentLevel)
|
||||
local r = options.newline .. string.rep(options.indentation, indentLevel)
|
||||
if options.mapLines then
|
||||
local sub = code:sub(lastInputPos)
|
||||
local source, line = sub:sub(1, sub:find("\n")):match("%-%- (.-)%:(%d+)\n")
|
||||
|
||||
if source and line then
|
||||
lastSource = source
|
||||
lastLine = tonumber(line)
|
||||
else
|
||||
for _ in code:sub(prevLinePos, lastInputPos):gmatch("\n") do
|
||||
lastLine += 1
|
||||
end
|
||||
end
|
||||
|
||||
prevLinePos = lastInputPos
|
||||
|
||||
r = " -- " .. lastSource .. ":" .. lastLine .. r
|
||||
end
|
||||
return r
|
||||
end
|
||||
local function indent()
|
||||
indentLevel += 1
|
||||
|
|
@ -32,6 +49,9 @@ return function(ast, opts)
|
|||
|
||||
local tags
|
||||
local function lua(ast, forceTag, ...)
|
||||
if options.mapLines and ast.pos then
|
||||
lastInputPos = ast.pos
|
||||
end
|
||||
return tags[forceTag or ast.tag](ast, ...)
|
||||
end
|
||||
|
||||
|
|
@ -54,14 +74,30 @@ return function(ast, opts)
|
|||
Do = function(t)
|
||||
return "do" .. indent() .. lua(t, "Block") .. unindent() .. "end"
|
||||
end,
|
||||
-- Set{ {lhs+} opid? {expr+} }
|
||||
-- Set{ {lhs+} (opid? = opid?)? {expr+} }
|
||||
Set = function(t)
|
||||
if #t == 2 then
|
||||
return lua(t[1], "_lhs") .. " = " .. lua(t[2], "_lhs")
|
||||
else
|
||||
local r = lua(t[1], "_lhs") .. " = " .. lua({ t[2], t[1][1], t[3][1] }, "Op")
|
||||
for i=2, math.min(#t[3], #t[1]), 1 do
|
||||
r = r .. ", " .. lua({ t[2], t[1][i], t[3][i] }, "Op")
|
||||
elseif #t == 3 then
|
||||
return lua(t[1], "_lhs") .. " = " .. lua(t[3], "_lhs")
|
||||
elseif #t == 4 then
|
||||
if t[3] == "=" then
|
||||
local r = lua(t[1], "_lhs") .. " = " .. lua({ t[2], t[1][1], t[4][1] }, "Op")
|
||||
for i=2, math.min(#t[4], #t[1]), 1 do
|
||||
r = r .. ", " .. lua({ t[2], t[1][i], t[4][i] }, "Op")
|
||||
end
|
||||
return r
|
||||
else
|
||||
local r = lua(t[1], "_lhs") .. " = " .. lua({ t[3], t[4][1], t[1][1] }, "Op")
|
||||
for i=2, math.min(#t[4], #t[1]), 1 do
|
||||
r = r .. ", " .. lua({ t[3], t[4][i], t[1][i] }, "Op")
|
||||
end
|
||||
return r
|
||||
end
|
||||
else -- You are mad.
|
||||
local r = lua(t[1], "_lhs") .. " = " .. lua({ t[2], t[1][1], { tag = "Op", t[4], t[5][1], t[1][1] } }, "Op")
|
||||
for i=2, math.min(#t[5], #t[1]), 1 do
|
||||
r = r .. ", " .. lua({ t[2], t[1][i], { tag = "Op", t[4], t[5][i], t[1][i] } }, "Op")
|
||||
end
|
||||
return r
|
||||
end
|
||||
|
|
@ -274,12 +310,5 @@ return function(ast, opts)
|
|||
|
||||
#placeholder("patch")
|
||||
|
||||
if opts then
|
||||
for k, v in pairs(opts) do
|
||||
options[k] = v
|
||||
end
|
||||
end
|
||||
|
||||
local r = lua(ast)
|
||||
return requireStr .. r
|
||||
return requireStr .. lua(ast) .. newline()
|
||||
end
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue