lazy fixes

This commit is contained in:
theFox6 2020-02-20 16:58:43 +01:00
parent ce7cf7a406
commit e29ade9887
Signed by: theFox6
GPG Key ID: C884FE8D3BCE128A
3 changed files with 45 additions and 29 deletions

View File

@ -18,12 +18,15 @@ function parser.warn(msg)
print("VenusParser warning: " .. msg)
end
--TODO: check if spaces before a curly brace were already added
--TODO: make some functions handling each group of commands
local function parse_element(el,pc)
if el == "" then
return el
end
local prefix
local precurlch = false
if el == "elseif" then
if pc.ifend then
pc.ifend = false
@ -33,8 +36,13 @@ local function parse_element(el,pc)
pc.ifend = false
pc.curlyopt = true
pc.precurly = el
precurlch = true
elseif pc.ifend then
prefix = pc.ifend
if pc.linestart then
prefix = pc.ifend
else
prefix = " "..pc.ifend
end
pc.ifend = false
end
@ -102,7 +110,7 @@ local function parse_element(el,pc)
pc.foreach = 0
table.insert(pc.opencurly, "for")
pc.curlyopt = false
return ") do",prefix
return ") do ",prefix
elseif not pc.curlyopt then
table.insert(pc.opencurly, "table")
return el,prefix
@ -117,13 +125,13 @@ local function parse_element(el,pc)
elseif pc.curlyopt == "for" or pc.curlyopt == "while" then
table.insert(pc.opencurly, pc.curlyopt)
pc.curlyopt = false
return " do",prefix
return " do ",prefix
elseif pc.curlyopt == "if" then
table.insert(pc.opencurly, pc.curlyopt)
pc.curlyopt = false
return " then",prefix
return " then ",prefix
end
elseif pc.precurly then
elseif pc.precurly and not precurlch then
pc.precurly = false
pc.curlyopt = false
end
@ -137,7 +145,11 @@ local function parse_element(el,pc)
elseif closecurly == "for" or closecurly == "while" or
closecurly == "function" or closecurly == "repeat" or
closecurly == "do" or closecurly == "else" then
return "end",prefix
if pc.linestart then
return "end",prefix
else
return " end",prefix
end
elseif closecurly == "if" then
pc.ifend = "end"
return "",prefix
@ -312,7 +324,7 @@ local function handle_prefix(el,p)
print("prel:" .. el)
end
--]]
return vp_util.concat_optnil(pre,el),lpre
return vp_util.concat_optnil(pre,el," "),lpre
end
return el
end

View File

@ -119,7 +119,7 @@ do {
table.insert(reft,i)
} elseif i%4 == 0 {
table.insert(reft,i/4)
}
} else {}
}
assert(vp_util.dftc(reft,{3,1,6,2,9}))
}
@ -203,4 +203,6 @@ local fn concatsub(t) {
}
assert(vp_util.dftc(concatsub(tt),{"hello there", "venus test"}))
assert(not (() => {if(true){return}return true})())
print("venus test end")

View File

@ -22,13 +22,13 @@ local function for_in_test()
}
local reft = {}
for i,el in pairs(testt) do
for i,el in pairs(testt) do
reft[i] = el
end
assert(vp_util.dftc(reft, testt))
assert(vp_util.dftc(reft, testt) )
reft = {}
for _,el in pairs(testt) do
for _,el in pairs(testt) do
table.insert(reft,el)
end
@ -36,7 +36,7 @@ local function for_in_test()
for _, el in pairs(testt ) do
table.insert(reft2,el)
end
assert(vp_util.dftc(reft, reft2))
assert(vp_util.dftc(reft, reft2) )
end
for_in_test()
@ -56,7 +56,7 @@ local function shadow_test()
local function a()
return "function"
end
assert(a()=="function")
assert(a() =="function")
local reft = {}
do
@ -76,7 +76,7 @@ local function shadow_test()
end
assert(n == 12)
assert(a()=="function")
assert(a() =="function")
end
shadow_test()
@ -84,28 +84,28 @@ shadow_test()
local function t()
return "hi"
end
assert(t()=="hi")
assert(t() =="hi")
local function t2()
return "also hi"
end
assert(type(t2)=="function")
assert(t2()=="also hi")
assert(type(t2) =="function")
assert(t2() =="also hi")
local b = true
if (true) then
if (true) then
b = "weewoo"
end
assert(b == "weewoo")
local reft = {}
for i = 0, 10 do
for i = 0, 10 do
table.insert(reft,i)
end
assert(vp_util.dftc(reft,{0,1,2,3,4,5,6,7,8,9,10}))
local reft2 = {}
for _, el in pairs({"lot's of test",2,"3",1} ) do
for _, el in pairs({"lot's of test",2,"3",1} ) do
table.insert(reft2,el)
end
assert(vp_util.dftc(reft2,{"lot's of test",2,"3",1}))
@ -113,13 +113,13 @@ assert(vp_util.dftc(reft2,{"lot's of test",2,"3",1}))
do
local reft = {}
local i = 0
while i < 10 do
while i < 10 do
i = i + 1
if i%3 == 0 then
if i%3 == 0 then
table.insert(reft,i)
elseif i%4 == 0 then
elseif i%4 == 0 then
table.insert(reft,i/4)
end
else end
end
assert(vp_util.dftc(reft,{3,1,6,2,9}))
end
@ -147,7 +147,7 @@ assert(
end, 10, 6) == 16
)
assert(callit(function() end,false)==nil)
assert(callit(function() end,false)==nil)
---
--comment
@ -163,7 +163,7 @@ local function decj()
j = j - 1
return j-- not a decrement, only returns n, this is a comment
end
assert(decj()==1)
assert(decj() ==1)
assert(j == 1)
local function reti()
@ -172,7 +172,7 @@ local function reti()
end
i = i + 1
assert(reti() == 2)
assert(reti() == 2)
-- () => {}
@ -196,11 +196,13 @@ local tt = {
local function concatsub(t)
local ret = {}
for _, el in pairs(t ) do
for _, el in pairs(t ) do
table.insert(ret,table.concat(el," "))
end
return ret
end
assert(vp_util.dftc(concatsub(tt),{"hello there", "venus test"}))
assert(vp_util.dftc(concatsub(tt) ,{"hello there", "venus test"}))
assert(not (function() if(true) then return end return true end)() )
print("venus test end")