From 5b9683a8f29dd473e17502aa1746a6bcc3036fe3 Mon Sep 17 00:00:00 2001 From: Hans Hagen Date: Sun, 19 Nov 2017 21:16:29 +0100 Subject: 2017-11-19 20:20:00 --- tex/context/base/mkiv/lang-rep.lua | 37 ++++++++++++++++++++++++------------- 1 file changed, 24 insertions(+), 13 deletions(-) (limited to 'tex/context/base/mkiv/lang-rep.lua') diff --git a/tex/context/base/mkiv/lang-rep.lua b/tex/context/base/mkiv/lang-rep.lua index a09574ef4..d4d16f6a3 100644 --- a/tex/context/base/mkiv/lang-rep.lua +++ b/tex/context/base/mkiv/lang-rep.lua @@ -77,6 +77,9 @@ local v_reset = interfaces.variables.reset local implement = interfaces.implement +local processors = typesetters.processors +local splitprocessor = processors.split + local replacements = languages.replacements or { } languages.replacements = replacements @@ -102,7 +105,8 @@ lists[v_reset].attribute = unsetvalue -- so we discard 0 -- todo: glue kern attr local function add(root,word,replacement) - local replacement = lpegmatch(stripper,replacement) or replacement + local processor, replacement = splitprocessor(replacement,true) -- no check + replacement = lpegmatch(stripper,replacement) or replacement local list = utfsplit(word,true) local size = #list for i=1,size do @@ -111,16 +115,12 @@ local function add(root,word,replacement) root[l] = { } end if i == size then - -- local newlist = utfsplit(replacement,true) - -- for i=1,#newlist do - -- newlist[i] = utfbyte(newlist[i]) - -- end local special = find(replacement,"{",1,true) local newlist = lpegmatch(splitter,replacement) - -- root[l].final = { word = word, replacement = replacement, + processor = processor, oldlength = size, newcodes = newlist, special = special, @@ -170,7 +170,10 @@ local function hit(a,head) local lastrun = false local lastfinal = false while current do - local char = isglyph(current) + local char, id = isglyph(current) + -- if not char and id == glue_code then + -- char = " " -- if needed we can also deal with spaces and special nbsp and such + -- end if char then local newroot = root[char] if not newroot then @@ -213,20 +216,21 @@ local function tonodes(list,template) return head end - function replacements.handler(head) head = tonut(head) - local current = head - local done = false + local current = head + local done = false + local overload = attributes.applyoverloads while current do if getid(current) == glyph_code then local a = getattr(current,a_replacements) if a then local last, final = hit(a,current) if last then - local oldlength = final.oldlength - local newcodes = final.newcodes - local newlength = #newcodes + local precurrent = getprev(current) or head + local oldlength = final.oldlength + local newcodes = final.newcodes + local newlength = newcodes and #newcodes or 0 if trace_replacement then report_replacement("replacing word %a by %a",final.word,final.replacement) end @@ -288,6 +292,9 @@ function replacements.handler(head) i = i + 1 end flush_list(list) + elseif newlength == 0 then + -- nothing gets replaced + current = getnext(last) elseif oldlength == newlength then -- #old == #new if final.word == final.replacement then -- nothing to do but skip @@ -317,10 +324,14 @@ function replacements.handler(head) current = getnext(current) end end + if overload then + overload(final,getnext(precurrent),getprev(current)) + end done = true end end end + -- we're one ahead now but we need to because we handle words current = getnext(current) end return tonode(head), done -- cgit v1.2.3