-- This file: -- https://anggtwu.net/LUA/OiHeader1.lua.html -- https://anggtwu.net/LUA/OiHeader1.lua -- (find-angg "LUA/OiHeader1.lua") -- Author: Eduardo Ochs -- -- (defun e () (interactive) (find-angg "LUA/OiHeader1.lua")) -- (defun o () (interactive) (find-angg "LUA/OiReginaldo1.lua")) -- (find-angg ".emacs" "oiheader") -- (find-LATEX "2022-2-C2-C3-ajuda.tex" "2022-500-linhas-etel") Path.addLUAtopath() require "ELpeg1" -- (find-angg "LUA/ELpeg1.lua") gr,V,VA,VE,PE = Gram.new() foosp = function (pat) return pat * (" " * pat)^0 end foocomma = function (pat) return pat * (", " * pat)^0 end V.basicname = foosp((1-S' ,:<>""')^1):C() V.qname = '"' * V.basicname * '"' V.angname = '<' * V.basicname * '>' V.Lname = V.basicname + V.qname V.optangname = (" " * V.angname)^-1 V.Name = (V.Lname * V.optangname + V.angname) / 1 V.names = V.Name * (P", ":C() * V.Name)^0 V.Names = V.names:Ct() / table.concat V.dateword = (R"AZ" + R"az" + R"09" + ":" + "à")^1 V.datewords = foosp(V.dateword) V.Date = (P" "^2 * V.datewords:Cs()) / "[Date:] %1" -- V.Date = (Cc("[Date:] ") * V.date):Cs() V.From = V.Name / "[From:] %1" V.FromDate = (V.From * V.Date) V.FromDate = (V.From * V.Date):Ct() V.FromDate = (V.From * V.Date) / "%1\n%2" V.Other = ((R"AZ" * R"az"^1 * ":"):C() * " " * V.Names) / "[%1] %2" f = function (bigstr) local lines = map(bitrim, splitlines(bigstr)) local g = function (name,subj) return gr:cm0(name, subj) or subj end local out = {g("FromDate", lines[1])} for i=2,#lines do table.insert(out, g("Other", lines[i])) end return table.concat(out, "\n") end argv = {...} if argv[1] == "-from" then print(f(bitrim(argv[2]))) end --[==[  (eepitch-lua51)  (eepitch-kill)  (eepitch-lua51) dofile "OiHeader1.lua" grcm("Names", "Edx Ox") grcm("Names", "Edx Ox, Ab Cd, \"Ef Gh\" , ") grcm("Date", " 12 jan 2003") grcm("Date", " 12 jan 2003") grcm("FromDate", "Edrx Ox 12 jan 2003") = gr:cm("FromDate", "Edrx Ox 12 jan 2003") = gr:cm0("FromDate", "Edrx Ox 12 jan 2003") PPV(gr:cm0("FromDate", "Edrx Ox 12 jan 2003")) grcm("Other", "To: Edx Ox, Ab Cd, \"Ef Gh\" , ") bs = [[ Edrx Ox 12 jan 2003 To: Edx Ox, Ab Cd, "Ef Gh" , ]] = f(bs) = bitrim("\n \n\tfoo bar\n\n")  (eepitch-shell)  (eepitch-kill)  (eepitch-shell) lua51 ~/LUA/OiHeader1.lua -from bla lua51 ~/LUA/OiHeader1.lua -from ' Edrx Ox 12 jan 2003 To: Edx Ox, Ab Cd, "Ef Gh" , ' (defun oiheader0 (bigstr) (find-callprocess0 `("lua5.1" "~/LUA/OiHeader1.lua" "-from" ,bigstr))) (defun oiheader () (interactive) (kill-region (point) (mark)) (insert (oiheader0 (ee-last-kill)) "\n")) ;; (oiheader0 "Ed Ox 12 jan 2003\nTo: Ex Ox, \"Ef Gh\" , ") program-and-args &rest pos-spec-list) --]==] -- Local Variables: -- coding: utf-8-unix -- End: