diff options
Diffstat (limited to 'Master/texmf-dist/tex/context/base/mkiv/buff-ini.lua')
-rw-r--r-- | Master/texmf-dist/tex/context/base/mkiv/buff-ini.lua | 159 |
1 files changed, 140 insertions, 19 deletions
diff --git a/Master/texmf-dist/tex/context/base/mkiv/buff-ini.lua b/Master/texmf-dist/tex/context/base/mkiv/buff-ini.lua index 5b5c4786756..4589e5498c5 100644 --- a/Master/texmf-dist/tex/context/base/mkiv/buff-ini.lua +++ b/Master/texmf-dist/tex/context/base/mkiv/buff-ini.lua @@ -42,7 +42,9 @@ local scantokencode = scanners.tokencode local getters = tokens.getters local gettoken = getters.token -local scanners = interfaces.scanners +local getcommand = token.get_command +local getcsname = token.get_csname +local getnextchar = token.scan_next_char or token.get_next_char local variables = interfaces.variables local settings_to_array = utilities.parsers.settings_to_array @@ -375,7 +377,7 @@ local tochar = { local experiment = false local experiment = scantokencode and true -function tokens.pickup(start,stop) +local function pickup(start,stop) local stoplist = split[stop] -- totable(stop) local stoplength = #stoplist local stoplast = stoplist[stoplength] @@ -439,11 +441,11 @@ function tokens.pickup(start,stop) -- we're skipping leading stuff, like obeyedlines and relaxes if experiment and size > 0 then -- we're probably in a macro - local char = tochar[token.get_command(t)] -- could also be char(token.get_mode(t)) + local char = tochar[getcommand(t)] if char then size = size + 1 ; list[size] = char else - local csname = token.get_csname(t) + local csname = getcsname(t) if csname == stop then stoplength = 0 break @@ -494,6 +496,118 @@ function tokens.pickup(start,stop) end end +-- -- lmtx: +-- +-- local function pickup(start,stop) +-- local stoplist = split[stop] -- totable(stop) +-- local stoplength = #stoplist +-- local stoplast = stoplist[stoplength] +-- local startlist = split[start] -- totable(start) +-- local startlength = #startlist +-- local startlast = startlist[startlength] +-- local list = { } +-- local size = 0 +-- local depth = 0 +-- getnextchar() -- we start with a \relax +-- while true do -- or use depth +-- local char = getnextchar() +-- if char then +-- size = size + 1 +-- list[size] = char +-- if char == stoplast and size >= stoplength then +-- local done = true +-- local last = size +-- for i=stoplength,1,-1 do +-- if stoplist[i] ~= list[last] then +-- done = false +-- break +-- end +-- last = last - 1 +-- end +-- if done then +-- if depth > 0 then +-- depth = depth - 1 +-- else +-- break +-- end +-- char = false -- trick: let's skip the next (start) test +-- end +-- end +-- if char == startlast and size >= startlength then +-- local done = true +-- local last = size +-- for i=startlength,1,-1 do +-- if startlist[i] ~= list[last] then +-- done = false +-- break +-- end +-- last = last - 1 +-- end +-- if done then +-- depth = depth + 1 +-- end +-- end +-- else +-- local t = gettoken() +-- if t then +-- -- we're skipping leading stuff, like obeyedlines and relaxes +-- if experiment and size > 0 then +-- -- we're probably in a macro +-- local char = tochar[getcommand(t)] +-- if char then +-- size = size + 1 ; list[size] = char +-- else +-- local csname = getcsname(t) +-- if csname == stop then +-- stoplength = 0 +-- break +-- else +-- size = size + 1 ; list[size] = "\\" +-- size = size + 1 ; list[size] = csname +-- size = size + 1 ; list[size] = " " +-- end +-- end +-- else +-- -- ignore and hope for the best +-- end +-- else +-- break +-- end +-- end +-- end +-- local start = 1 +-- local stop = size - stoplength - 1 +-- -- not good enough: only empty lines, but even then we miss the leading +-- -- for verbatim +-- -- +-- -- the next is not yet adapted to the new scanner ... we don't need lpeg here +-- -- +-- for i=start,stop do +-- local li = list[i] +-- if lpegmatch(blackspace,li) then +-- -- keep going +-- elseif lpegmatch(eol,li) then +-- -- okay +-- start = i + 1 +-- else +-- break +-- end +-- end +-- for i=stop,start,-1 do +-- if lpegmatch(whitespace,list[i]) then +-- stop = i - 1 +-- else +-- break +-- end +-- end +-- -- +-- if start <= stop then +-- return concat(list,"",start,stop) +-- else +-- return "" +-- end +-- end + -- function buffers.pickup(name,start,stop,finish,catcodes,doundent) -- local data = tokens.pickup(start,stop) -- if doundent or (autoundent and doundent == nil) then @@ -505,21 +619,28 @@ end -- commands.pickupbuffer = buffers.pickup -scanners.pickupbuffer = function() - local name = scanstring() - local start = scanstring() - local stop = scanstring() - local finish = scanstring() - local catcodes = scaninteger() - local doundent = scanboolean() - local data = tokens.pickup(start,stop) - if doundent or (autoundent and doundent == nil) then - data = undent(data) - end - buffers.assign(name,data,catcodes) - -- context[finish]() - context(finish) -end +tokens.pickup = pickup + +implement { + name = "pickupbuffer", + actions = function() + -- let's pickup all here (no arguments) + local name = scanstring() + local start = scanstring() + local stop = scanstring() + local finish = scanstring() + local catcodes = scaninteger() + local doundent = scanboolean() + -- could be a scanner: + local data = pickup(start,stop) + if doundent or (autoundent and doundent == nil) then + data = undent(data) + end + buffers.assign(name,data,catcodes) + -- context[finish]() + context(finish) + end +} local function savebuffer(list,name,prefix) -- name is optional if not list or list == "" then |