Warning: this is an htmlized version!
The original is here, and the conversion rules are here. |
-- This file: -- http://angg.twu.net/LUA/Lisp3.lua.html -- http://angg.twu.net/LUA/Lisp3.lua -- (find-angg "LUA/Lisp3.lua") -- Author: Eduardo Ochs <eduardoochs@gmail.com> -- -- Parsing lisp with lpegrex, version 3. -- Superseded by: (find-angg "LUA/Lisp4.lua") -- -- (defun l2 () (interactive) (find-angg "LUA/Lisp2.lua")) -- (defun l3 () (interactive) (find-angg "LUA/Lisp3.lua")) -- (defun ll () (interactive) (find-2a '(l3) '(l2))) -- (defun lq () (interactive) (find-lpegrexfile "README.md" "Quick References")) -- (defun lr () (interactive) (find-es "lpeg" "lpegrex")) -- (defun lt () (interactive) (find-es "lpeg" "lpegrex-tag")) -- (defun l () (interactive) (find-es "lpeg" "lpeg-quickref")) -- (defun j () (interactive) (find-es "lpeg" "lpegrex-json")) -- (find-lpegrexgrep "grep --color=auto -nH --null -e options * */*") -- (find-lpegrexgrep "grep --color=auto -nRH --null -e '%cn' * *") -- (find-lpegrexfile "tests/lpegrex-test.lua" "__options={tag=") require "Tree1" -- (find-anggfile "LUA/Tree1.lua") require "lpeg" -- (find-es "lpeg" "lpeg-quickref") loadlpegrex() -- (find-angg "LUA/lua50init.lua" "loadlpegrex") -- Path.prepend("path", "~/usrc/lpeglabel/?.lua") -- Path.prepend("cpath", "~/usrc/lpeglabel/?.so") -- Path.prepend("path", "~/usrc/lpegrex/?.lua") -- lpegrex = require 'lpegrex' lpegrex_compilef = function (patstr, f) return lpegrex.compile(patstr, {__options={tag=f}}) 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[0] == "String" then return expr(ast:body()) end if ast[0] == "Number" then return expr(ast:body()) end -- if ast[0] == "Symbol" then return ast:body()[2] end if ast[0] == "Symbol" then return ast:body() 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 sexp = lpegrex_compilef([[ top <-- skip Element skip <-- hspace (hcomment? linebreak hspace)* hspace <-- [ %ct]* hcomment <-- ';' [^%cn]* linebreak <-- %cn Element <-- Quoted / Number / Symbol / String / List Elements <-- skip (Element skip)* List <== '(' Elements ')' Number <== [0-9]+ Symbol <== symbolchar + symbolchar <-- ![()"\] [!-~] String <== '"' strchar* '"' strchar <-- ('\'.) / (!'"' .) Quoted <== "'" skip Element ]], function (name, node) node[0] = name return Tagged(node) end) --[==[ * (eepitch-lua52) * (eepitch-kill) * (eepitch-lua52) dofile "Lisp3.lua" -- (find-eev "eev-videolinks.el" "more-info") 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[2] = ast[3] = ast[3][1] = ast[3][1][1] = ast[3][1][1]:asvideo() = ast[3][1]:asvideos() vs = ast[3][1]:asvideos() = videos_to_expr(vs) --]==] -- Local Variables: -- coding: utf-8-unix -- End: