|
Warning: this is an htmlized version!
The original is here, and the conversion rules are here. |
-- This file:
-- http://anggtwu.net/LUA/Comissao1.lua.html
-- http://anggtwu.net/LUA/Comissao1.lua
-- (find-angg "LUA/Comissao1.lua")
-- Author: Eduardo Ochs <eduardoochs@gmail.com>
--
-- (defun e () (interactive) (find-angg "LUA/Comissao1.lua"))
-- Will be superseded by: (find-angg "LUA/TocLines1.lua")
--
-- «.run_options» (to "run_options")
require "ELpeg1" -- (find-angg "LUA/ELpeg1.lua")
-- (find-anggfile "LUA/Caepro4.lua" "lpeg.Copyto")
lpeg.ptmatch = function (pat, str) PP(pat:Ct():match(str)) end
lpeg.Copyto = function (pat, tag) return pat:Cg(tag) * Cb(tag) end
Comissao = Class {
type = "Comissao",
readtex = function ()
local bigstr = ee_readfile "~/LATEX/2022-2-C2-C3-ajuda.tex"
local pat = "\n\\mytocline{(.-)}{(.-)}{(.-)}"
local entries = VTable {}
local secpage = VTable {}
for n,sec,page in bigstr:gmatch(pat) do
local entry = {n=n, page=page, sec=sec}
table.insert(entries, entry)
entries[sec] = entry
end
return entries
end,
initialize = function ()
Comissao.entries = Comissao.readtex()
end,
pat = nil, -- defined after the class
parse = function (str)
local o = Comissao.pat:match(str)
if not o then return end
local entry = Comissao.entries[o.secname]
if not entry then return end
o.initpage = entry.page
o.realpage = o.subpage and (o.initpage + o.subpage - 1) or o.initpage
o.sexp = format("(ajup %d)", o.realpage)
o.sexpt = format("(ajut %d)", o.realpage)
return o
end,
pagesexp = function (head, str)
local o = Comissao.parse(str)
local p = o and o.realpage
return o and format("(%s %s)", head, p)
end,
texsection = function (str)
local o = str and Comissao.parse(str)
local s = (o and o.secname) or "toc"
return format('(ajua "%s")', s)
end,
sexp = function (str) return Comissao.pagesexp("-sexp", str) end,
sexpt = function (str) return Comissao.pagesexp("-sexpt", str) end,
sexpt = function (str)
local o = Comissao.parse(str)
return o and o.sexpt
end,
__index = {
},
}
Comissao.initialize()
gr,V,VA = Gram.new()
V.sec0 = Cs(R("AZ", "az", "09", "--")^1)
VA.secpage = V.sec0:Copyto"secname" * (P"_" * Cs(R"09"^1):Copyto"subpage")^0
Comissao.pat = gr:compile"secpage"
-- «run_options» (to ".run_options")
-- (find-angg ".emacs" "comissao1")
-- (find-angg "LUA/Caepro4.lua" "Abbrev")
-- (find-angg "LUA/Caepro4.lua" "run_options")
run_options = function (a, b, c)
if a == nil then return
elseif a == "Comissao1" then return
elseif a == "-pagesexp" then print(Comissao.pagesexp(b, c))
elseif a == "-texsection" then print(Comissao.texsection(b))
else PP("Bad options:", a, b, c)
end
end
run_options(...)
--[[
* (eepitch-lua51)
* (eepitch-kill)
* (eepitch-lua51)
dofile "Comissao1.lua"
= Comissao.entries
= Comissao.pat:match"foo:33"
PP(Comissao.pat:match"foo:33")
PP(Comissao.parse"foo:33")
PP(Comissao.parse"2022-dts-acomp")
PP(Comissao.parse"2022-dts-acomp_1")
PP(Comissao.parse"2022-dts-acomp_2")
PP(Comissao.sexp "2022-dts-acomp")
PP(Comissao.sexp "2022-dts-acomp_1")
PP(Comissao.sexp "2022-dts-acomp_2")
PP(Comissao.sexp "")
PP(Comissao.sexp "foo")
PP(run_options("-pagesexp", "aju", "2022-dts-acomp:3"))
PP(run_options("-texsection"))
PP(run_options("-texsection", ""))
PP(run_options("-texsection", "2022-dts-acomp:3"))
--]]
-- Local Variables:
-- coding: utf-8-unix
-- End: