Warning: this is an htmlized version!
The original is here, and the conversion rules are here. |
-- This file: -- http://anggtwu.net/LUA/DeleteComments3.lua.html -- http://anggtwu.net/LUA/DeleteComments3.lua -- (find-angg "LUA/DeleteComments3.lua") -- Author: Eduardo Ochs <eduardoochs@gmail.com> -- -- (defun e () (interactive) (find-angg "LUA/DeleteComments3.lua")) -- Supersedes: (find-angg "LUA/DeleteComments1.lua") -- (find-angg "LUA/DeleteComments2.lua") -- -- Note that this does not convert double newlines into "\par"s! -- See: (find-es "luatex" "3-questions-about-tex-print") -- https://tug.org/pipermail/luatex/2024-September/008002.html -- (find-angg "LUA/ELpeg1.lua" "globals") lpeg = lpeg or require "lpeg" local B,C,P,R,S,V = lpeg.B,lpeg.C,lpeg.P,lpeg.R,lpeg.S,lpeg.V local Cb,Cc,Cf,Cg = lpeg.Cb,lpeg.Cc,lpeg.Cf,lpeg.Cg local Cp,Cs,Ct = lpeg.Cp,lpeg.Cs,lpeg.Ct local Carg,Cmt = lpeg.Carg,lpeg.Cmt require "Gram4" -- (find-angg "LUA/Gram4.lua") local gr,V = Gram4.new() V.PR1 = P"%" * (1-S"\n")^0 -- a percent and everything at its right V.NS1 = "\n" * (S" \t")^0 -- a newline and the spaces following it V.PR2 = V.PR1 * V.NS2^-1 -- recurse starting from PR1 V.NS2 = V.NS1 * V.PR2^-1 -- recurse starting from NS1 V.comment = V.PR2 V.commentspc = V.comment / " " -- comment, replaced by a single space V.commentdel = V.comment / "" -- comment, deleted V.bperc = P"\\%" -- backslack percent V.bname = P"\\"*R("AZ","az")^1 -- backslash name V.bnamespc = P"\\"*R("AZ","az")^1 * V.commentspc^-1 -- backslash name space V.unit = V.bperc + V.bnamespc + V.commentdel + P(1) V.delcomments = (V.unit^0):Cs() deletecomments_pat = gr:compile("delcomments") deletecomments = function (bigstr) return deletecomments_pat:match(bigstr) end --[[ * (eepitch-lua51) * (eepitch-kill) * (eepitch-lua51) dofile "DeleteComments3.lua" = deletecomments( "%foo\n %plic\n ploc") = deletecomments("blergh%foo\n %plic\n ploc") = deletecomments("b\\rgh%foo\n %plic\n ploc") --]] -- Local Variables: -- coding: utf-8-unix -- End: