Warning: this is an htmlized version!
The original is here, and
the conversion rules are here.
-- This file:
--   http://angg.twu.net/LUA/Lisp2.lua.html
--   http://angg.twu.net/LUA/Lisp2.lua
--           (find-angg "LUA/Lisp2.lua")
-- Author: Eduardo Ochs <eduardoochs@gmail.com>
--
-- (defun e () (interactive) (find-angg "LUA/Lisp2.lua"))
-- (defun o () (interactive) (find-angg "LUA/Lisp1.lua"))
-- (defun eo () (interactive) (find-2a '(e) (o)))
-- (defun l () (interactive) (find-es "lpeg" "lpeg-quickref"))
-- (defun j () (interactive) (find-es "lpeg" "lpegrex-json"))

-- Usage:
-- This test block:
--   (to "write-sandwiches-videos")
-- generated this file,
--   (find-angg "blogme3/sandwiches-videos.lua")
-- that is used by:
--   (find-blogme3grep "grep --color=auto -nH --null -e sandwiches-videos *.lua")

-- «.write-sandwiches-videos»	(to "write-sandwiches-videos")

require "Tree1"    -- (find-anggfile "LUA/Tree1.lua")
require "lpeg"     -- (find-es "lpeg" "lpeg-quickref")

B,C,P,R,S,V = lpeg.B,lpeg.C,lpeg.P,lpeg.R,lpeg.S,lpeg.V
Cb,Cc,Cf,Cg = lpeg.Cb,lpeg.Cc,lpeg.Cf,lpeg.Cg
Cp,Cs,Ct    = lpeg.Cp,lpeg.Cs,lpeg.Ct
Carg,Cmt    = lpeg.Carg,lpeg.Cmt

packlist = function (a, ...)
    if type(a) == "string" then return Tree {[0]=a, ...} end
    return Tree {a, ...}
  end

Tagged = Class {
  type    = "Tagged",
  __tostring = function (tgd) return tgd:abody() end,
  __index = {
    body = function (tgd)
        return subj:sub(tgd.pos, tgd.endpos-1)
      end,
    abody = function (tgd) return "<"..tgd:body()..">" end,
    value = function (ast)
        if ast.tag == "string" then return expr(ast:body()) end
        if ast.tag == "symbol" then return ast:body():sub(2) end
      end,
    asvideo = function (ast)
        local id = ast[1]:value()
        local A = {}
        for i=2,#ast-1,2 do
          local key,val = ast[i]:value(), ast[i+1]:value()
          A[key] = val
        end
        return id,A
      end,
    asvideos = function (ast)
        local B = {}
        for i=1,#ast do
          local id,A = ast[i]:asvideo()
          B[id] = A
        end
        return B
      end,
  },
}

videos_to_expr = function (B)
    local f,g,h,m,n
    f = function (str) return format("[%q]", str) end
    g = function (key,val) return format("    %-11s = %q,\n", f(key), val) end
    h = function (A)
        local fg = function (key) return g(key, A[key]) end
        return mapconcat(fg, sorted(keys(A)), "")
      end
    m = function (id,A) return format("  %s = {\n%s  },", f(id), h(A)) end
    n = function (B)
        local mk = function (key) return m(key, B[key]) end
        return "{\n"..mapconcat(mk, sorted(keys(B)), "\n").."\n}"
      end
    return n(B)
  end

tagged = function (name, patt)
    return Ct(Cg(Cc(name),"tag")
            * Cg(Cp(),"pos")
            * patt 
            * Cg(Cp(),"endpos"))
         / function (o) return Tagged(o) end
  end

sexp = P({
  "top",
  --
  hspaces    = S(" \t\n")^0,
  comment    = ";" * (1-P("\n"))^0 * "\n", 
  skip       = V("hspaces") * (V("comment") * V("hspaces"))^0,
  --
  symbolchar = R("!~") - S([[()"\]]),
  symbol     = tagged("symbol", V("symbolchar")^1),
  --
  strchar    = ('\\'*P(1)) + (P(1)-'"'),
  str        = tagged("string", '"' * V("strchar")^0 * '"'),
  --
  element    = V("symbol") + V("str") + V("list"),
  elements   = V("skip") * (V("element") * V("skip"))^0,
  list       = tagged("list", "(" * V("elements") * ")"),
  --
  top        = V("skip") * V("element"),
})


--[==[
* (eepitch-lua51)
* (eepitch-kill)
* (eepitch-lua51)
dofile "Lisp2.lua"

subj = [[  ((MLIST SIMP) $X "foo \" bar" $Z)  ]]
ast = sexp:match(subj)
= ast
= ast[1]
= ast[1][2]
= ast[3]
PPPV(ast)

# (find-eevfile "eev-videolinks.el" "(defvar ee-1stclassvideos-info")

* (eepitch-lua51)
* (eepitch-kill)
* (eepitch-lua51)
dofile "Lisp2.lua"
bigstr = ee_readfile "~/eev-current/eev-videolinks.el"
pos = bigstr:match "()%(defvar ee%-1stclassvideos%-info"
= pos
subj = bigstr
ast = sexp:match(subj, pos)
= ast
= ast[1]
= ast[3]
= ast[4]
= ast[4][1]
= ast[4][1][1]
= ast[4][1][2]
=       ast[4][1][3]
=       ast[4][1][2].tag
=       ast[4][1][3].tag
=       ast[4][1][2]:value()
=       ast[4][1][3]:value()
= otype(ast[4][1][3])
=       ast[4][1][3]:body()
=  expr(ast[4][1][3]:body())
= ast[4][1][3])

PP(ast[4][1]:asvideo())
PPV(ast[4]:asvideos())

videos = ast[4]:asvideos()
PPV(videos)
PPV(keys(videos))
PPV(sorted(keys(videos)))

videos_e = videos_to_expr(videos)
= videos_e
= expr(videos_e)
PPPV(expr(videos_e)["eev2019"])

--]==]


-- «write-sandwiches-videos»  (to ".write-sandwiches-videos")
--[[
* (eepitch-lua51)
* (eepitch-kill)
* (eepitch-lua51)
dofile "Lisp2.lua"
bigstr = ee_readfile "~/eev-current/eev-videolinks.el"
pos = bigstr:match "()%(defvar ee%-1stclassvideos%-info"
= pos
subj = bigstr
ast = sexp:match(subj, pos)
videos = ast[4]:asvideos()
videos_expr0 = videos_to_expr(videos)
videos_expr  = '-- Generated by:\n' ..
               '-- (find-angg "LUA/Lisp2.lua" "write-sandwiches-videos")\n' ..
               'sandwiches_videos = '..
               videos_expr0
= videos_expr

* (find-sh0 "rm -v ~/blogme3/sandwiches-videos.lua")
ee_writefile(     "~/blogme3/sandwiches-videos.lua", videos_expr)
-- (find-fline    "~/blogme3/sandwiches-videos.lua")

--]]




-- Local Variables:
-- coding:  utf-8-unix
-- End: