1if not modules then modules = { } end modules ['toks-map'] = { 2 version = 1.001, 3 author = "Hans Hagen, PRAGMA-ADE, Hasselt NL", 4 copyright = "PRAGMA ADE / ConTeXt Development Team", 5 license = "see context related readme files" 6} 7 8-- Even more experimental ... this used to be part of toks-ini but as 9-- this kind of remapping has not much use it is not loaded in the 10-- core. We just keep it here for old times sake. 11 12-- local remapper = { } -- namespace 13-- collectors.remapper = remapper 14-- 15-- local remapperdata = { } -- user mappings 16-- remapper.data = remapperdata 17-- 18-- function remapper.store(tag,class,key) 19-- local s = remapperdata[class] 20-- if not s then 21-- s = { } 22-- remapperdata[class] = s 23-- end 24-- s[key] = collectordata[tag] 25-- collectordata[tag] = nil 26-- end 27-- 28-- function remapper.convert(tag,toks) 29-- local data = remapperdata[tag] 30-- local leftbracket = utfbyte('[') 31-- local rightbracket = utfbyte(']') 32-- local skipping = 0 33-- -- todo: math 34-- if data then 35-- local t, n = { }, 0 36-- for s=1,#toks do 37-- local tok = toks[s] 38-- local one, two = tok[1], tok[2] 39-- if one == 11 or one == 12 then 40-- if two == leftbracket then 41-- skipping = skipping + 1 42-- n = n + 1 ; t[n] = tok 43-- elseif two == rightbracket then 44-- skipping = skipping - 1 45-- n = n + 1 ; t[n] = tok 46-- elseif skipping == 0 then 47-- local new = data[two] 48-- if new then 49-- if #new > 1 then 50-- for n=1,#new do 51-- n = n + 1 ; t[n] = new[n] 52-- end 53-- else 54-- n = n + 1 ; t[n] = new[1] 55-- end 56-- else 57-- n = n + 1 ; t[n] = tok 58-- end 59-- else 60-- n = n + 1 ; t[n] = tok 61-- end 62-- else 63-- n = n + 1 ; t[n] = tok 64-- end 65-- end 66-- return t 67-- else 68-- return toks 69-- end 70-- end 71 |