initialize project

This commit is contained in:
theFox6 2020-02-11 10:41:41 +01:00
commit 00f79af101
Signed by: theFox6
GPG Key ID: C884FE8D3BCE128A
5 changed files with 136 additions and 0 deletions

17
.project Normal file
View File

@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>VenusParser</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.dltk.core.scriptbuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.ldt.nature</nature>
</natures>
</projectDescription>

View File

@ -0,0 +1,2 @@
Grammar__default_id=lua-5.2
eclipse.preferences.version=1

55
init.lua Normal file
View File

@ -0,0 +1,55 @@
local parser = {}
local elements = "(%s*%g+)"
local function parse_element(el,pc)
local space = el:match("%s*")
local word = el:sub(#space+1)
if pc.foreach == 2 then
pc.foreach = 3
return space.."pairs("..word
end
if word == "foreach" then
pc.foreach = 1
return space .. "for"
elseif word == "for" then
pc.foreach = 0
elseif word == "in" then
if pc.foreach == 1 then
pc.foreach = 2
end
elseif word == "do" then
if pc.foreach == 3 then
return ")" .. el
end
end
--print(el)
return el
end
local function parse_line(l,pc)
local pl = ""
for w in l:gmatch(elements) do
pl = pl .. parse_element(w,pc)
end
return pl
end
function parser.loadvenus(file)
local fc = ""
local pc = {opencurly = {}}
for l in io.lines(file) do
fc = fc .. parse_line(l,pc) .. "\n"
end
return loadstring(fc,"@"..file)
end
function parser.dovenus(file)
local ff, err = parser.loadvenus(file)
if ff == nil then
error(err,2)
end
return ff()
end
return parser

3
runTest.lua Normal file
View File

@ -0,0 +1,3 @@
local p = dofile("src/init.lua")
p.dovenus("src/test.venus")

59
test.venus Normal file
View File

@ -0,0 +1,59 @@
print("test")
local testt = {
venus = "awesome",
"lots of test",1,2,
test2 = "hi"
}
for i = 0,5 do
print(i)
end
for _,el in pairs(testt) do
print(el)
end
foreach i,el in testt do
print(i.." = "..el)
end
--[[ coming soon
//comment
fn a()
print("function")
end
local i = 0
local j = 0
i = i + 1
j = j + 2
i++
j += 2
function t() {
print("hi")
}
if (true) {
print("weewoo")
}
for i = 0, 10 {
print(i)
}
function callit(fun,arg)
fun(arg)
end
callit(() => {
print("testing")
})
callit((t) => {
print(t)
}, "more test")
--]]