diff --git a/06/main.lua b/06/main.lua deleted file mode 100644 index 62d74c5..0000000 --- a/06/main.lua +++ /dev/null @@ -1,44 +0,0 @@ -local pg = require("parser-gen.parser-gen") -local peg = require "parser-gen.peg-parser" -local errs = {errMissingThen = "Missing Then"} -- one custom error -pg.setlabels(errs) - - -local f = assert(io.open("zig.peg", "r")) -local zig_grammar = f:read("*all") -f:close() -pg.compile(zig_grammar) - - --- local function dump(value, call_indent) --- if not call_indent then --- call_indent = "" --- end - --- local indent = call_indent .. " " - --- local output = "" - --- if type(value) == "table" then --- output = output .. "{" --- local first = true --- for inner_key, inner_value in pairs ( value ) do --- if not first then --- output = output .. ", " --- else --- first = false --- end --- output = output .. "\n" .. indent --- output = output .. inner_key .. " = " .. dump ( inner_value, indent ) --- end --- output = output .. "\n" .. call_indent .. "}" - --- elseif type (value) == "userdata" then --- output = "userdata" --- else --- output = value --- end --- return output --- end - --- print(dump(res, "")) \ No newline at end of file diff --git a/06/src/main.c b/06/src/main.c index 83aab82..5530ca7 100644 --- a/06/src/main.c +++ b/06/src/main.c @@ -12,7 +12,7 @@ int main (void) { luaopen_lpeglabel(L); lua_setglobal(L, "m"); - luaL_loadfile(L, "main.lua"); + luaL_loadfile(L, "src/main.lua"); error = lua_pcall(L, 0, LUA_MULTRET, 0); if (error) { fprintf(stderr, "%s", lua_tostring(L, -1)); diff --git a/06/src/main.lua b/06/src/main.lua new file mode 100644 index 0000000..9429ccc --- /dev/null +++ b/06/src/main.lua @@ -0,0 +1,13 @@ +local pg = require("parser-gen.parser-gen") +local peg = require("parser-gen.peg-parser") +local util = require("src.util") + + +-- local errs = {errMissingThen = "Missing Then"} -- one custom error +-- pg.setlabels(errs) + +-- local f = assert(io.open("zig.peg", "r")) +-- local zig_grammar = f:read("*all") +-- f:close() +-- pg.compile(zig_grammar) + diff --git a/06/src/util.lua b/06/src/util.lua new file mode 100644 index 0000000..04a3ff8 --- /dev/null +++ b/06/src/util.lua @@ -0,0 +1,34 @@ +local function dump(value, call_indent) + if not call_indent then + call_indent = "" + end + + local indent = call_indent .. " " + + local output = "" + + if type(value) == "table" then + output = output .. "{" + local first = true + for inner_key, inner_value in pairs ( value ) do + if not first then + output = output .. ", " + else + first = false + end + output = output .. "\n" .. indent + output = output .. inner_key .. " = " .. dump ( inner_value, indent ) + end + output = output .. "\n" .. call_indent .. "}" + + elseif type (value) == "userdata" then + output = "userdata" + else + output = value + end + return output +end + +return { + dump = dump +} \ No newline at end of file