diff options
Diffstat (limited to 'Master/texmf-dist/tex/context/base/node-ser.lua')
-rw-r--r-- | Master/texmf-dist/tex/context/base/node-ser.lua | 99 |
1 files changed, 78 insertions, 21 deletions
diff --git a/Master/texmf-dist/tex/context/base/node-ser.lua b/Master/texmf-dist/tex/context/base/node-ser.lua index b0a6e9952aa..d7593cec748 100644 --- a/Master/texmf-dist/tex/context/base/node-ser.lua +++ b/Master/texmf-dist/tex/context/base/node-ser.lua @@ -9,24 +9,37 @@ if not modules then modules = { } end modules ['node-ser'] = { -- beware, some field names will change in a next releases -- of luatex; this is pretty old code that needs an overhaul -local type, format, rep = type, string.format, string.rep +local type = type local concat, tohash, sortedkeys, printtable = table.concat, table.tohash, table.sortedkeys, table.print +local formatters, format, rep = string.formatters, string.format, string.rep local allocate = utilities.storage.allocate -local nodes, node = nodes, node +local context = context +local nodes = nodes +local node = node -local traverse = node.traverse -local is_node = node.is_node +local traverse = nodes.traverse +local is_node = nodes.is_node local nodecodes = nodes.nodecodes +local subtcodes = nodes.codes local noadcodes = nodes.noadcodes -local nodefields = nodes.fields +local getfields = nodes.fields + +local tonode = nodes.tonode local hlist_code = nodecodes.hlist local vlist_code = nodecodes.vlist +----- utfchar = utf.char +local f_char = formatters["%U"] +----- fontchars = { } table.setmetatableindex(fontchars,function(t,k) fontchars = fonts.hashes.characters return fontchars[k] end) + +----- f_char = utilities.strings.chkuni -- formatters["%!chkuni!"] + local expand = allocate ( tohash { + -- text: "list", -- list_ptr & ins_ptr & adjust_ptr "pre", -- "post", -- @@ -42,6 +55,23 @@ local expand = allocate ( tohash { "action", -- action_ptr "value", -- user_defined nodes with subtype 'a' en 'n' "head", + -- math: + "nucleus", + "sup", + "sub", + "list", + "num", + "denom", + "left", + "right", + "display", + "text", + "script", + "scriptscript", + "delim", + "degree", + "accent", + "bot_accent", } ) -- page_insert: "height", "last_ins_ptr", "best_ins_ptr" @@ -72,8 +102,9 @@ nodes.ignorablefields = ignore -- not ok yet: -local function astable(n,sparse) -- not yet ok - local f, t = nodefields(n), { } +local function astable(n,sparse) -- not yet ok, might get obsolete anyway + n = tonode(n) + local f, t = getfields(n), { } for i=1,#f do local v = f[i] local d = n[v] @@ -101,10 +132,9 @@ setinspector(function(v) if is_node(v) then printtable(astable(v),tostring(v)) r -- under construction: -local function totable(n,flat,verbose,noattributes) - -- todo: no local function +local function totable(n,flat,verbose,noattributes) -- nicest: n,true,true,true local function to_table(n,flat,verbose,noattributes) -- no need to pass - local f = nodefields(n) + local f = getfields(n) local tt = { } for k=1,#f do local v = f[k] @@ -118,7 +148,7 @@ local function totable(n,flat,verbose,noattributes) if type(nv) == "number" or type(nv) == "string" then tt[v] = nv else - tt[v] = totable(nv,flat,verbose) + tt[v] = totable(nv,flat,verbose,noattributes) end elseif type(nv) == "table" then tt[v] = nv -- totable(nv,flat,verbose) -- data @@ -128,7 +158,27 @@ local function totable(n,flat,verbose,noattributes) end end if verbose then - tt.type = nodecodes[tt.id] + local subtype = tt.subtype + local id = tt.id + local nodename = nodecodes[id] + tt.id = nodename + local subtypes = subtcodes[nodename] + if subtypes then + tt.subtype = subtypes[subtype] + elseif subtype == 0 then + tt.subtype = nil + else + -- we need a table + end + if tt.char then + tt.char = f_char(tt.char) + end + if tt.small_char then + tt.small_char = f_char(tt.small_char) + end + if tt.large_char then + tt.large_char = f_char(tt.large_char) + end end return tt end @@ -137,14 +187,18 @@ local function totable(n,flat,verbose,noattributes) local t, tn = { }, 0 while n do tn = tn + 1 - t[tn] = to_table(n,flat,verbose,noattributes) + local nt = to_table(n,flat,verbose,noattributes) + t[tn] = nt + nt.next = nil + nt.prev = nil n = n.next end return t else - local t = to_table(n) - if n.next then - t.next = totable(n.next,flat,verbose,noattributes) + local t = to_table(n,flat,verbose,noattributes) + local n = n.next + if n then + t.next = totable(n,flat,verbose,noattributes) end return t end @@ -153,7 +207,8 @@ local function totable(n,flat,verbose,noattributes) end end -nodes.totable = totable +nodes.totable = function(n,...) return totable(tonode(n),...) end +nodes.totree = function(n) return totable(tonode(n),true,true,true) end -- no attributes, todo: attributes in k,v list local function key(k) return ((type(k) == "number") and "["..k.."]") or k @@ -161,7 +216,7 @@ end -- not ok yet; this will become a module --- todo: adapt to nodecodes etc +-- todo: adapt to nodecodes etc .. use formatters local function serialize(root,name,handle,depth,m,noattributes) handle = handle or print @@ -186,12 +241,12 @@ local function serialize(root,name,handle,depth,m,noattributes) if root then local fld if root.id then - fld = nodefields(root) -- we can cache these (todo) + fld = getfields(root) -- we can cache these (todo) else fld = sortedkeys(root) end if type(root) == 'table' and root['type'] then -- userdata or table - handle(format("%s %s=%q,",depth,'type',root['type'])) + handle(format("%s type=%q,",depth,root['type'])) end for f=1,#fld do local k = fld[f] @@ -241,7 +296,7 @@ function nodes.serialize(root,name,noattributes) n = n + 1 t[n] = s end - serialize(root,name,flush,nil,0,noattributes) + serialize(tonode(root),name,flush,nil,0,noattributes) return concat(t,"\n") end @@ -258,6 +313,7 @@ function nodes.visualizebox(...) -- to be checked .. will move to module anyway end function nodes.list(head,n) -- name might change to nodes.type -- to be checked .. will move to module anyway + head = tonode(head) if not n then context.starttyping(true) end @@ -275,6 +331,7 @@ function nodes.list(head,n) -- name might change to nodes.type -- to be checked end function nodes.print(head,n) + head = tonode(head) while head do local id = head.id logs.writer(string.formatters["%w%S"],n or 0,head) |