Thomas A. Schmitz wrote:
Hi all,
I'm working on my Greek module again and am trying to filter and massage the input via lpeg, but there's something I don't quite get. As a minimal example: suppose I want to substitute A and B in my input with X and leave all other letters alone. Here's my attempt:
brrr ... massaging input ... can be dangerous ... anyhow, here you go \startluacode local replace = { A = "X", B = "X", } setmetatable(replace, { __index = function(t,k) return k end }) local dosub = (lpeg.Cs(1)) / replace local subs = (dosub)^0 function test (string) tex.sprint(lpeg.match(subs,string)) end \stopluacode \def\Substitute#1{\ctxlua{test("#1")}} \starttext \Substitute{thomas ABC whatever} \stoptext and yes, it's slow; the next variant is faster but takes a bit more memory (neglectable compared to what is alrwady taken) setmetatable(replace, { __index = function(t,k) t[k] = k return k end }) ----------------------------------------------------------------- Hans Hagen | PRAGMA ADE Ridderstraat 27 | 8061 GH Hasselt | The Netherlands tel: 038 477 53 69 | fax: 038 477 53 74 | www.pragma-ade.com | www.pragma-pod.nl -----------------------------------------------------------------