summaryrefslogtreecommitdiff
path: root/tex/context/base/mkiv/lang-rep.lua
diff options
context:
space:
mode:
authorHans Hagen <pragma@wxs.nl>2017-11-19 21:16:29 +0100
committerContext Git Mirror Bot <phg42.2a@gmail.com>2017-11-19 21:16:29 +0100
commit5b9683a8f29dd473e17502aa1746a6bcc3036fe3 (patch)
treeeaae6dd20452c0f09a569fe1c849a480f2060440 /tex/context/base/mkiv/lang-rep.lua
parentd3ddabbb5b5f45bac3da8cb51d3e63810aa2d4ca (diff)
downloadcontext-5b9683a8f29dd473e17502aa1746a6bcc3036fe3.tar.gz
2017-11-19 20:20:00
Diffstat (limited to 'tex/context/base/mkiv/lang-rep.lua')
-rw-r--r--tex/context/base/mkiv/lang-rep.lua37
1 files changed, 24 insertions, 13 deletions
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