From 00f79af1019459a1f5a05ea8fa75b19beeaf2730 Mon Sep 17 00:00:00 2001 From: theFox6 Date: Tue, 11 Feb 2020 10:41:41 +0100 Subject: [PATCH] initialize project --- .project | 17 ++++++++++ .settings/org.eclipse.ldt.prefs | 2 ++ init.lua | 55 ++++++++++++++++++++++++++++++ runTest.lua | 3 ++ test.venus | 59 +++++++++++++++++++++++++++++++++ 5 files changed, 136 insertions(+) create mode 100644 .project create mode 100644 .settings/org.eclipse.ldt.prefs create mode 100644 init.lua create mode 100644 runTest.lua create mode 100644 test.venus 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") +--]]