diff options
author | Karl Berry <karl@freefriends.org> | 2013-04-08 00:43:40 +0000 |
---|---|---|
committer | Karl Berry <karl@freefriends.org> | 2013-04-08 00:43:40 +0000 |
commit | 824f7b0903de8ad7f6ee3d7656005e4c59155e06 (patch) | |
tree | abfc8673ef9916f3ab7074e811207384c301492b /Master/texmf-dist/tex/context/base/node-ser.lua | |
parent | 689aefb0727676ed3cddf331337b4be226495e72 (diff) |
context import for TL13, from www.pragma-ade.com/context/beta/cont-tmf.zip
git-svn-id: svn://tug.org/texlive/trunk@29731 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-dist/tex/context/base/node-ser.lua')
-rw-r--r-- | Master/texmf-dist/tex/context/base/node-ser.lua | 38 |
1 files changed, 26 insertions, 12 deletions
diff --git a/Master/texmf-dist/tex/context/base/node-ser.lua b/Master/texmf-dist/tex/context/base/node-ser.lua index 63690d00ade..b0a6e9952aa 100644 --- a/Master/texmf-dist/tex/context/base/node-ser.lua +++ b/Master/texmf-dist/tex/context/base/node-ser.lua @@ -10,15 +10,17 @@ if not modules then modules = { } end modules ['node-ser'] = { -- of luatex; this is pretty old code that needs an overhaul local type, format, rep = type, string.format, string.rep -local concat, tohash, sortedkeys = table.concat, table.tohash, table.sortedkeys +local concat, tohash, sortedkeys, printtable = table.concat, table.tohash, table.sortedkeys, table.print local allocate = utilities.storage.allocate local nodes, node = nodes, node local traverse = node.traverse +local is_node = node.is_node local nodecodes = nodes.nodecodes +local noadcodes = nodes.noadcodes local nodefields = nodes.fields local hlist_code = nodecodes.hlist @@ -39,6 +41,7 @@ local expand = allocate ( tohash { "leader", -- leader_ptr "action", -- action_ptr "value", -- user_defined nodes with subtype 'a' en 'n' + "head", } ) -- page_insert: "height", "last_ins_ptr", "best_ins_ptr" @@ -69,7 +72,7 @@ nodes.ignorablefields = ignore -- not ok yet: -function nodes.astable(n,sparse) -- not yet ok +local function astable(n,sparse) -- not yet ok local f, t = nodefields(n), { } for i=1,#f do local v = f[i] @@ -92,11 +95,15 @@ function nodes.astable(n,sparse) -- not yet ok return t end +nodes.astable = astable + +setinspector(function(v) if is_node(v) then printtable(astable(v),tostring(v)) return true end end) + -- under construction: -local function totable(n,flat,verbose) -- todo: no attributes +local function totable(n,flat,verbose,noattributes) -- todo: no local function - local function to_table(n,flat,verbose) + local function to_table(n,flat,verbose,noattributes) -- no need to pass local f = nodefields(n) local tt = { } for k=1,#f do @@ -105,6 +112,8 @@ local function totable(n,flat,verbose) -- todo: no attributes if nv then if ignore[v] then -- skip + elseif noattributes and v == "attr" then + -- skip elseif expand[v] then if type(nv) == "number" or type(nv) == "string" then tt[v] = nv @@ -128,14 +137,14 @@ local function totable(n,flat,verbose) -- todo: no attributes local t, tn = { }, 0 while n do tn = tn + 1 - t[tn] = to_table(n,flat,verbose) + t[tn] = to_table(n,flat,verbose,noattributes) n = n.next end return t else local t = to_table(n) if n.next then - t.next = totable(n.next,flat,verbose) + t.next = totable(n.next,flat,verbose,noattributes) end return t end @@ -154,7 +163,7 @@ end -- todo: adapt to nodecodes etc -local function serialize(root,name,handle,depth,m) +local function serialize(root,name,handle,depth,m,noattributes) handle = handle or print if depth then depth = depth .. " " @@ -188,6 +197,11 @@ local function serialize(root,name,handle,depth,m) local k = fld[f] if k == "ref_count" then -- skip + elseif noattributes and k == "attr" then + -- skip + elseif k == "id" then + local v = root[k] + handle(format("%s id=%s,",depth,nodecodes[v] or noadcodes[v] or v)) elseif k then local v = root[k] local t = type(v) @@ -206,12 +220,12 @@ local function serialize(root,name,handle,depth,m) elseif t == "boolean" then handle(format("%s %s=%q,",depth,key(k),tostring(v))) elseif v then -- userdata or table - serialize(v,k,handle,depth,m+1) + serialize(v,k,handle,depth,m+1,noattributes) end end end if root['next'] then -- userdata or table - serialize(root['next'],'next',handle,depth,m+1) + serialize(root['next'],'next',handle,depth,m+1,noattributes) end end if m and m > 0 then @@ -221,13 +235,13 @@ local function serialize(root,name,handle,depth,m) end end -function nodes.serialize(root,name) +function nodes.serialize(root,name,noattributes) local t, n = { }, 0 local function flush(s) n = n + 1 t[n] = s end - serialize(root, name, flush, nil, 0) + serialize(root,name,flush,nil,0,noattributes) return concat(t,"\n") end @@ -263,7 +277,7 @@ end function nodes.print(head,n) while head do local id = head.id - texio.write_nl(rep(" ",n or 0) .. tostring(head)) + logs.writer(string.formatters["%w%S"],n or 0,head) if id == hlist_code or id == vlist_code then nodes.print(head.list,(n or 0)+1) end |