commit 00f79af1019459a1f5a05ea8fa75b19beeaf2730 Author: theFox6 Date: Tue Feb 11 10:41:41 2020 +0100 initialize project diff --git a/.project b/.project new file mode 100644 index 0000000..8801809 --- /dev/null +++ b/.project @@ -0,0 +1,17 @@ + + + VenusParser + + + + + + org.eclipse.dltk.core.scriptbuilder + + + + + + org.eclipse.ldt.nature + + diff --git a/.settings/org.eclipse.ldt.prefs b/.settings/org.eclipse.ldt.prefs new file mode 100644 index 0000000..af16c14 --- /dev/null +++ b/.settings/org.eclipse.ldt.prefs @@ -0,0 +1,2 @@ +Grammar__default_id=lua-5.2 +eclipse.preferences.version=1 diff --git a/init.lua b/init.lua new file mode 100644 index 0000000..c6867c8 --- /dev/null +++ b/init.lua @@ -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 diff --git a/runTest.lua b/runTest.lua new file mode 100644 index 0000000..f8c1834 --- /dev/null +++ b/runTest.lua @@ -0,0 +1,3 @@ +local p = dofile("src/init.lua") + +p.dovenus("src/test.venus") diff --git a/test.venus b/test.venus new file mode 100644 index 0000000..fed8311 --- /dev/null +++ b/test.venus @@ -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") +--]]