From a2d6c449808f968b0f0f5125cce3d8148d3b871d Mon Sep 17 00:00:00 2001 From: theFox6 Date: Wed, 11 Mar 2020 08:55:08 +0100 Subject: [PATCH] renamed repository --- .project | 2 +- VenusParser.lua => LuaVenusCompiler.lua | 52 ++++++++++++------------- README.md | 38 +++++++++--------- init.lua | 16 ++++---- runTest.lua | 4 +- test.venus | 2 +- testout/test.lua | 2 +- translateTest.lua | 4 +- vp_util.lua => vc_util.lua | 50 ++++++++++++------------ 9 files changed, 85 insertions(+), 85 deletions(-) rename VenusParser.lua => LuaVenusCompiler.lua (87%) rename vp_util.lua => vc_util.lua (79%) diff --git a/.project b/.project index 8801809..e4593c5 100644 --- a/.project +++ b/.project @@ -1,6 +1,6 @@ - VenusParser + LuaVenusCompiler diff --git a/VenusParser.lua b/LuaVenusCompiler.lua similarity index 87% rename from VenusParser.lua rename to LuaVenusCompiler.lua index 485521b..d48a18b 100644 --- a/VenusParser.lua +++ b/LuaVenusCompiler.lua @@ -1,7 +1,7 @@ -local local_path = VenusParser.path or "" -local vp_util = dofile(local_path.."vp_util.lua") +local local_path = LuaVenusCompiler.path or "" +local vp_util = dofile(local_path.."vc_util.lua") -local parser = {} +local compiler = {} local elements = { names = "^(%a%w*)$", @@ -14,8 +14,8 @@ local elements = { local non_space_elements = {elements.special_combined,elements.special,elements.strings} -function parser.warn(msg) - print("VenusParser warning: " .. msg) +function compiler.warn(msg) + print("LuaVenusCompiler warning: " .. msg) end --TODO: check if spaces before a curly brace were already added @@ -61,7 +61,7 @@ local function parse_element(el,pc) if el == "=>" then if not pc.lambargs then - parser.warn(("invalid lambda in line %i"):format(pc.line)) + compiler.warn(("invalid lambda in line %i"):format(pc.line)) return el end local larg = pc.lambargs @@ -72,7 +72,7 @@ local function parse_element(el,pc) return "function" .. larg .. " " elseif pc.lambend then if prefix then - parser.warn(("end statement and lambda match end may be mixed in line %i"):format(pc.line)) + compiler.warn(("end statement and lambda match end may be mixed in line %i"):format(pc.line)) prefix = pc.lambargs .. prefix else prefix = pc.lambargs @@ -154,7 +154,7 @@ local function parse_element(el,pc) pc.ifend = "end" return "",prefix else - parser.warn(("closing curly bracket in line %i could not be matched to an opening one"):format(pc.line)) + compiler.warn(("closing curly bracket in line %i could not be matched to an opening one"):format(pc.line)) return el,prefix end elseif el == "foreach" then @@ -220,7 +220,7 @@ local function parse_element(el,pc) pc.optassign = false return " = " .. nam .. " + 1" else - parser.warn(("empty increment in line %i"):format(pc.line)) + compiler.warn(("empty increment in line %i"):format(pc.line)) return el, prefix end elseif el == "+=" then @@ -229,7 +229,7 @@ local function parse_element(el,pc) pc.optassign = false return "= " .. nam .. "+" else - parser.warn(("empty increment assignment in line %i"):format(pc.line)) + compiler.warn(("empty increment assignment in line %i"):format(pc.line)) end elseif el == "-=" then if pc.optassign then @@ -237,7 +237,7 @@ local function parse_element(el,pc) pc.optassign = false return "= " .. nam .. "-" else - parser.warn(("empty decrement assignment in line %i"):format(pc.line)) + compiler.warn(("empty decrement assignment in line %i"):format(pc.line)) end elseif el == "*=" then if pc.optassign then @@ -245,7 +245,7 @@ local function parse_element(el,pc) pc.optassign = false return "= " .. nam .. "*" else - parser.warn(("empty multiply assignment in line %i"):format(pc.line)) + compiler.warn(("empty multiply assignment in line %i"):format(pc.line)) end elseif el == "/=" then if pc.optassign then @@ -253,7 +253,7 @@ local function parse_element(el,pc) pc.optassign = false return "= " .. nam .. "/" else - parser.warn(("empty divide assignment in line %i"):format(pc.line)) + compiler.warn(("empty divide assignment in line %i"):format(pc.line)) end elseif el == "^=" then if pc.optassign then @@ -261,7 +261,7 @@ local function parse_element(el,pc) pc.optassign = false return "= " .. nam .. "^" else - parser.warn(("empty power assignment in line %i"):format(pc.line)) + compiler.warn(("empty power assignment in line %i"):format(pc.line)) end elseif el == ".=" then if pc.optassign then @@ -269,7 +269,7 @@ local function parse_element(el,pc) pc.optassign = false return "= " .. nam .. ".." else - parser.warn(("empty concatenation assignment in line %i"):format(pc.line)) + compiler.warn(("empty concatenation assignment in line %i"):format(pc.line)) end end --print(el,pc.instring and "in string" or "") @@ -441,7 +441,7 @@ local function handle_lineend_lambargs(pc) return "" end -function parser.tl_venus_string(str) +function compiler.tl_venus_string(str) local fc = "" local pc = {instring = false, opencurly = {}, line = 0} for l,e in vp_util.optmatch(str,"\n") do @@ -460,20 +460,20 @@ function parser.tl_venus_string(str) end end if (#pc.opencurly > 0) then - parser.warn("not all curly brackets were closed") + compiler.warn("not all curly brackets were closed") end return fc end -function parser.tl_venus_file(file) +function compiler.tl_venus_file(file) local f = io.open(file) - local ret = parser.tl_venus_string(f:read("*a")) + local ret = compiler.tl_venus_string(f:read("*a")) f:close() return ret end -function parser.loadvenus(file,env) - local fc = parser.tl_venus_file(file) +function compiler.loadvenus(file,env) + local fc = compiler.tl_venus_file(file) if env then return loadstring(fc,"@"..file,"t",env) else @@ -481,19 +481,19 @@ function parser.loadvenus(file,env) end end -function parser.dovenus(file) - local ff, err = parser.loadvenus(file) +function compiler.dovenus(file) + local ff, err = compiler.loadvenus(file) if ff == nil then error(err,2) end return ff() end -function parser.convert_venus_file(venus_file_in,lua_file_out) - local s = parser.tl_venus_file(venus_file_in) +function compiler.convert_venus_file(venus_file_in,lua_file_out) + local s = compiler.tl_venus_file(venus_file_in) local f = io.open(lua_file_out,"w") f:write(s) f:close() end -return parser +return compiler diff --git a/README.md b/README.md index 4fb6edf..afc97fd 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ -# venus lua parser +# LuaVenusCompiler [![luacheck][luacheck badge]][luacheck workflow] -A parser that loads venus files into lua. Written in lua. -The parser reads a venus file and replaces venus syntax by lua syntax. +A compiler that translates venus files into lua. Written in lua. +The compiler reads a venus file and replaces venus syntax by lua syntax. It can also load and run the result. ## features @@ -132,15 +132,15 @@ Assignment operators `+=`, `-=`, `*=`, `/=`, `^=` and `.=` can be used. local a = 0 -- increment a += 2 --- decrement +// decrement a -= 1 --- multiply +## multiply a *= 8 --- divide +// divide a /= 2 -- to the power of a ^= 3 --- concatenate string +// concatenate string a .= " str" ``` will generate @@ -160,21 +160,21 @@ a = a ^ 3 a = a .. " str" ``` -## working with the parser +## working with the compiler ### loading -The init.lua returns a function for loading the parser. +The init.lua returns a function for loading the compiler. You have to call it with the path to the script itself as argument. -In case you have the VenusParser directory within your project's +In case you have the LuaVenusCompiler directory within your project's ways of loding it may be: ```lua --in case your project is run within it's own folder -local vc = dofile("VenusParser/init.lua")("VenusParser/") +local vc = dofile("LuaVenusCompiler/init.lua")("LuaVenusCompiler/") --in case you have a variable called project_loc containing the path to your projects folder -local vc = dofile(project_loc.."/VenusParser/init.lua")(project_loc.."/VenusParser/") +local vc = dofile(project_loc.."/LuaVenusCompiler/init.lua")(project_loc.."/LuaVenusCompiler/") --using require -local vc = require("VenusParser")("VenusParser/") +local vc = require("LuaVenusCompiler")("LuaVenusCompiler/") ``` -When it is loaded it can also be accessed with the global called "VenusParser". +When it is loaded it can also be accessed with the global called "LuaVenusCompiler". ### running venus files `vc.dovenus(file)` works like `dofile(file)` @@ -186,17 +186,17 @@ It's argument can be a relative or absolute path to the file that should be load It returns a function that runs the generated lua. ### generating lua code -`vp.tl_venus_file(file)` returns the lua generated from the files contents +`vc.tl_venus_file(file)` returns the lua generated from the files contents It's argument can be a relative or absolute path to the file that should be translated. It returns the generated lua as string. -`vp.tl_venus_string(str)` returns the lua generated from the given string +`vc.tl_venus_string(str)` returns the lua generated from the given string It returns the generated lua as string. ### generating lua files -`vp.convert_venus_file(venus_file_in,lua_file_out)` generates a lua file +`vc.convert_venus_file(venus_file_in,lua_file_out)` generates a lua file It's arguments can be relative or absolute paths. The venus_file_in will be converted to lua and written to lua_file_out. -[luacheck badge]: https://github.com/theFox6/VenusParser/workflows/luacheck/badge.svg -[luacheck workflow]: https://github.com/theFox6/VenusParser/actions?query=workflow%3Aluacheck +[luacheck badge]: https://github.com/theFox6/LuaVenusCompiler/workflows/luacheck/badge.svg +[luacheck workflow]: https://github.com/theFox6/LuaVenusCompiler/actions?query=workflow%3Aluacheck diff --git a/init.lua b/init.lua index fadd629..7f59e86 100644 --- a/init.lua +++ b/init.lua @@ -1,16 +1,16 @@ -if VenusParser then - print("VenusParser warning: already initialized") +if rawget(_G,"LuaVenusCompiler") then + print("LuaVenusCompiler warning: already initialized") else - VenusParser = {} + LuaVenusCompiler = {} end -function VenusParser.loadFromPath(path) - VenusParser.path = path - local ret = dofile(path.."VenusParser.lua") +function LuaVenusCompiler.loadFromPath(path) + LuaVenusCompiler.path = path + local ret = dofile(path.."LuaVenusCompiler.lua") for i,v in pairs(ret) do - VenusParser[i] = v + LuaVenusCompiler[i] = v end return ret end -return VenusParser.loadFromPath +return LuaVenusCompiler.loadFromPath diff --git a/runTest.lua b/runTest.lua index 4f38318..8b4397e 100644 --- a/runTest.lua +++ b/runTest.lua @@ -1,3 +1,3 @@ -local vp = dofile("init.lua")("") +local vc = dofile("init.lua")("") -vp.dovenus("test.venus") +vc.dovenus("test.venus") diff --git a/test.venus b/test.venus index 700a9c4..80078dc 100644 --- a/test.venus +++ b/test.venus @@ -1,6 +1,6 @@ print("running venus test script") -local vp_util = dofile("vp_util.lua") +local vp_util = dofile("vc_util.lua") local function for_range_test() local a = 0 diff --git a/testout/test.lua b/testout/test.lua index a0cff42..4b645f4 100644 --- a/testout/test.lua +++ b/testout/test.lua @@ -1,6 +1,6 @@ print("running venus test script") -local vp_util = dofile("vp_util.lua") +local vp_util = dofile("vc_util.lua") local function for_range_test() local a = 0 diff --git a/translateTest.lua b/translateTest.lua index 2c4eb3c..72e0ec4 100644 --- a/translateTest.lua +++ b/translateTest.lua @@ -1,6 +1,6 @@ -local vp = dofile("init.lua")("") +local vc = dofile("init.lua")("") local o = "testout/test.lua" -vp.convert_venus_file("test.venus",o) +vc.convert_venus_file("test.venus",o) dofile(o) diff --git a/vp_util.lua b/vc_util.lua similarity index 79% rename from vp_util.lua rename to vc_util.lua index 8c31349..61b0ede 100644 --- a/vp_util.lua +++ b/vc_util.lua @@ -1,8 +1,8 @@ --- ---A module with lots of helpers for the VenusParser. +--A module with lots of helpers for the LuaVenusCompiler. -- ---@module vp_util -local vp_util = {} +--@module vc_util +local vc_util = {} --- --Find the first match of a set of patterns within a string. @@ -10,11 +10,11 @@ local vp_util = {} --The pattern, that can be found at the earliest position within the string is used to match. --If two patterns are at the same position the shorter match is returned. -- ---@function [parent=#vp_util] find_min_match +--@function [parent=#vc_util] find_min_match --@param #string str the string to be searched for the patterns --@param patterns the pattern or patterns that are searched within the string --@return the starting and the end position of the match -function vp_util.find_min_match(str,patterns) +function vc_util.find_min_match(str,patterns) local pats local patt = type(patterns) if patt == "string" then @@ -55,15 +55,15 @@ end --Every sequence given to the iteration is removed from the iterator. --Like this it will traverse the string splitting it into the matches and non-matches. -- ---@function [parent=#vp_util] optmatch +--@function [parent=#vc_util] optmatch --@param #string str the string to search for matches --@param patterns the pattern or patterns to split by --@return #function the iterator for a loop -function vp_util.optmatch(str,patterns) +function vc_util.optmatch(str,patterns) local cutstr = str return function() if not cutstr then return end - local spos, epos = vp_util.find_min_match(cutstr,patterns) + local spos, epos = vc_util.find_min_match(cutstr,patterns) local match local found = (spos == 1) if found then @@ -90,10 +90,10 @@ end --- --A function generating a table from an iterator. -- ---@function [parent=#vp_util] gen_table +--@function [parent=#vc_util] gen_table --@param #function it the iterator to use in a for loop --@return #table the table containing the returns of the iterator -function vp_util.gen_table(it) +function vc_util.gen_table(it) local tab = {} for el in it do table.insert(tab,el) @@ -108,11 +108,11 @@ end -- --It iterates over both tables checking if the other contains the same elements. -- ---@function [parent=#vp_util] dftc +--@function [parent=#vc_util] dftc --@param #table t1 the table to compare with t2 --@param #table t2 the table to compare with t1 --@return #boolean whether the tables contents are the same -function vp_util.dftc(t1,t2) +function vc_util.dftc(t1,t2) for i,el in pairs(t1) do if t2[i] ~= el then return false @@ -130,13 +130,13 @@ end --concatenate strings --if one string is nil the other is returned -- ---@function [parent=#vp_util] concat_optnil +--@function [parent=#vc_util] concat_optnil --@param #string fstr the first string to be concatenated --@param #string lstr the second string to be concatenated --@param #string sep the seperator to be added between the strings if both are present --@param #string retstr The string returned if both strings are empty. -- Can be true to return an empty string. -function vp_util.concat_optnil(fstr,lstr,sep,retstr) +function vc_util.concat_optnil(fstr,lstr,sep,retstr) if fstr then if lstr then if sep then @@ -167,20 +167,20 @@ function vp_util.concat_optnil(fstr,lstr,sep,retstr) end --- ---The unit tests for the vp utilities. +--The unit tests for the vc utilities. local function tests() - assert(vp_util.dftc({},{})) - assert(vp_util.dftc({1},{1})) - assert(not vp_util.dftc({1},{2})) - assert(vp_util.dftc({1,"2",true},{1,"2",true})) - assert(not vp_util.dftc({true,"1",1},{1,1,1})) + assert(vc_util.dftc({},{})) + assert(vc_util.dftc({1},{1})) + assert(not vc_util.dftc({1},{2})) + assert(vc_util.dftc({1,"2",true},{1,"2",true})) + assert(not vc_util.dftc({true,"1",1},{1,1,1})) - assert(vp_util.dftc(vp_util.gen_table(vp_util.optmatch("123","123")),{"123"})) - assert(vp_util.dftc(vp_util.gen_table(vp_util.optmatch("123","321")),{"123"})) - assert(vp_util.dftc(vp_util.gen_table(vp_util.optmatch("123", "1")), {"1","23"})) - assert(vp_util.dftc(vp_util.gen_table(vp_util.optmatch("123", "2")), {"1","2","3"})) + assert(vc_util.dftc(vc_util.gen_table(vc_util.optmatch("123","123")),{"123"})) + assert(vc_util.dftc(vc_util.gen_table(vc_util.optmatch("123","321")),{"123"})) + assert(vc_util.dftc(vc_util.gen_table(vc_util.optmatch("123", "1")), {"1","23"})) + assert(vc_util.dftc(vc_util.gen_table(vc_util.optmatch("123", "2")), {"1","2","3"})) end tests() -return vp_util +return vc_util