Warning: this is an htmlized version!
The original is across this link,
and the conversion rules are here.
-- build.lua: generate a single dednat5.lua from separate files.
-- This file:
--   http://angg.twu.net/dednat5/build.lua.html
--   http://angg.twu.net/dednat5/build.lua
--                    (find-dn5 "build.lua")
-- Author: Eduardo Ochs <eduardoochs@gmail.com>
-- Version: 2011nov26
-- License: GPL3
--
-- Related to:   (find-blogme4 "build.lua")
-- See: (find-tkdiff "~/blogme4/build.lua" "~/dednat5/build.lua")
--
-- This script generates "dednat5.lua".
-- It needs to be run from the dednat5 directory,
-- It uses functions from: (find-angg "LUA/lua50init.lua")
-- Run with:               (find-sh0 "cd ~/dednat5/ && lua51 build.lua && chmod 755 dednat5.lua")
-- (defun m () (interactive) (find-sh0 "cd ~/dednat5/&&lua51 build.lua && chmod 755 dednat5.lua"))
-- (defun m () (interactive) (find-dn5sh "lua51 build.lua && chmod 755 dednat5.lua"))
-- (defun m () (interactive) (find-dn5sh "lua51 build.lua"))
-- (defun dd () (interactive) (eek "C-e 5*SPC -- SPC (find-dn5 SPC \" C-y .lua\" )"))
--

require "eoo"         -- (find-dn5 "eoo.lua")
require "common"      -- (find-dn5 "common.lua")
target = "dednat5.lua"   -- (find-dn5 "dednat5.lua")

----------------------------------------

T0 = {
  prog = "dednat5", 
  date = os.date("%Y%b%d %k:%M"):lower(),
  date = os.date("%Y%b%d %k:%M %Z"),
  c    = "dn5",
  dir  = "dednat5",
}
guill = function (str) return (str:gsub("<<", "\171"):gsub(">>", "\187")) end
spaces = function (n) return string.rep(" ", n) end
interpolate  = function (T, str) return (str:gsub("{([A-Za-z0-9]+)}", T)) end
interpolateg = function (T, str) return interpolate(T, guill(str)) end
template = function (str) return Template {str=str} end
Template = Class {
  type    = "Template",
  __index = {
    map = function (template, tbl)
        return interpolateg(over(T0)(tbl), template.str) 
      end,
    mapstem = function (template, stem, len, f)
        return template:map {
            stem = stem,
            s    = spaces((len or 20)-#stem),
            body = (f and f(stem)),
          }
      end,
    mapconcat = function (template, A, sep, len, f)
        local g = function (stem) return template:mapstem(stem, len, f) end
        return mapconcat(g, A, (sep or ""))
      end,
  },
}
module_body = function (stem)
    local name = stem..".lua"
    local contents  = readfile(name)
    local contents2 = contents:gsub("\nrequire", "\n-- require")
    local contents3 = contents2:gsub("\n%-%- dump%-to: tests.*", "")
    return contents3
  end

----------------------------------------

output__ = template [[
#!/usr/bin/env lua5.1
---- This is a one-file version of {prog}, generated
---- automatically by build.lua on {date}. See:
----   http://angg.twu.net/{dir}/build.lua.html
----                {sp}(find-{c} "build.lua")
----   http://angg.twu.net/{dir}/{prog}.lua.html
----                {sp}(find-{c} "dednat5.lua")

---- Index to the modules:
{index}

{body}

-- Local Variables:
-- coding:             raw-text-unix
-- ee-anchor-format:   "<<%s>>"
-- End:
]]

index_line__ = template [[
-- <<.{stem}.lua>>{s}(to "{stem}.lua")
]]

module__ = template [[
---- From: (find-{c} "{stem}")
---- <<{stem}.lua>>  (to ".{stem}.lua")
---- This block is from: (find-{c} "{stem}.lua")
{body}
]]

bigfile = function (stems)
    local index  = index_line__:mapconcat(stems)
    local body   = module__:mapconcat(stems, "\n", nil, module_body)
    local output = output__:map{index = index, body = body}
    return output
  end

    
----------------------------------------

stems = {
  -- The four lowest-level modules (all independent):
  "common",       -- (find-dn5 "common.lua")
  "eoo",          -- (find-dn5 "eoo.lua")
  "prefixes",     -- (find-dn5 "prefixes.lua")
  "parse",        -- (find-dn5 "parse.lua")
  --
  -- General functions to read and process ".tex" files
  -- and write out a ".dnt" file:
  "preamble",     -- (find-dn5 "preamble.lua")
  "process",      -- (find-dn5 "process.lua")
  -- 
  -- Code for generating derivation trees from "%:" lines:
  "treetex",      -- (find-dn5 "treetex.lua")
  "treesegs",     -- (find-dn5 "treesegs.lua")
  "treehead",     -- (find-dn5 "treehead.lua")
  --
  -- Code for generating diagxy diagrams from "%D" lines:
  "diagstacks",   -- (find-dn5 "diagstacks.lua")
  "diagtex",      -- (find-dn5 "diagtex.lua")
  "diagforth",    -- (find-dn5 "diagforth.lua")
  "diagmiddle",   -- (find-dn5 "diagmiddle.lua")
  --
  -- The Begriffsschrift extension (experimental):
  "begriff",      -- (find-dn5 "begriff.lua")
  -- The REPL, for interaction (experimental):
  "repl",         -- (find-dn5 "repl.lua")
  --
  -- Interpret command-line options and run everything:
  "options",      -- (find-dn5 "options.lua")
}

expansions = {
  BASE    = "common,eoo,errors,prefixes,parse",
  BASETEX = "preamble,process",
  TREES   = "treetex,treesegs,treehead",
  DIAGS   = "diagstacks,diagtex,diagforth,diagmiddle",
  B       = "BASE,BASETEX,TREES,DIAGS",
  BEGRIFF = "begriff",
  REPL    = "repl",
  E       = "BEGRIFF,REPL",
  O       = "options",
  ALL     = "B,E,O",
}

expand = function (T, str)
    local f = function (s) if T[s] then print(s.." -> "..T[s]); return T[s] end
      end
    while true do
      -- local newstr = str:gsub("([A-Z]+)", T)
      local newstr = str:gsub("([A-Z]+)", f)
      if newstr == str then return str end
      str = newstr
    end
  end



module_bodies_glued = function (stems)
    return mapconcat(module_body, stems, "\n\n\n")
  end

body_all = mapconcat(module_body, stems, "\n\n\n")

-- writefile(target, head_all..
--                   body_all..
--                   footer_all)
-- writefile(target, bigfile())
stems = split(expand(expansions, "ALL"), "([^,]+)")
writefile(target, bigfile(stems))

print(" Created: "..target)
print(" From: "..mapconcat(gformat "%1.lua", stems, " "))

-- dump-to: tests
--[===[
* (eepitch-lua51)
* (eepitch-kill)
* (eepitch-lua51)
dofile "build.lua"
= expand(expansions, "ALL")
stems = split(expand(expansions, "ALL"), "([^%s,]+)")
PP(stems)
PP(map(gformat "%0.lua", stems))
= bigfile {}
= module_body("eoo")
= bigfile {"eoo"}



* (eepitch-lua51)
* (eepitch-kill)
* (eepitch-lua51)
-- (find-angg ".emacs" "date")
-- (find-luamanualw3m "#pdf-os.date")
= os.date("%Y%b%d %k:%M")
= os.date("%Y%b%d %k:%M %Z"):lower()

--]===]



-- Local Variables:
-- coding:             raw-text-unix
-- ee-anchor-format:   "«%s»"
-- End: