lang-bootstrap/06/main.lua
Dawid Sobczak e6b88d5a0f Add stage 06: Lua bootstrap
The goal of stage 06 is to try parse zig synax in lua. I pulled in
lpeglable 1.2.0 and parser-gen off github to get started. All of this
needs to be cleaned up rather soon.

Lua boostraps using tcc and musl from the previous stage. Since musl
0.6.0 doesn't support dynamic linking this build of lua doesn't support
shared libraries. I couldn't easily patch musl with dlopen and friends
so instead I link statically and call deps with c api.
2023-07-06 12:32:47 +01:00

44 lines
No EOL
1 KiB
Lua

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, ""))