|
Warning: this is an htmlized version!
The original is here, and the conversion rules are here. |
-- This file:
-- http://anggtwu.net/LUA/Verbatim4.lua.html
-- http://anggtwu.net/LUA/Verbatim4.lua
-- (find-angg "LUA/Verbatim4.lua")
-- Author: Eduardo Ochs <eduardoochs@gmail.com>
--
-- (defun e () (interactive) (find-angg "LUA/Verbatim4.lua"))
-- (defun o () (interactive) (find-angg "LUA/Verbatim3.lua"))
-- (defun a () (interactive) (find-angg "LUA/Actions1.lua"))
-- «.Verbatim» (to "Verbatim")
-- «.Verbatim-tests» (to "Verbatim-tests")
require "Actions1" -- (find-angg "LUA/Actions1.lua")
require "Co1" -- (find-angg "LUA/Co1.lua" "Co-tests")
require "Show2" -- (find-angg "LUA/Show2.lua")
-- __ __ _ _ _
-- \ \ / /__ _ __| |__ __ _| |_(_)_ __ ___
-- \ \ / / _ \ '__| '_ \ / _` | __| | '_ ` _ \
-- \ V / __/ | | |_) | (_| | |_| | | | | | |
-- \_/ \___|_| |_.__/ \__,_|\__|_|_| |_| |_|
--
-- «Verbatim» (to ".Verbatim")
Verbatim = Class {
type = "Verbatim",
from = function (o) return Verbatim {o = o} end,
__tostring = function (vb)
if type(vb.o) == "string" then return vb.o end
return mytostringv(vb.o)
end,
__index = {
act1 = function (vb,...) return Actions.from(vb):act1(...) end,
act = function (vb,...) return Actions.from(vb):act (...) end,
--
-- (find-angg "LUA/Co1.lua" "poor-mans-code")
-- vb:e(str) expands some (non-utf8) characters in str.
co = Co.new("#$", " %&\\^_{}~"):add("\n", "\\\\\n"),
e = function (vb, s) return vb.co:translate(s) end,
--
-- Some functions that are not methods, used by map
-- (find-LATEX "edrx21.sty" "defvbt" "vbtbgbox")
__e = function (s) return Verbatim({}):e(s) end,
__v = function (s) return format("\\vbox{%%\n%s%%\n}", s) end,
__h1 = function (s) return format("\\vbthbox{%s}", s) end,
__bg = function (s) return format("\\vbtbgbox{%s}", s) end,
--
-- Actions with arguments
_fmt = function (vb,fmt,...) vb.o = format(fmt,...) end,
_def = function (vb,name) vb:_fmt("\\def\\%s{%s}", name, vb.o) end,
_defvbt = function (vb,name) vb:_fmt("\\defvbt{%s}{%s}", name, vb.o) end,
_sa = function (vb,name) vb:_fmt("\\sa{%s}{%s}", name, vb.o) end,
--
-- Simple actions
prefix = " ",
_e = function (vb) vb.o = map(vb.__e, vb.o) end,
_h = function (vb) vb.o = map(vb.__h1, vb.o) end,
_v = function (vb) vb.o = vb.__v (vb.o) end,
_bg = function (vb) vb.o = vb.__bg(vb.o) end,
_c = function (vb) vb.o = table.concat(vb.o, "%\n"..vb.prefix) end,
_p = function (vb) vb.o = vb.prefix..vb.o end,
_o = function (vb) output(vb.o) end,
_P = function (vb) print(vb) end,
--
-- Other methods (for "users")
copy = function (vb) return deepcopy(vb) end,
sa = function (vb, name) return vb:act1("sa", name) end,
defvbt0 = function (vb, name) return vb:act1("defvbt", name) end,
defvbt = function (vb, name) return vb:act("e h c p v bg"):defvbt0(name) end,
},
}
-- «Verbatim-tests» (to ".Verbatim-tests")
--[==[
* (eepitch-lua51)
* (eepitch-kill)
* (eepitch-lua51)
dofile "Verbatim4.lua"
output = print
= Verbatim.__index.co
= Verbatim({}):e "Hello #$\n%&\\^_{}~!!!\n Hey hey"
Verbatim.from({"a", "bb", "ccc"}):act("P")
Verbatim.from({"a", "bb", "ccc"}):act("c P")
Verbatim.from({"a", "bb", "ccc"}):act("e h c P")
Verbatim.from({"a", "bb", "ccc"}):act("e h c p P")
Verbatim.from({"a", "bb", "ccc"}):act("e h c v P")
Verbatim.from({"a", "bb", "ccc"}):act("e h c p v P")
Verbatim.from({"a", "bb", "ccc"}):act("e h c p v bg P")
Verbatim.from({"a", "bb", "ccc"}):act("e h c p v bg def:foo P")
Verbatim.from({"a", "bb", "ccc"}):act("e h c p v bg defvbt:foo P")
= Verbatim.from({"a", "bb", "ccc"}):act("e h c p v bg")
= Verbatim.from({"a", "bb", "ccc"}):act("e h c p v bg"):sa("[a b c] box")
= Verbatim.from({"a", "bb", "ccc"}):act("e h c p v bg defvbt:foo")
= Verbatim.from({"a", "bb", "ccc"}):act("e h c p v bg"):defvbt0("foo")
= Verbatim.from({"a", "bb", "ccc"}):act("e h c p v bg"):defvbt0("foo bar")
= Verbatim.from({"a", "bb", "ccc"}):defvbt("foo bar")
Verbatim.from({"a", "bb", "ccc"}):defvbt("foo bar"):act("o")
--]==]
-- Local Variables:
-- coding: utf-8-unix
-- End: