diff options
author | Philipp Gesang <phg@phi-gamma.net> | 2015-03-29 11:49:58 +0200 |
---|---|---|
committer | Philipp Gesang <phg@phi-gamma.net> | 2015-03-29 11:49:58 +0200 |
commit | 237d0436d8505bb4263a477022d42c8a291f5b36 (patch) | |
tree | 531e4acebca37b5896dea51634718d3035b57881 /src/fontloader | |
parent | 4a713e7180d2de832a5cd69f4ebf706e927f7032 (diff) | |
download | luaotfload-237d0436d8505bb4263a477022d42c8a291f5b36.tar.gz |
[fontloader] sync with Context as of 2015-03-29
Diffstat (limited to 'src/fontloader')
-rw-r--r-- | src/fontloader/misc/fontloader-l-lpeg.lua | 270 | ||||
-rw-r--r-- | src/fontloader/runtime/fontloader-fontloader.lua | 88 |
2 files changed, 122 insertions, 236 deletions
diff --git a/src/fontloader/misc/fontloader-l-lpeg.lua b/src/fontloader/misc/fontloader-l-lpeg.lua index 0c89706..9225b57 100644 --- a/src/fontloader/misc/fontloader-l-lpeg.lua +++ b/src/fontloader/misc/fontloader-l-lpeg.lua @@ -834,209 +834,45 @@ end -- experiment: --- local function make(t) --- local p --- local keys = sortedkeys(t) --- for i=1,#keys do --- local k = keys[i] --- local v = t[k] --- if not p then --- if next(v) then --- p = P(k) * make(v) --- else --- p = P(k) --- end --- else --- if next(v) then --- p = p + P(k) * make(v) --- else --- p = p + P(k) --- end --- end --- end --- return p --- end - --- local function make(t) --- local p = P(false) --- local keys = sortedkeys(t) --- for i=1,#keys do --- local k = keys[i] --- local v = t[k] --- if next(v) then --- p = p + P(k) * make(v) --- else --- p = p + P(k) --- end --- end --- return p --- end - --- function lpeg.utfchartabletopattern(list) -- goes to util-lpg --- local tree = { } --- for i=1,#list do --- local t = tree --- for c in gmatch(list[i],".") do --- local tc = t[c] --- if not tc then --- tc = { } --- t[c] = tc --- end --- t = tc --- end --- end --- return make(tree) --- end - local p_false = P(false) local p_true = P(true) --- local function make(t,hash) --- local p = p_false --- local keys = sortedkeys(t) --- for i=1,#keys do --- local k = keys[i] --- local v = t[k] --- local h = hash[v] --- if h then --- if next(v) then --- p = p + P(k) * (make(v,hash) + p_true) --- else --- p = p + P(k) * p_true --- end --- else --- if next(v) then --- p = p + P(k) * make(v,hash) --- else --- p = p + P(k) --- end --- end --- end --- return p --- end - --- local function make(t,hash) --- local p = p_false --- local keys = sortedkeys(t) --- local function making(t,w) --- local p = p_false --- local keys = sortedkeys(t) --- for i=1,#keys do --- local k = keys[i] --- local v = t[k] --- if w then --- if next(v) then --- p = p + P(k) * (making(v,w) + p_true) --- else --- p = p + P(k) * p_true --- end --- else --- if next(v) then --- p = p + P(k) * making(v,w) --- else --- p = p + P(k) --- end --- end --- end --- return p --- end --- for i=1,#keys do --- local k = keys[i] --- local v = t[k] --- local h = hash[v] --- if h then --- if next(v) then --- p = p + P(k) * (making(v,true) + p_true) --- else --- p = p + P(k) * p_true --- end --- else --- if next(v) then --- p = p + P(k) * making(v,false) --- else --- p = p + P(k) --- end --- end --- end --- return p --- end --- --- function lpeg.utfchartabletopattern(list) -- goes to util-lpg --- local tree = { } --- local hash = { } --- local n = #list --- if n == 0 then --- for s in next, list do --- local t = tree --- for c in gmatch(s,".") do --- local tc = t[c] --- if not tc then --- tc = { } --- t[c] = tc --- end --- t = tc --- end --- hash[t] = s --- end --- else --- for i=1,n do --- local t = tree --- local s = list[i] --- for c in gmatch(s,".") do --- local tc = t[c] --- if not tc then --- tc = { } --- t[c] = tc --- end --- t = tc --- end --- hash[t] = s --- end --- end --- return make(tree,hash) --- end - - -local function make(t,hash) - local p = p_false - local keys = sortedkeys(t) - local function making(t,w) +local function make(t) + local function making(t) local p = p_false local keys = sortedkeys(t) + local okay = t[""] for i=1,#keys do local k = keys[i] - local v = t[k] - if w then + if k ~= "" then + local v = t[k] if v == true then p = p + P(k) * p_true + elseif v == false then + -- can't happen + elseif okay then + p = p + P(k) * (making(v) + p_true) else - p = p + P(k) * (making(v,w) + p_true) - end - else - if v == true then - p = p + P(k) - else - p = p + P(k) * making(v,w) + p = p + P(k) * making(v) end end end return p end + local p = p_false + local keys = sortedkeys(t) for i=1,#keys do local k = keys[i] - local v = t[k] - local h = hash[v] - if h then + if k ~= "" then + local v = t[k] if v == true then p = p + P(k) * p_true + elseif v == false then + -- can't happen + elseif v[""] then + p = p + P(k) * (making(v) + p_true) else - p = p + P(k) * (making(v,true) + p_true) - end - else - if v == true then - p = p + P(k) - else - p = p + P(k) * making(v,false) + p = p + P(k) * making(v) end end end @@ -1045,61 +881,99 @@ end function lpeg.utfchartabletopattern(list) -- goes to util-lpg local tree = { } --- local hash = { } - local hash local n = #list if n == 0 then - hash = list for s in next, list do local t = tree local p, pk for c in gmatch(s,".") do if t == true then - t = { [c] = true } + t = { [c] = true, [""] = true } + p[pk] = t + p = t + t = false + elseif t == false then + t = { [c] = false } p[pk] = t p = t - t = true + t = false else local tc = t[c] if not tc then - tc = true - t[c] = tc + tc = false + t[c] = false end p = t t = tc end pk = c end + if t == false then + p[pk] = true + elseif t == true then + -- okay + else + t[""] = true + end end else - hash = { } for i=1,n do - local t = tree local s = list[i] + local t = tree local p, pk for c in gmatch(s,".") do if t == true then - t = { [c] = true } + t = { [c] = true, [""] = true } p[pk] = t p = t - t = true + t = false + elseif t == false then + t = { [c] = false } + p[pk] = t + p = t + t = false else local tc = t[c] if not tc then - tc = true - t[c] = true + tc = false + t[c] = false end p = t t = tc end pk = c end - hash[s] = true + if t == false then + p[pk] = true + elseif t == true then + -- okay + else + t[""] = true + end end end - return make(tree,hash) +-- inspect(tree) + return make(tree) end +-- local t = { "a", "abc", "ac", "abe", "abxyz", "xy", "bef" } +-- local p = lpeg.Cs((lpeg.utfchartabletopattern(t)/string.upper + 1)^1) +-- +-- inspect(lpegmatch(p,"a")) +-- inspect(lpegmatch(p,"aaaa")) +-- inspect(lpegmatch(p,"ac")) +-- inspect(lpegmatch(p,"bc")) +-- inspect(lpegmatch(p,"zzbczz")) +-- inspect(lpegmatch(p,"zzabezz")) +-- inspect(lpegmatch(p,"ab")) +-- inspect(lpegmatch(p,"abc")) +-- inspect(lpegmatch(p,"abe")) +-- inspect(lpegmatch(p,"xa")) +-- inspect(lpegmatch(p,"bx")) +-- inspect(lpegmatch(p,"bax")) +-- inspect(lpegmatch(p,"abxyz")) +-- inspect(lpegmatch(p,"foobarbefcrap")) + -- lpeg.utfchartabletopattern { -- utfchar(0x00A0), -- nbsp -- utfchar(0x2000), -- enquad diff --git a/src/fontloader/runtime/fontloader-fontloader.lua b/src/fontloader/runtime/fontloader-fontloader.lua index 0c307c7..b47d49e 100644 --- a/src/fontloader/runtime/fontloader-fontloader.lua +++ b/src/fontloader/runtime/fontloader-fontloader.lua @@ -1,6 +1,6 @@ -- merged file : luatex-fonts-merged.lua -- parent file : luatex-fonts.lua --- merge date : 03/25/15 22:13:54 +-- merge date : 03/28/15 22:37:53 do -- begin closure to overcome local limits and interference @@ -662,46 +662,40 @@ function lpeg.append(list,pp,delayed,checked) end local p_false=P(false) local p_true=P(true) -local function make(t,hash) - local p=p_false - local keys=sortedkeys(t) - local function making(t,w) +local function make(t) + local function making(t) local p=p_false local keys=sortedkeys(t) + local okay=t[""] for i=1,#keys do local k=keys[i] - local v=t[k] - if w then + if k~="" then + local v=t[k] if v==true then p=p+P(k)*p_true + elseif v==false then + elseif okay then + p=p+P(k)*(making(v)+p_true) else - p=p+P(k)*(making(v,w)+p_true) - end - else - if v==true then - p=p+P(k) - else - p=p+P(k)*making(v,w) + p=p+P(k)*making(v) end end end return p end + local p=p_false + local keys=sortedkeys(t) for i=1,#keys do local k=keys[i] - local v=t[k] - local h=hash[v] - if h then + if k~="" then + local v=t[k] if v==true then p=p+P(k)*p_true + elseif v==false then + elseif v[""] then + p=p+P(k)*(making(v)+p_true) else - p=p+P(k)*(making(v,true)+p_true) - end - else - if v==true then - p=p+P(k) - else - p=p+P(k)*making(v,false) + p=p+P(k)*making(v) end end end @@ -709,58 +703,76 @@ local function make(t,hash) end function lpeg.utfchartabletopattern(list) local tree={} - local hash local n=#list if n==0 then - hash=list for s in next,list do local t=tree local p,pk for c in gmatch(s,".") do if t==true then - t={ [c]=true } + t={ [c]=true,[""]=true } + p[pk]=t + p=t + t=false + elseif t==false then + t={ [c]=false } p[pk]=t p=t - t=true + t=false else local tc=t[c] if not tc then - tc=true - t[c]=tc + tc=false + t[c]=false end p=t t=tc end pk=c end + if t==false then + p[pk]=true + elseif t==true then + else + t[""]=true + end end else - hash={} for i=1,n do - local t=tree local s=list[i] + local t=tree local p,pk for c in gmatch(s,".") do if t==true then - t={ [c]=true } + t={ [c]=true,[""]=true } + p[pk]=t + p=t + t=false + elseif t==false then + t={ [c]=false } p[pk]=t p=t - t=true + t=false else local tc=t[c] if not tc then - tc=true - t[c]=true + tc=false + t[c]=false end p=t t=tc end pk=c end - hash[s]=true + if t==false then + p[pk]=true + elseif t==true then + else + t[""]=true + end end end - return make(tree,hash) + return make(tree) end patterns.containseol=lpeg.finder(eol) local function nextstep(n,step,result) |