diff options
Diffstat (limited to 'Master/texmf-dist/tex/context/base/node-ini.lua')
-rw-r--r-- | Master/texmf-dist/tex/context/base/node-ini.lua | 303 |
1 files changed, 222 insertions, 81 deletions
diff --git a/Master/texmf-dist/tex/context/base/node-ini.lua b/Master/texmf-dist/tex/context/base/node-ini.lua index 36e240238e3..eb70fa6e6d1 100644 --- a/Master/texmf-dist/tex/context/base/node-ini.lua +++ b/Master/texmf-dist/tex/context/base/node-ini.lua @@ -15,55 +15,11 @@ modules.</p> local utf = unicode.utf8 local next, type = next, type -local format, concat, match, utfchar = string.format, table.concat, string.match, utf.char - -local chardata = characters and characters.data - ---[[ldx-- -<p>We start with a registration system for atributes so that we can use the -symbolic names later on.</p> ---ldx]]-- - -attributes = attributes or { } - -attributes.names = attributes.names or { } -attributes.numbers = attributes.numbers or { } -attributes.list = attributes.list or { } -attributes.unsetvalue = -0x7FFFFFFF - -storage.register("attributes/names", attributes.names, "attributes.names") -storage.register("attributes/numbers", attributes.numbers, "attributes.numbers") -storage.register("attributes/list", attributes.list, "attributes.list") - -local names, numbers, list = attributes.names, attributes.numbers, attributes.list - -function attributes.define(name,number) -- at the tex end - if not numbers[name] then - numbers[name], names[number], list[number] = number, name, { } - end -end - ---[[ldx-- -<p>We can use the attributes in the range 127-255 (outside user space). These -are only used when no attribute is set at the \TEX\ end which normally -happens in <l n='context'/>.</p> ---ldx]]-- - -storage.shared.attributes_last_private = storage.shared.attributes_last_private or 127 - -function attributes.private(name) -- at the lua end (hidden from user) - local number = numbers[name] - if not number then - local last = storage.shared.attributes_last_private or 127 - if last < 255 then - last = last + 1 - storage.shared.attributes_last_private = last - end - number = last - numbers[name], names[number], list[number] = number, name, { } - end - return number -end +local format, concat, match, gsub = string.format, table.concat, string.match, string.gsub +local utfchar = utf.char +local swapped = table.swapped +local lpegmatch = lpeg.match +local formatcolumns = utilities.formatters.formatcolumns --[[ldx-- <p>Access to nodes is what gives <l n='luatex'/> its power. Here we @@ -98,39 +54,226 @@ into the <l n='tex'/> engine, but this is a not so natural extension.</p> also ignore the empty nodes. [This is obsolete!]</p> --ldx]]-- -nodes = nodes or { } - -local hlist = node.id('hlist') -local vlist = node.id('vlist') -local glyph = node.id('glyph') -local glue = node.id('glue') -local penalty = node.id('penalty') -local kern = node.id('kern') -local whatsit = node.id('whatsit') - -local traverse_id = node.traverse_id local traverse = node.traverse +local traverse_id = node.traverse_id local free_node = node.free local remove_node = node.remove local insert_node_before = node.insert_before local insert_node_after = node.insert_after +local node_fields = node.fields + +local allocate = utilities.storage.allocate + +nodes = nodes or { } +local nodes = nodes + +nodes.handlers = nodes.handlers or { } + +-- there will be more of this: + +local skipcodes = allocate { + [ 0] = "userskip", + [ 1] = "lineskip", + [ 2] = "baselineskip", + [ 3] = "parskip", + [ 4] = "abovedisplayskip", + [ 5] = "belowdisplayskip", + [ 6] = "abovedisplayshortskip", + [ 7] = "belowdisplayshortskip", + [ 8] = "leftskip", + [ 9] = "rightskip", + [10] = "topskip", + [11] = "splittopskip", + [12] = "tabskip", + [13] = "spaceskip", + [14] = "xspaceskip", + [15] = "parfillskip", + [16] = "thinmuskip", + [17] = "medmuskip", + [18] = "thickmuskip", +} + +local noadcodes = allocate { + [ 0] = "ord", + [ 1] = "opdisplaylimits", + [ 2] = "oplimits", + [ 3] = "opnolimits", + [ 4] = "bin", + [ 5] = "rel", + [ 6] = "open", + [ 7] = "close", + [ 8] = "punct", + [ 9] = "inner", + [10] = "under", + [11] = "over", + [12] = "vcenter", +} + +local listcodes = allocate { + [ 0] = "unknown", + [ 1] = "line", + [ 2] = "box", + [ 3] = "indent", + [ 4] = "alignment", -- row or column + [ 5] = "cell", +} + +local glyphcodes = allocate { + [0] = "character", + [1] = "glyph", + [2] = "ligature", + [3] = "ghost", + [4] = "left", + [5] = "right", +} + +local kerncodes = allocate { + [0] = "fontkern", + [1] = "userkern", + [2] = "accentkern", +} + +local mathcodes = allocate { + [0] = "beginmath", + [1] = "endmath", +} -function nodes.remove(head, current, free_too) +local fillcodes = allocate { + [0] = "stretch", + [1] = "fi", + [2] = "fil", + [3] = "fill", + [4] = "filll", +} + +local function simplified(t) + local r = { } + for k, v in next, t do + r[k] = gsub(v,"_","") + end + return r +end + +local nodecodes = simplified(node.types()) +local whatcodes = simplified(node.whatsits()) + +skipcodes = allocate(swapped(skipcodes, skipcodes )) +noadcodes = allocate(swapped(noadcodes, noadcodes )) +nodecodes = allocate(swapped(nodecodes, nodecodes )) +whatcodes = allocate(swapped(whatcodes, whatcodes )) +listcodes = allocate(swapped(listcodes, listcodes )) +glyphcodes = allocate(swapped(glyphcodes,glyphcodes)) +kerncodes = allocate(swapped(kerncodes, kerncodes )) +mathcodes = allocate(swapped(mathcodes, mathcodes )) +fillcodes = allocate(swapped(fillcodes, fillcodes )) + +nodes.skipcodes = skipcodes nodes.gluecodes = skipcodes -- more official +nodes.noadcodes = noadcodes +nodes.nodecodes = nodecodes +nodes.whatcodes = whatcodes nodes.whatsitcodes = whatcodes -- more official +nodes.listcodes = listcodes +nodes.glyphcodes = glyphcodes +nodes.kerncodes = kerncodes +nodes.mathcodes = mathcodes +nodes.fillcodes = fillcodes + +listcodes.row = listcodes.alignment +listcodes.column = listcodes.alignment + +kerncodes.italiccorrection = kerncodes.userkern +kerncodes.kerning = kerncodes.fontkern + +nodes.codes = allocate { + hlist = listcodes, + vlist = listcodes, + glyph = glyphcodes, + glue = skipcodes, + kern = kerncodes, + whatsit = whatcodes, + math = mathnodes, + noad = noadcodes, +} + +function nodes.showcodes() + local t = { } + for name, codes in table.sortedhash(nodes.codes) do + local sorted = table.sortedkeys(codes) + for i=1,#sorted do + local s = sorted[i] + if type(s) ~= "number" then + t[#t+1] = { name, s, codes[s] } + end + end + end + formatcolumns(t) + for k=1,#t do + texio.write_nl(t[k]) + end +end + +local whatsit_node = nodecodes.whatsit + +local messyhack = table.tohash { -- temporary solution + nodecodes.attributelist, + nodecodes.attribute, + nodecodes.gluespec, + nodecodes.action, +} + +function nodes.fields(n) + local id = n.id + if id == whatsit_node then + return node_fields(id,n.subtype) + else + local t = node_fields(id) + if messyhack[id] then + for i=1,#t do + if t[i] == "subtype" then + table.remove(t,i) + break + end + end + end + return t + end +end + +trackers.register("system.showcodes", nodes.showcodes) + +local hlist_code = nodecodes.hlist +local vlist_code = nodecodes.vlist +local glue_code = nodecodes.glue + +--~ if t.id == glue_code then +--~ local s = t.spec +--~ print(t) +--~ print(s,s and s.writable) +--~ if s and s.writable then +--~ free_node(s) +--~ end +--~ t.spec = nil +--~ end + +local function remove(head, current, free_too) local t = current +--~ print(t) head, current = remove_node(head,current) if t then if free_too then free_node(t) t = nil else - t.next, t.prev = nil, nil + t.next = nil + t.prev = nil end end return head, current, t end +nodes.remove = remove + function nodes.delete(head,current) - return nodes.remove(head,current,true) + return remove(head,current,true) end nodes.before = insert_node_before @@ -184,10 +327,12 @@ function nodes.replace(head,current,new) -- no head returned if false end local prev, next = current.prev, current.next if next then - new.next, next.prev = next, new + new.next = next + next.prev = new end if prev then - new.prev, prev.next = prev, new + new.prev = prev + prev.next = new end if head then if head == current then @@ -207,7 +352,7 @@ local function count(stack,flat) local n = 0 while stack do local id = stack.id - if not flat and id == hlist or id == vlist then + if not flat and id == hlist_code or id == vlist_code then local list = stack.list if list then n = n + 1 + count(list) -- self counts too @@ -224,21 +369,17 @@ end nodes.count = count --- new, will move - -function attributes.ofnode(n) - local a = n.attr - if a then - local names = attributes.names - a = a.next - while a do - local number, value = a.number, a.value - texio.write_nl(format("%s : attribute %3i, value %4i, name %s",tostring(n),number,value,names[number] or '?')) - a = a.next - end - end +local left, space = lpeg.P("<"), lpeg.P(" ") + +local reference = left * (1-left)^0 * left * space^0 * lpeg.C((1-space)^0) + +function nodes.reference(n) + return lpegmatch(reference,tostring(n)) end -local left, space = lpeg.P("<"), lpeg.P(" ") +if not node.next then -nodes.filterkey = left * (1-left)^0 * left * space^0 * lpeg.C((1-space)^0) + function node.next(n) return n and n.next end + function node.prev(n) return n and n.prev end + +end |