Warning: this is an htmlized version!
The original is here, and
the conversion rules are here.
-- texinfo.lua:
-- This file:
--   http://angg.twu.net/blogme4/texinfo.lua.html
--   http://angg.twu.net/blogme4/texinfo.lua
--                    (find-blogme4 "texinfo.lua")
-- Author: Eduardo Ochs <eduardoochs@gmail.com>
-- Version: 2011sep27
-- License: GPL3
--
-- (find-es "texinfo")
-- (find-angg "LUA/texinfo.lua")
-- (find-dn5 "treesegs.lua")
--
-- This does very little at the moment.


-- «.TexiTree»			(to "TexiTree")
-- «.TOP-NODE-SUBNODES»		(to "TOP-NODE-SUBNODES")
-- «.MYNODE»			(to "MYNODE")
-- «.ANODE»			(to "ANODE")


require "eoo"         -- (find-blogme4 "eoo.lua")
require "def"         -- (find-blogme4 "def.lua")

-- «TexiTree»  (to ".TexiTree")
TexiTree = Class {
  type    = "TexiTree",
  __index = {
    addnode_ = function (texitree, treepos, node)
        node.treepos = treepos
        table.insert(texitree.structure, treepos)
        texitree.nodes[treepos] = node
      end,
    addnode_at = function (texitree, level, node)
        local structure  = texitree.structure
        local last_pos   = structure[#structure]
        local last_level = #last_pos
        if last_level + 1 == level then
          return texitree:addnode_(last_pos.."A", node)
        else
          if last_level + 1 < level then error("Going too deep too fast") end
          local prev_pos = last_pos:sub(1, level)
          local prev_up  = prev_pos:sub(1, -2)
          local prev_cb  = prev_pos:sub(-1):byte()
          local node_pos = prev_up .. string.char(prev_cb + 1)
          return texitree:addnode_(node_pos, node)
        end
      end,
    add_at = function (texitree, level, node)
        if level == 1
        then texitree:addnode_("_", node)
        else texitree:addnode_at(level, node)
        end
      end,
    add_top        = function (texitree, node) texitree:add_at(1, node) end,
    add_chapter    = function (texitree, node) texitree:add_at(2, node) end,
    add_section    = function (texitree, node) texitree:add_at(3, node) end,
    add_subsection = function (texitree, node) texitree:add_at(4, node) end,
    --
    menubody = function (texitree, pos)
        local items = {}
        for ascii=65,126 do
          local subpos = pos..string.char(ascii)
          local node = texitree.nodes[subpos]
          if not node then break end
          local short, long = node.short, node.long
          local left = "* "..short.."::"
          local line = string.format("%-32s%s\n", left, long)
          table.insert(items, line)
        end
        return table.concat(items)
      end,
    menufor = function (texitree, pos)
        local body = texitree:menubody(pos)
        if body ~= "" then return "\n\n@menu\n"..body.."@end menu\n" end
      end,
    --
    up_prev_next = function (texitree, node)
        local pos_this = node.treepos
        local pos_up   = pos_this:sub(1, -2)
        local pos_cb   = pos_this:sub(-1):byte()
        local pos_prev = pos_up .. string.char(pos_cb - 1)
        local pos_next = pos_up .. string.char(pos_cb + 1)
        local up   = texitree.nodes[pos_up]
        local prev = texitree.nodes[pos_prev]
        local next = texitree.nodes[pos_next]
        return up, prev, next
      end,
    node_head = function (texitree, node)
        local up, prev, next = texitree:up_prev_next(node)
        local up_short   = (up   and up.short)   or "(dir)"
        local prev_short = (prev and prev.short) or ""
        local next_short = (next and next.short) or ""
        local short = node.short
        local long  = node.long
        local command = ({"@top", "@chapter", "@section",
          "@subsection", "@subsubsection"})[#node.treepos]
        return string.format(
            "@node %s, %s, %s, %s\n" ..
            "@comment  node-name,  next,  previous,  up\n" ..
            "%s %s",
            short, next_short, prev_short, up_short,
            command, long)
      end,
    node_texi = function (texitree, node)
        local header = texitree:node_head(node)
        local body   = node.body or ""
        return string.format("%s\n%s\n", header, body)
      end,
    nodes_texi = function (texitree)
        local f = function (pos)
            return texitree:node_texi(texitree.nodes[pos])
                .. (texitree:menufor(pos) or "")
          end
        return mapconcat(f, texitree.structure, "\n")
      end,
    head_texi = function (texitree)
        local stem  = texitree.stem or "foo"
        local title = texitree.title or "Foo"
        return "\\input texinfo\n"
            .. "@setfilename "..stem..".info\n"
            .. "@settitle "..title.."\n\n"
      end,
    foot_texi = function (texitree)
        return "\n@bye\n"
      end,
    full_texi = function (texitree)
        return texitree:head_texi()
            .. texitree:nodes_texi()
            .. texitree:foot_texi()
      end,
    print = function (texitree) print(texitree:nodes_texi()) end,
    print = function (texitree) print(texitree:full_texi()) end,
    writefile = function (texitree, fname)
        writefile(fname, texitree:full_texi())
      end,
    --
    srclink_fmt  = '(find-blogme4 "doc/blogme4.b4texi" "%s")',
    infolink_fmt = '(find-node "(blogme4)%s")',
    srclink = function (texitree, anchor)
        return texitree.srclink_fmt:format(anchor)
      end,
    infolink = function (texitree, short)
        return texitree.infolink_fmt:format(short)
      end,
  },
}


-- «TOP-NODE-SUBNODES»  (to ".TOP-NODE-SUBNODES")
Def [[ TOP 3 stem,title,body
       tt = TexiTree {structure={}, nodes={}, stem=stem, title=title}
       tt:add_at(1, {short="Top", long="Top", body=body})
       tt.level = 2
  ]]
Def [[ NODE 3 short,long,body
       tt:add_at(tt.level, {short=short, long=long, body=body})
  ]]
Def [[ SUBNODES nop _
       local oldlevel = tt.level
       tt.level = tt.level + 1
       readvrest()		-- process the body with level=level+1
       tt.level = oldlevel
  ]]


-- «MYNODE»  (to ".MYNODE")
-- (find-texinode "exampleindent")
-- (find-texinode "Quotations and Examples")
-- (find-texinode "Block Enclosing Commands")
-- (find-texinode   "example")
-- (find-texinode   "verbatim")
-- (find-texinode "noindent")
trim   = function (str) return str:match("^(.-)[ \n\t]*$") end
tquote = function (str) return (str:gsub("[{}@]", "@%1")) end
def [[ IE 1 body "\n@example\n" ..tquote(trim(body)).."\n@end example\n" ]]
def [[ LE 1 body "\n@verbatim\n"..tquote(trim(body)).."\n@end verbatim\n" ]]
def [[ IE' 1Q body IE(body) ]]
def [[ LE' 1Q body LE(body) ]]
def [[ NI nop _ "@noindent " ]]

def [[ PRELINK 1 anchor "" ]]
def [[ PRELINK 1 anchor IE("src: "..tt:srclink(anchor).."\n") ]]
Def [[ MYNODE 4 anchor,short,long,body
    print(tt:infolink(short))
    return NODE(short, long, PRELINK(anchor)..body)
  ]]


-- «ANODE»  (to ".ANODE")
-- (find-blogme4 "eval.lua" "parse_pattern")
read_pattern = function (pat)
    if not parse_pattern(pat) then
      print("Failed pattern: "..pat)
      error()
    end
    return result
  end
read_line     = function () return read_pattern("^([^\n]+)\n?()") end
read_line_pat = function (pat) return read_line():match(pat) end
read_anchor   = function () return read_line_pat("«([!-~]+)»") end
read_qstr     = function () return read_line_pat("\"([^\"]*)\"") end
_A["A3"] = function ()
    return read_anchor(), read_qstr(), readvvrest()
  end
def [[ ANODE A3 anchor,short,long,body
         MYNODE(anchor,short,long,body)
  ]]




-- dump-to: tests
test1 = function ()
    tt = TexiTree {structure={}, nodes={}}
    tt:addnode_("_",   {short="Top",      long="Top"})
    tt:addnode_("_A",  {short="Short A",  long="Long A"})
    tt:addnode_("_AA", {short="Short AA", long="Long AA"})
    tt:addnode_("_AB", {short="Short AB", long="Long AB"})
    tt:addnode_("_B",  {short="Short B",  long="Long B"})
    tt:print()
  end

test2 = function ()
    tt = TexiTree {structure={}, nodes={}}
    tt:add_at(1, {short="Top",      long="Top",     body="Top body"})
    tt:add_at(2, {short="Short A",  long="Long A",  body="A body"  })
    tt:add_at(3, {short="Short AA", long="Long AA", body="AA body" })
    tt:add_at(3, {short="Short AB", long="Long AB", body="AB body" })
    tt:add_at(2, {short="Short B",  long="Long B",  body="B body"  })
    tt:print()
  end


-- (find-blogme4 "texinfo.lua")
-- print(trim(" A B \n ").."!")
-- def [[ TEST nop _ PP(read_line(), read_line(), readvvrest()) ]]
-- def [[ TEST nop _ PP(read_anchor(), read_qstr(), readvvrest()) ]]


--[==[
* (eepitch-lua51)
* (eepitch-kill)
* (eepitch-lua51)
require "texinfo"
test1()
test2()

print(tt:menufor("_A"))
print(tt:menufor("_"))

PP(tt)
node = tt.nodes["_A"]
PP(node)
PP(tt:header(node))
PP(tt:nodes_texi())

* (eepitch-lua51)
* (eepitch-kill)
* (eepitch-lua51)
require "texinfo"
require "anggdefs"
tt = TexiTree {structure={}, nodes={}}
def [[ NODE 3 level,short,long,body 
       tt:add_at(level+0, {short=short, long=long, body=body})
  ]]
NODE(1, "Top", "My manual", "topmatter")
NODE(2, "short A",  "long A",  "body A")
NODE(3, "short AA", "long AA", "body AA")
NODE(3, "short AB", "long AB", "body AB")
NODE(2, "short B",  "long B",  "body B")
PP(tt)
tt:print()
* (message (find-sh0 "rm -v /tmp/foo.texi"))
tt:writefile("/tmp/foo.texi")
* (message (find-sh0 "ls -l /tmp/foo.texi"))
-- (find-fline "/tmp/foo.texi")


* (eepitch-lua51)
* (eepitch-kill)
* (eepitch-lua51)
require "texinfo"
test2()
* (message (find-sh0 "rm -v /tmp/foo.texi"))
tt:writefile("/tmp/foo.texi")
* (message (find-sh0 "ls -l /tmp/foo.texi"))
-- (find-fline "/tmp/foo.texi")

* (eepitch-shell)
* (eepitch-kill)
* (eepitch-shell)
cd /tmp/
makeinfo foo.texi
-- (find-fline "/tmp/")
# (find-node "(/tmp/eev)Top")




-- (find-blogme4 "eval.lua" "blogme_eval")
-- (find-blogme4 "eval.lua" "blogme_eval" "return wordf(argpf())")
-- (find-blogme4 "eval.lua" "readqword")
-- (find-blogme4 "eval.lua" "_A")
-- (find-blogme4 "def.lua" "def")
* (eepitch-lua51)
* (eepitch-kill)
* (eepitch-lua51)
require "texinfo"
require "eval"
require "anggdefs"
bev = blogme_eval
pev = function (str) print(blogme_eval(str)) end
pev [[ foo [IT bar] plic ]]

mycount = 0
Def [[ PN  nop _ mycount = mycount+1; print(mycount) ]]
pev [[ [PN] [PN] [PN] ]]

_A["pos"] = function () return pos end
def [[ POS pos pos pos ]]
pev [[ [POS] [POS] [POS] ]]

Def [[ P* pos p
    local mycount_ = mycount
    mycount = mycount*10
    local result = readvrest()
    mycount = mycount_
  ]]
mycount = 0
pev [=[ [PN] [PN] [P* [PN] [PN]] [PN] [PN] ]=]

tt = TexiTree {structure={}, nodes={}, level=1}
Def [[ NODE 3 short,long,body
       tt:add_at(tt.level, {short=short, long=long, body=body})
  ]]
Def [[ SUBNODES pos p
       local oldlevel = tt.level
       tt.level = tt.level + 1
       readvrest()
       tt.level = oldlevel
  ]]

bev [=[
  [NODE [J Top]      [J Top]   Top body]
  [SUBNODES
  [NODE [J Short A]  [J Long A]  A body]
  [SUBNODES
   [NODE [J Short AA] [J Long AA] AA body]
   [NODE [J Short AB] [J Long AB] AB body]
  ]
  [NODE [J Short B]  [J Long B]  B boody]
  ]
]=]
tt:print()


* (eepitch-lua51)
* (eepitch-kill)
* (eepitch-lua51)
require "texinfo"
require "eval"
require "anggdefs"
bev = blogme_eval
pev = function (str) print(blogme_eval(str)) end
pev [[ foo [IT bar] plic ]]
tt = TexiTree {structure={}, nodes={}, level=1}
Def [[ TOP 3 stem,title,body
       tt = TexiTree {structure={}, nodes={}, stem=stem, title=title}
       tt:add_at(1, {short="Top", long="Top", body=body})
       tt.level = 2
  ]]
Def [[ NODE 3 short,long,body
       tt:add_at(tt.level, {short=short, long=long, body=body})
  ]]
Def [[ SUBNODES pos p
       local oldlevel = tt.level
       tt.level = tt.level + 1
       readvrest()
       tt.level = oldlevel
  ]]
bev [=[
  [TOP mystem [J My title]  Top body]
  [NODE [J Short A]  [J Long A]  A body]
  [SUBNODES
   [NODE [J Short AA] [J Long AA] AA body]
   [NODE [J Short AB] [J Long AB] AB body]
  ]
  [NODE [J Short B]  [J Long B]  B boody]
]=]
tt:print()
tt:writefile("/tmp/"..tt.stem..".texi")


--]==]


-- (find-angg "LUA/texinfo.lua" "output")
-- (find-texinode "First Node" "@node Top")
-- (find-texinode "makeinfo top command" "@top Your Manual Title")
-- (find-texinode "Node Menu Illustration")




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