summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/context/base/strc-mar.lua
diff options
context:
space:
mode:
authorMojca Miklavec <mojca.miklavec@gmail.com>2014-05-05 20:29:55 +0000
committerMojca Miklavec <mojca.miklavec@gmail.com>2014-05-05 20:29:55 +0000
commitba9a57343987f1c2c72396e7c38f1fa30352c24c (patch)
tree66a8b12cdf67427ce96770fd0e9e581759aade1c /Master/texmf-dist/tex/context/base/strc-mar.lua
parent15242121b8ddf7d4a041fb3998d295dd8232e1eb (diff)
ConTeXt 2014.04.28 23:24
git-svn-id: svn://tug.org/texlive/trunk@33856 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-dist/tex/context/base/strc-mar.lua')
-rw-r--r--Master/texmf-dist/tex/context/base/strc-mar.lua129
1 files changed, 82 insertions, 47 deletions
diff --git a/Master/texmf-dist/tex/context/base/strc-mar.lua b/Master/texmf-dist/tex/context/base/strc-mar.lua
index 7b3ac11e137..9c6259de4c4 100644
--- a/Master/texmf-dist/tex/context/base/strc-mar.lua
+++ b/Master/texmf-dist/tex/context/base/strc-mar.lua
@@ -12,19 +12,34 @@ if not modules then modules = { } end modules ['strc-mar'] = {
local insert, concat = table.insert, table.concat
local tostring, next, rawget = tostring, next, rawget
local lpegmatch = lpeg.match
-local match = string.match
+
+local context = context
+local commands = commands
local allocate = utilities.storage.allocate
local setmetatableindex = table.setmetatableindex
+local nuts = nodes.nuts
+local tonut = nuts.tonut
+
+local getfield = nuts.getfield
+local setfield = nuts.setfield
+local getnext = nuts.getnext
+local getprev = nuts.getprev
+local getid = nuts.getid
+local getlist = nuts.getlist
+local getattr = nuts.getattr
+local setattr = nuts.setattr
+local getbox = nuts.getbox
+
+local traversenodes = nuts.traverse
+
local nodecodes = nodes.nodecodes
local glyph_code = nodecodes.glyph
local hlist_code = nodecodes.hlist
local vlist_code = nodecodes.vlist
-local traversenodes = node.traverse
local texsetattribute = tex.setattribute
-local texbox = tex.box
local a_marks = attributes.private("structure","marks")
@@ -63,6 +78,10 @@ local lists = structures.lists
local settings_to_array = utilities.parsers.settings_to_array
+local boxes_too = false -- at some point we can also tag boxes or use a zero char
+
+directives.register("marks.boxestoo", function(v) boxes_too = v end)
+
marks.data = marks.data or allocate()
storage.register("structures/marks/data", marks.data, "structures.marks.data")
@@ -100,9 +119,9 @@ end
local function sweep(head,first,last)
for n in traversenodes(head) do
- local id = n.id
+ local id = getid(n)
if id == glyph_code then
- local a = n[a_marks]
+ local a = getattr(n,a_marks)
if not a then
-- next
elseif first == 0 then
@@ -111,17 +130,19 @@ local function sweep(head,first,last)
last = a
end
elseif id == hlist_code or id == vlist_code then
- local a = n[a_marks]
- if not a then
- -- next
- elseif first == 0 then
- first, last = a, a
- elseif a > last then
- last = a
+ if boxes_too then
+ local a = getattr(n,a_marks)
+ if not a then
+ -- next
+ elseif first == 0 then
+ first, last = a, a
+ elseif a > last then
+ last = a
+ end
end
- local list = n.list
+ local list = getlist(n)
if list then
- first, last = sweep(list, first, last)
+ first, last = sweep(list,first,last)
end
end
end
@@ -135,9 +156,9 @@ setmetatableindex(classes, function(t,k) local s = settings_to_array(k) t[k] = s
local lasts = { }
function marks.synchronize(class,n,option)
- local box = texbox[n]
+ local box = getbox(n)
if box then
- local first, last = sweep(box.list,0,0)
+ local first, last = sweep(getlist(box),0,0)
if option == v_keep and first == 0 and last == 0 then
if trace_marks_get or trace_marks_set then
report_marks("action %a, class %a, box %a","retain at synchronize",class,n)
@@ -151,11 +172,16 @@ function marks.synchronize(class,n,option)
for i=1,#classlist do
local class = classlist[i]
local range = ranges[class]
- if not range then
- range = { }
+ if range then
+ range.first = first
+ range.last = last
+ else
+ range = {
+ first = first,
+ last = last,
+ }
ranges[class] = range
end
- range.first, range.last = first, last
if trace_marks_get or trace_marks_set then
report_marks("action %a, class %a, first %a, last %a","synchronize",class,range.first,range.last)
end
@@ -520,20 +546,22 @@ local function do_first(name,range,check)
report_marks("action %a, name %a, range %a","resolving first",name,range)
end
local f_value, f_index, f_found = doresolve(name,range,false,0,0,check)
- if trace_marks_get then
- report_marks("action %a, name %a, range %a","resolving last",name,range)
- end
- local l_value, l_index, l_found = doresolve(name,range,true ,0,0,check)
- if f_found and l_found and l_index > f_index then
- local name = parentname(name)
- for i=f_index,l_index,1 do
- local si = stack[i]
- local sn = si[name]
- if sn and sn ~= false and sn ~= true and sn ~= "" and sn ~= f_value then
- if trace_marks_get then
- report_marks("action %a, name %a, range %a, index %a, value %a","resolving",name,range,i,sn)
+ if f_found then
+ if trace_marks_get then
+ report_marks("action %a, name %a, range %a","resolving last",name,range)
+ end
+ local l_value, l_index, l_found = doresolve(name,range,true ,0,0,check)
+ if l_found and l_index > f_index then
+ local name = parentname(name)
+ for i=f_index,l_index,1 do
+ local si = stack[i]
+ local sn = si[name]
+ if sn and sn ~= false and sn ~= true and sn ~= "" and sn ~= f_value then
+ if trace_marks_get then
+ report_marks("action %a, name %a, range %a, index %a, value %a","resolving",name,range,i,sn)
+ end
+ return sn, i, si
end
- return sn, i, si
end
end
end
@@ -545,23 +573,25 @@ end
local function do_last(name,range,check)
if trace_marks_get then
- report_marks("action %a, name %a, range %a","resolving first",name,range)
- end
- local f_value, f_index, f_found = doresolve(name,range,false,0,0,check)
- if trace_marks_get then
report_marks("action %a, name %a, range %a","resolving last",name,range)
end
local l_value, l_index, l_found = doresolve(name,range,true ,0,0,check)
- if f_found and l_found and l_index > f_index then
- local name = parentname(name)
- for i=l_index,f_index,-1 do
- local si = stack[i]
- local sn = si[name]
- if sn and sn ~= false and sn ~= true and sn ~= "" and sn ~= l_value then
- if trace_marks_get then
- report_marks("action %a, name %a, range %a, index %a, value %a","resolving",name,range,i,sn)
+ if l_found then
+ if trace_marks_get then
+ report_marks("action %a, name %a, range %a","resolving first",name,range)
+ end
+ local f_value, f_index, f_found = doresolve(name,range,false,0,0,check)
+ if f_found and l_index > f_index then
+ local name = parentname(name)
+ for i=l_index,f_index,-1 do
+ local si = stack[i]
+ local sn = si[name]
+ if sn and sn ~= false and sn ~= true and sn ~= "" and sn ~= l_value then
+ if trace_marks_get then
+ report_marks("action %a, name %a, range %a, index %a, value %a","resolving",name,range,i,sn)
+ end
+ return sn, i, si
end
- return sn, i, si
end
end
end
@@ -659,8 +689,10 @@ function marks.fetchallmarks(name,range) fetchallmarks(name,range )
-- here we have a few helpers .. will become commands.*
+local pattern = lpeg.afterprefix("li::")
+
function marks.title(tag,n)
- local listindex = match(n,"^li::(.-)$")
+ local listindex = lpegmatch(pattern,n)
if listindex then
commands.savedlisttitle(tag,listindex,"marking")
else
@@ -669,7 +701,7 @@ function marks.title(tag,n)
end
function marks.number(tag,n) -- no spec
- local listindex = match(n,"^li::(.-)$")
+ local listindex = lpegmatch(pattern,n)
if listindex then
commands.savedlistnumber(tag,listindex)
else
@@ -680,6 +712,9 @@ end
-- interface
+commands.markingtitle = marks.title
+commands.markingnumber = marks.number
+
commands.definemarking = marks.define
commands.relatemarking = marks.relate
commands.setmarking = marks.set