diff options
30 files changed, 440 insertions, 260 deletions
diff --git a/scripts/context/lua/mtxrun.lua b/scripts/context/lua/mtxrun.lua index 97690ecc7..75d09a583 100644 --- a/scripts/context/lua/mtxrun.lua +++ b/scripts/context/lua/mtxrun.lua @@ -8,11 +8,6 @@ if not modules then modules = { } end modules ['mtxrun'] = { license = "see context related readme files" } --- if not lpeg then require("lpeg") end --- if not md5 then require("md5") end --- if not lfs then require("lfs") end --- if not texconfig then texconfig = { } end - -- one can make a stub: -- -- #!/bin/sh @@ -48,6 +43,23 @@ if not modules then modules = { } end modules ['mtxrun'] = { do -- create closure to overcome 200 locals limit +if not modules then modules = { } end modules ['l-functions'] = { + version = 1.001, + comment = "companion to luat-lib.mkiv", + author = "Hans Hagen, PRAGMA-ADE, Hasselt NL", + copyright = "PRAGMA ADE / ConTeXt Development Team", + license = "see context related readme files" +} + +functions = functions or { } + +function functions.dummy() end + + +end -- of closure + +do -- create closure to overcome 200 locals limit + if not modules then modules = { } end modules ['l-string'] = { version = 1.001, comment = "companion to luat-lib.mkiv", @@ -1074,6 +1086,15 @@ function table.swapped(t,s) -- hash return n end +function table.mirror(t) -- hash + local n = { } + for k, v in next, t do + n[v] = k + n[k] = v + end + return n +end + function table.reversed(t) if t then local tt, tn = { }, #t @@ -1752,7 +1773,7 @@ else end -local range = Cs(utf8byte) * (Cs(utf8byte) + Cc(false)) +local range = utf8byte * utf8byte + Cc(false) -- utf8byte is already a capture local utfchar = unicode and unicode.utf8 and unicode.utf8.char @@ -1769,7 +1790,7 @@ function lpeg.UR(str,more) end if first == last then return P(str) - elseif utfchar and last - first < 8 then -- a somewhat arbitrary criterium + elseif utfchar and (last - first < 8) then -- a somewhat arbitrary criterium local p = P(false) for i=first,last do p = p + P(utfchar(i)) @@ -1779,10 +1800,13 @@ function lpeg.UR(str,more) local f = function(b) return b >= first and b <= last end + -- tricky, these nested captures return utf8byte / f -- nil when invalid range end end +-- print(lpeg.match(lpeg.Cs((C(lpeg.UR("αω"))/{ ["χ"] = "OEPS" })^0),"αωχαω")) + function lpeg.is_lpeg(p) @@ -5512,10 +5536,10 @@ if not modules then modules = { } end modules ['util-prs'] = { local lpeg, table, string = lpeg, table, string -local P, R, V, S, C, Ct, Cs, Carg, Cc = lpeg.P, lpeg.R, lpeg.V, lpeg.S, lpeg.C, lpeg.Ct, lpeg.Cs, lpeg.Carg, lpeg.Cc +local P, R, V, S, C, Ct, Cs, Carg, Cc, Cg, Cf = lpeg.P, lpeg.R, lpeg.V, lpeg.S, lpeg.C, lpeg.Ct, lpeg.Cs, lpeg.Carg, lpeg.Cc, lpeg.Cg, lpeg.Cf local lpegmatch, patterns = lpeg.match, lpeg.patterns local concat, format, gmatch, find = table.concat, string.format, string.gmatch, string.find -local tostring, type, next = tostring, type, next +local tostring, type, next, rawset = tostring, type, next, rawset utilities = utilities or {} utilities.parsers = utilities.parsers or { } @@ -5570,6 +5594,10 @@ local pattern_b = spaces * comma^0 * spaces * (key * ((spaces * equal * spaces * -- "a=1, b=2, c=3, d={a{b,c}d}, e=12345, f=xx{a{b,c}d}xx, g={}" : outer {} removes, leading spaces ignored +-- todo: rewrite to fold etc +-- +-- parse = lpeg.Cf(lpeg.Carg(1) * lpeg.Cg(key * equal * value) * separator^0,rawset)^0 -- lpeg.match(parse,"...",1,hash) + local hash = { } local function set(key,value) @@ -5781,6 +5809,30 @@ patterns.paragraphs = Ct((optionalwhitespace * Cs((whitespace^1*endofstring/"" + -- inspect(lpegmatch(patterns.sentences,str)) -- inspect(lpegmatch(patterns.words,str)) +-- handy for k="v" [, ] k="v" + +local dquote = P('"') +local equal = P('=') +local escape = P('\\') +local separator = S(' ,') + +local key = C((1-equal)^1) +local value = dquote * C((1-dquote-escape*dquote)^0) * dquote + +local pattern = Cf(Ct("") * Cg(key * equal * value) * separator^0,rawset)^0 + +parsers.patterns.keq_to_hash_c = pattern + +function parsers.keq_to_hash(str) + if str and str ~= "" then + return lpegmatch(pattern,str) + else + return { } + end +end + +-- inspect(lpeg.match(pattern,[[key="value"]])) + end -- of closure @@ -16801,6 +16853,7 @@ own = { } -- not local, might change own.libs = { -- order can be made better + 'l-function.lua', 'l-string.lua', 'l-table.lua', 'l-lpeg.lua', @@ -16884,7 +16937,7 @@ own.path = gsub(match(own.name,"^(.+)[\\/].-$") or ".","\\","/") local ownpath, owntree = own.path, environment and environment.ownpath or own.path -own.list = { -- predictable paths +own.list = { '.', ownpath , ownpath .. "/../sources", -- HH's development path @@ -16908,7 +16961,7 @@ local function locate_libs() local filename = pth .. "/" .. lib local found = lfs.isfile(filename) if found then - package.path = package.path .. ";" .. pth .. "/?.lua" -- in case l-* does a require (probably obsolete) + package.path = package.path .. ";" .. pth .. "/?.lua" -- in case l-* does a require return pth end end @@ -17040,7 +17093,6 @@ local helpinfo = [[ --var-value report value of variable --find-file report file location --find-path report path of file ---show-package-path report package paths --pattern=str filter variables ]] @@ -17725,18 +17777,7 @@ else end -if e_argument("script") or e_argument("scripts") then - - -- run a script by loading it (using libs), pass args - - runners.loadbase() - if is_mkii_stub then - ok = runners.execute_script(filename,false,true) - else - ok = runners.execute_ctx_script(filename) - end - -elseif e_argument("selfmerge") then +if e_argument("selfmerge") then -- embed used libraries @@ -17759,19 +17800,6 @@ elseif e_argument("selfupdate") then trackers.enable("resolvers.locating") resolvers.updatescript(own.name,"mtxrun") -elseif e_argument("show-package-path") or e_argument("show-package-paths") then - - local l = package.libpaths() - local c = package.clibpaths() - - for i=1,#l do - report("package lib path %s: %s",i,l[i]) - end - - for i=1,#c do - report("package clib path %s: %s",i,c[i]) - end - elseif e_argument("ctxlua") or e_argument("internal") then -- run a script by loading it (using libs) @@ -17779,6 +17807,17 @@ elseif e_argument("ctxlua") or e_argument("internal") then runners.loadbase() ok = runners.execute_script(filename,true) +elseif e_argument("script") or e_argument("scripts") then + + -- run a script by loading it (using libs), pass args + + runners.loadbase() + if is_mkii_stub then + ok = runners.execute_script(filename,false,true) + else + ok = runners.execute_ctx_script(filename) + end + elseif e_argument("execute") then -- execute script diff --git a/scripts/context/stubs/mswin/mtxrun.lua b/scripts/context/stubs/mswin/mtxrun.lua index 97690ecc7..75d09a583 100644 --- a/scripts/context/stubs/mswin/mtxrun.lua +++ b/scripts/context/stubs/mswin/mtxrun.lua @@ -8,11 +8,6 @@ if not modules then modules = { } end modules ['mtxrun'] = { license = "see context related readme files" } --- if not lpeg then require("lpeg") end --- if not md5 then require("md5") end --- if not lfs then require("lfs") end --- if not texconfig then texconfig = { } end - -- one can make a stub: -- -- #!/bin/sh @@ -48,6 +43,23 @@ if not modules then modules = { } end modules ['mtxrun'] = { do -- create closure to overcome 200 locals limit +if not modules then modules = { } end modules ['l-functions'] = { + version = 1.001, + comment = "companion to luat-lib.mkiv", + author = "Hans Hagen, PRAGMA-ADE, Hasselt NL", + copyright = "PRAGMA ADE / ConTeXt Development Team", + license = "see context related readme files" +} + +functions = functions or { } + +function functions.dummy() end + + +end -- of closure + +do -- create closure to overcome 200 locals limit + if not modules then modules = { } end modules ['l-string'] = { version = 1.001, comment = "companion to luat-lib.mkiv", @@ -1074,6 +1086,15 @@ function table.swapped(t,s) -- hash return n end +function table.mirror(t) -- hash + local n = { } + for k, v in next, t do + n[v] = k + n[k] = v + end + return n +end + function table.reversed(t) if t then local tt, tn = { }, #t @@ -1752,7 +1773,7 @@ else end -local range = Cs(utf8byte) * (Cs(utf8byte) + Cc(false)) +local range = utf8byte * utf8byte + Cc(false) -- utf8byte is already a capture local utfchar = unicode and unicode.utf8 and unicode.utf8.char @@ -1769,7 +1790,7 @@ function lpeg.UR(str,more) end if first == last then return P(str) - elseif utfchar and last - first < 8 then -- a somewhat arbitrary criterium + elseif utfchar and (last - first < 8) then -- a somewhat arbitrary criterium local p = P(false) for i=first,last do p = p + P(utfchar(i)) @@ -1779,10 +1800,13 @@ function lpeg.UR(str,more) local f = function(b) return b >= first and b <= last end + -- tricky, these nested captures return utf8byte / f -- nil when invalid range end end +-- print(lpeg.match(lpeg.Cs((C(lpeg.UR("αω"))/{ ["χ"] = "OEPS" })^0),"αωχαω")) + function lpeg.is_lpeg(p) @@ -5512,10 +5536,10 @@ if not modules then modules = { } end modules ['util-prs'] = { local lpeg, table, string = lpeg, table, string -local P, R, V, S, C, Ct, Cs, Carg, Cc = lpeg.P, lpeg.R, lpeg.V, lpeg.S, lpeg.C, lpeg.Ct, lpeg.Cs, lpeg.Carg, lpeg.Cc +local P, R, V, S, C, Ct, Cs, Carg, Cc, Cg, Cf = lpeg.P, lpeg.R, lpeg.V, lpeg.S, lpeg.C, lpeg.Ct, lpeg.Cs, lpeg.Carg, lpeg.Cc, lpeg.Cg, lpeg.Cf local lpegmatch, patterns = lpeg.match, lpeg.patterns local concat, format, gmatch, find = table.concat, string.format, string.gmatch, string.find -local tostring, type, next = tostring, type, next +local tostring, type, next, rawset = tostring, type, next, rawset utilities = utilities or {} utilities.parsers = utilities.parsers or { } @@ -5570,6 +5594,10 @@ local pattern_b = spaces * comma^0 * spaces * (key * ((spaces * equal * spaces * -- "a=1, b=2, c=3, d={a{b,c}d}, e=12345, f=xx{a{b,c}d}xx, g={}" : outer {} removes, leading spaces ignored +-- todo: rewrite to fold etc +-- +-- parse = lpeg.Cf(lpeg.Carg(1) * lpeg.Cg(key * equal * value) * separator^0,rawset)^0 -- lpeg.match(parse,"...",1,hash) + local hash = { } local function set(key,value) @@ -5781,6 +5809,30 @@ patterns.paragraphs = Ct((optionalwhitespace * Cs((whitespace^1*endofstring/"" + -- inspect(lpegmatch(patterns.sentences,str)) -- inspect(lpegmatch(patterns.words,str)) +-- handy for k="v" [, ] k="v" + +local dquote = P('"') +local equal = P('=') +local escape = P('\\') +local separator = S(' ,') + +local key = C((1-equal)^1) +local value = dquote * C((1-dquote-escape*dquote)^0) * dquote + +local pattern = Cf(Ct("") * Cg(key * equal * value) * separator^0,rawset)^0 + +parsers.patterns.keq_to_hash_c = pattern + +function parsers.keq_to_hash(str) + if str and str ~= "" then + return lpegmatch(pattern,str) + else + return { } + end +end + +-- inspect(lpeg.match(pattern,[[key="value"]])) + end -- of closure @@ -16801,6 +16853,7 @@ own = { } -- not local, might change own.libs = { -- order can be made better + 'l-function.lua', 'l-string.lua', 'l-table.lua', 'l-lpeg.lua', @@ -16884,7 +16937,7 @@ own.path = gsub(match(own.name,"^(.+)[\\/].-$") or ".","\\","/") local ownpath, owntree = own.path, environment and environment.ownpath or own.path -own.list = { -- predictable paths +own.list = { '.', ownpath , ownpath .. "/../sources", -- HH's development path @@ -16908,7 +16961,7 @@ local function locate_libs() local filename = pth .. "/" .. lib local found = lfs.isfile(filename) if found then - package.path = package.path .. ";" .. pth .. "/?.lua" -- in case l-* does a require (probably obsolete) + package.path = package.path .. ";" .. pth .. "/?.lua" -- in case l-* does a require return pth end end @@ -17040,7 +17093,6 @@ local helpinfo = [[ --var-value report value of variable --find-file report file location --find-path report path of file ---show-package-path report package paths --pattern=str filter variables ]] @@ -17725,18 +17777,7 @@ else end -if e_argument("script") or e_argument("scripts") then - - -- run a script by loading it (using libs), pass args - - runners.loadbase() - if is_mkii_stub then - ok = runners.execute_script(filename,false,true) - else - ok = runners.execute_ctx_script(filename) - end - -elseif e_argument("selfmerge") then +if e_argument("selfmerge") then -- embed used libraries @@ -17759,19 +17800,6 @@ elseif e_argument("selfupdate") then trackers.enable("resolvers.locating") resolvers.updatescript(own.name,"mtxrun") -elseif e_argument("show-package-path") or e_argument("show-package-paths") then - - local l = package.libpaths() - local c = package.clibpaths() - - for i=1,#l do - report("package lib path %s: %s",i,l[i]) - end - - for i=1,#c do - report("package clib path %s: %s",i,c[i]) - end - elseif e_argument("ctxlua") or e_argument("internal") then -- run a script by loading it (using libs) @@ -17779,6 +17807,17 @@ elseif e_argument("ctxlua") or e_argument("internal") then runners.loadbase() ok = runners.execute_script(filename,true) +elseif e_argument("script") or e_argument("scripts") then + + -- run a script by loading it (using libs), pass args + + runners.loadbase() + if is_mkii_stub then + ok = runners.execute_script(filename,false,true) + else + ok = runners.execute_ctx_script(filename) + end + elseif e_argument("execute") then -- execute script diff --git a/scripts/context/stubs/unix/mtxrun b/scripts/context/stubs/unix/mtxrun index 97690ecc7..75d09a583 100755 --- a/scripts/context/stubs/unix/mtxrun +++ b/scripts/context/stubs/unix/mtxrun @@ -8,11 +8,6 @@ if not modules then modules = { } end modules ['mtxrun'] = { license = "see context related readme files" } --- if not lpeg then require("lpeg") end --- if not md5 then require("md5") end --- if not lfs then require("lfs") end --- if not texconfig then texconfig = { } end - -- one can make a stub: -- -- #!/bin/sh @@ -48,6 +43,23 @@ if not modules then modules = { } end modules ['mtxrun'] = { do -- create closure to overcome 200 locals limit +if not modules then modules = { } end modules ['l-functions'] = { + version = 1.001, + comment = "companion to luat-lib.mkiv", + author = "Hans Hagen, PRAGMA-ADE, Hasselt NL", + copyright = "PRAGMA ADE / ConTeXt Development Team", + license = "see context related readme files" +} + +functions = functions or { } + +function functions.dummy() end + + +end -- of closure + +do -- create closure to overcome 200 locals limit + if not modules then modules = { } end modules ['l-string'] = { version = 1.001, comment = "companion to luat-lib.mkiv", @@ -1074,6 +1086,15 @@ function table.swapped(t,s) -- hash return n end +function table.mirror(t) -- hash + local n = { } + for k, v in next, t do + n[v] = k + n[k] = v + end + return n +end + function table.reversed(t) if t then local tt, tn = { }, #t @@ -1752,7 +1773,7 @@ else end -local range = Cs(utf8byte) * (Cs(utf8byte) + Cc(false)) +local range = utf8byte * utf8byte + Cc(false) -- utf8byte is already a capture local utfchar = unicode and unicode.utf8 and unicode.utf8.char @@ -1769,7 +1790,7 @@ function lpeg.UR(str,more) end if first == last then return P(str) - elseif utfchar and last - first < 8 then -- a somewhat arbitrary criterium + elseif utfchar and (last - first < 8) then -- a somewhat arbitrary criterium local p = P(false) for i=first,last do p = p + P(utfchar(i)) @@ -1779,10 +1800,13 @@ function lpeg.UR(str,more) local f = function(b) return b >= first and b <= last end + -- tricky, these nested captures return utf8byte / f -- nil when invalid range end end +-- print(lpeg.match(lpeg.Cs((C(lpeg.UR("αω"))/{ ["χ"] = "OEPS" })^0),"αωχαω")) + function lpeg.is_lpeg(p) @@ -5512,10 +5536,10 @@ if not modules then modules = { } end modules ['util-prs'] = { local lpeg, table, string = lpeg, table, string -local P, R, V, S, C, Ct, Cs, Carg, Cc = lpeg.P, lpeg.R, lpeg.V, lpeg.S, lpeg.C, lpeg.Ct, lpeg.Cs, lpeg.Carg, lpeg.Cc +local P, R, V, S, C, Ct, Cs, Carg, Cc, Cg, Cf = lpeg.P, lpeg.R, lpeg.V, lpeg.S, lpeg.C, lpeg.Ct, lpeg.Cs, lpeg.Carg, lpeg.Cc, lpeg.Cg, lpeg.Cf local lpegmatch, patterns = lpeg.match, lpeg.patterns local concat, format, gmatch, find = table.concat, string.format, string.gmatch, string.find -local tostring, type, next = tostring, type, next +local tostring, type, next, rawset = tostring, type, next, rawset utilities = utilities or {} utilities.parsers = utilities.parsers or { } @@ -5570,6 +5594,10 @@ local pattern_b = spaces * comma^0 * spaces * (key * ((spaces * equal * spaces * -- "a=1, b=2, c=3, d={a{b,c}d}, e=12345, f=xx{a{b,c}d}xx, g={}" : outer {} removes, leading spaces ignored +-- todo: rewrite to fold etc +-- +-- parse = lpeg.Cf(lpeg.Carg(1) * lpeg.Cg(key * equal * value) * separator^0,rawset)^0 -- lpeg.match(parse,"...",1,hash) + local hash = { } local function set(key,value) @@ -5781,6 +5809,30 @@ patterns.paragraphs = Ct((optionalwhitespace * Cs((whitespace^1*endofstring/"" + -- inspect(lpegmatch(patterns.sentences,str)) -- inspect(lpegmatch(patterns.words,str)) +-- handy for k="v" [, ] k="v" + +local dquote = P('"') +local equal = P('=') +local escape = P('\\') +local separator = S(' ,') + +local key = C((1-equal)^1) +local value = dquote * C((1-dquote-escape*dquote)^0) * dquote + +local pattern = Cf(Ct("") * Cg(key * equal * value) * separator^0,rawset)^0 + +parsers.patterns.keq_to_hash_c = pattern + +function parsers.keq_to_hash(str) + if str and str ~= "" then + return lpegmatch(pattern,str) + else + return { } + end +end + +-- inspect(lpeg.match(pattern,[[key="value"]])) + end -- of closure @@ -16801,6 +16853,7 @@ own = { } -- not local, might change own.libs = { -- order can be made better + 'l-function.lua', 'l-string.lua', 'l-table.lua', 'l-lpeg.lua', @@ -16884,7 +16937,7 @@ own.path = gsub(match(own.name,"^(.+)[\\/].-$") or ".","\\","/") local ownpath, owntree = own.path, environment and environment.ownpath or own.path -own.list = { -- predictable paths +own.list = { '.', ownpath , ownpath .. "/../sources", -- HH's development path @@ -16908,7 +16961,7 @@ local function locate_libs() local filename = pth .. "/" .. lib local found = lfs.isfile(filename) if found then - package.path = package.path .. ";" .. pth .. "/?.lua" -- in case l-* does a require (probably obsolete) + package.path = package.path .. ";" .. pth .. "/?.lua" -- in case l-* does a require return pth end end @@ -17040,7 +17093,6 @@ local helpinfo = [[ --var-value report value of variable --find-file report file location --find-path report path of file ---show-package-path report package paths --pattern=str filter variables ]] @@ -17725,18 +17777,7 @@ else end -if e_argument("script") or e_argument("scripts") then - - -- run a script by loading it (using libs), pass args - - runners.loadbase() - if is_mkii_stub then - ok = runners.execute_script(filename,false,true) - else - ok = runners.execute_ctx_script(filename) - end - -elseif e_argument("selfmerge") then +if e_argument("selfmerge") then -- embed used libraries @@ -17759,19 +17800,6 @@ elseif e_argument("selfupdate") then trackers.enable("resolvers.locating") resolvers.updatescript(own.name,"mtxrun") -elseif e_argument("show-package-path") or e_argument("show-package-paths") then - - local l = package.libpaths() - local c = package.clibpaths() - - for i=1,#l do - report("package lib path %s: %s",i,l[i]) - end - - for i=1,#c do - report("package clib path %s: %s",i,c[i]) - end - elseif e_argument("ctxlua") or e_argument("internal") then -- run a script by loading it (using libs) @@ -17779,6 +17807,17 @@ elseif e_argument("ctxlua") or e_argument("internal") then runners.loadbase() ok = runners.execute_script(filename,true) +elseif e_argument("script") or e_argument("scripts") then + + -- run a script by loading it (using libs), pass args + + runners.loadbase() + if is_mkii_stub then + ok = runners.execute_script(filename,false,true) + else + ok = runners.execute_ctx_script(filename) + end + elseif e_argument("execute") then -- execute script diff --git a/tex/context/base/cont-new.mkii b/tex/context/base/cont-new.mkii index 591c83703..c6a84db34 100644 --- a/tex/context/base/cont-new.mkii +++ b/tex/context/base/cont-new.mkii @@ -11,7 +11,7 @@ %C therefore copyrighted by \PRAGMA. See mreadme.pdf for %C details. -\newcontextversion{2012.10.22 23:51} +\newcontextversion{2012.10.28 13:23} %D This file is loaded at runtime, thereby providing an %D excellent place for hacks, patches, extensions and new diff --git a/tex/context/base/cont-new.mkiv b/tex/context/base/cont-new.mkiv index db527eb3b..c4e31a204 100644 --- a/tex/context/base/cont-new.mkiv +++ b/tex/context/base/cont-new.mkiv @@ -11,7 +11,7 @@ %C therefore copyrighted by \PRAGMA. See mreadme.pdf for %C details. -\newcontextversion{2012.10.22 23:51} +\newcontextversion{2012.10.28 13:23} %D This file is loaded at runtime, thereby providing an excellent place for %D hacks, patches, extensions and new features. diff --git a/tex/context/base/context-version.pdf b/tex/context/base/context-version.pdf Binary files differindex 2b98f662f..6d9f28098 100644 --- a/tex/context/base/context-version.pdf +++ b/tex/context/base/context-version.pdf diff --git a/tex/context/base/context-version.png b/tex/context/base/context-version.png Binary files differindex e829e7e07..d3f9c7ee1 100644 --- a/tex/context/base/context-version.png +++ b/tex/context/base/context-version.png diff --git a/tex/context/base/context.mkii b/tex/context/base/context.mkii index 70fc132e0..e5ff7b84b 100644 --- a/tex/context/base/context.mkii +++ b/tex/context/base/context.mkii @@ -20,7 +20,7 @@ %D your styles an modules. \edef\contextformat {\jobname} -\edef\contextversion{2012.10.22 23:51} +\edef\contextversion{2012.10.28 13:23} %D For those who want to use this: diff --git a/tex/context/base/context.mkiv b/tex/context/base/context.mkiv index 75890dd02..a1c25d76e 100644 --- a/tex/context/base/context.mkiv +++ b/tex/context/base/context.mkiv @@ -25,7 +25,7 @@ %D up and the dependencies are more consistent. \edef\contextformat {\jobname} -\edef\contextversion{2012.10.22 23:51} +\edef\contextversion{2012.10.28 13:23} %D For those who want to use this: diff --git a/tex/context/base/l-function.lua b/tex/context/base/l-function.lua new file mode 100644 index 000000000..7ded8ceec --- /dev/null +++ b/tex/context/base/l-function.lua @@ -0,0 +1,11 @@ +if not modules then modules = { } end modules ['l-functions'] = { + version = 1.001, + comment = "companion to luat-lib.mkiv", + author = "Hans Hagen, PRAGMA-ADE, Hasselt NL", + copyright = "PRAGMA ADE / ConTeXt Development Team", + license = "see context related readme files" +} + +functions = functions or { } + +function functions.dummy() end diff --git a/tex/context/base/l-lpeg.lua b/tex/context/base/l-lpeg.lua index 38ac3c0dd..55c520691 100644 --- a/tex/context/base/l-lpeg.lua +++ b/tex/context/base/l-lpeg.lua @@ -606,7 +606,7 @@ else end -local range = Cs(utf8byte) * (Cs(utf8byte) + Cc(false)) +local range = utf8byte * utf8byte + Cc(false) -- utf8byte is already a capture local utfchar = unicode and unicode.utf8 and unicode.utf8.char @@ -623,7 +623,7 @@ function lpeg.UR(str,more) end if first == last then return P(str) - elseif utfchar and last - first < 8 then -- a somewhat arbitrary criterium + elseif utfchar and (last - first < 8) then -- a somewhat arbitrary criterium local p = P(false) for i=first,last do p = p + P(utfchar(i)) @@ -633,10 +633,13 @@ function lpeg.UR(str,more) local f = function(b) return b >= first and b <= last end + -- tricky, these nested captures return utf8byte / f -- nil when invalid range end end +-- print(lpeg.match(lpeg.Cs((C(lpeg.UR("αω"))/{ ["χ"] = "OEPS" })^0),"αωχαω")) + --~ lpeg.print(lpeg.R("ab","cd","gh")) --~ lpeg.print(lpeg.P("a","b","c")) --~ lpeg.print(lpeg.S("a","b","c")) diff --git a/tex/context/base/l-pdfview.lua b/tex/context/base/l-pdfview.lua index 3f4a8bea5..e48358d78 100644 --- a/tex/context/base/l-pdfview.lua +++ b/tex/context/base/l-pdfview.lua @@ -40,6 +40,7 @@ if os.type == "windows" then pdfview.method = "acrobat" runner = function(...) +-- os.spawn(...) os.execute(...) end diff --git a/tex/context/base/l-table.lua b/tex/context/base/l-table.lua index 8d18452d2..9d5bf0904 100644 --- a/tex/context/base/l-table.lua +++ b/tex/context/base/l-table.lua @@ -891,25 +891,25 @@ end function table.swapped(t,s) -- hash local n = { } if s then ---~ for i=1,#s do ---~ n[i] = s[i] ---~ end for k, v in next, s do n[k] = v end end ---~ for i=1,#t do ---~ local ti = t[i] -- don't ask but t[i] can be nil ---~ if ti then ---~ n[ti] = i ---~ end ---~ end for k, v in next, t do n[v] = k end return n end +function table.mirror(t) -- hash + local n = { } + for k, v in next, t do + n[v] = k + n[k] = v + end + return n +end + function table.reversed(t) if t then local tt, tn = { }, #t diff --git a/tex/context/base/luat-bas.mkiv b/tex/context/base/luat-bas.mkiv index 683c0e92f..4d6f6d03b 100644 --- a/tex/context/base/luat-bas.mkiv +++ b/tex/context/base/luat-bas.mkiv @@ -13,22 +13,23 @@ \writestatus{loading}{ConTeXt Lua Macros / Basic Lua Libraries} -\registerctxluafile{l-string} {1.001} -\registerctxluafile{l-table} {1.001} -\registerctxluafile{l-lpeg} {1.001} -\registerctxluafile{l-boolean}{1.001} -\registerctxluafile{l-number} {1.001} -\registerctxluafile{l-math} {1.001} -%registerctxluafile{l-aux} {1.001} -\registerctxluafile{l-io} {1.001} -\registerctxluafile{l-os} {1.001} -\registerctxluafile{l-file} {1.001} -\registerctxluafile{l-md5} {1.001} -\registerctxluafile{l-dir} {1.001} -\registerctxluafile{l-unicode}{1.001} -%registerctxluafile{l-utils} {1.001} -\registerctxluafile{l-url} {1.001} -\registerctxluafile{l-set} {1.001} +\registerctxluafile{l-function}{1.001} +\registerctxluafile{l-string} {1.001} +\registerctxluafile{l-table} {1.001} +\registerctxluafile{l-lpeg} {1.001} +\registerctxluafile{l-boolean} {1.001} +\registerctxluafile{l-number} {1.001} +\registerctxluafile{l-math} {1.001} +%registerctxluafile{l-aux} {1.001} +\registerctxluafile{l-io} {1.001} +\registerctxluafile{l-os} {1.001} +\registerctxluafile{l-file} {1.001} +\registerctxluafile{l-md5} {1.001} +\registerctxluafile{l-dir} {1.001} +\registerctxluafile{l-unicode} {1.001} +%registerctxluafile{l-utils} {1.001} +\registerctxluafile{l-url} {1.001} +\registerctxluafile{l-set} {1.001} % \registerctxluafile{socket.lua}{} % \registerctxluafile{ltn12.lua} {} diff --git a/tex/context/base/luat-exe.lua b/tex/context/base/luat-exe.lua index 0e9a94313..0d5cb5abc 100644 --- a/tex/context/base/luat-exe.lua +++ b/tex/context/base/luat-exe.lua @@ -63,7 +63,6 @@ local function executer(action) local v = permitted[k] if find(name,v) then return action(name .. " " .. arguments) - -- print("executed: " .. name .. " " .. arguments) else report_executers("not permitted: %s %s",name,arguments) end diff --git a/tex/context/base/math-arr.mkiv b/tex/context/base/math-arr.mkiv index 5b50303d0..a9d9591a3 100644 --- a/tex/context/base/math-arr.mkiv +++ b/tex/context/base/math-arr.mkiv @@ -427,11 +427,11 @@ %D Now the under arrows \unexpanded\def\definemathunderarrow - {\dotripleargument\math_arrows_define_over} + {\dotripleargument\math_arrows_define_under} %D For underarrows the default kern is 0.3ex -\def\math_arrows_define_over[#1][#2][#3]% +\def\math_arrows_define_under[#1][#2][#3]% {\ifthirdargument \setuvalue{#1}{\math_arrows_under_handle[#2][#3]}% \else diff --git a/tex/context/base/mult-prm.lua b/tex/context/base/mult-prm.lua index 1775fe0bc..53d2c75a6 100644 --- a/tex/context/base/mult-prm.lua +++ b/tex/context/base/mult-prm.lua @@ -1024,6 +1024,7 @@ return { "skewchar", "skip", "skipdef", +--"skipexpr", "spacefactor", "spaceskip", "span", @@ -1111,4 +1112,4 @@ return { ["xetex"]={ "XeTeXversion", }, -}
\ No newline at end of file +} diff --git a/tex/context/base/pack-rul.mkiv b/tex/context/base/pack-rul.mkiv index 9eb44b747..33eaacff3 100644 --- a/tex/context/base/pack-rul.mkiv +++ b/tex/context/base/pack-rul.mkiv @@ -568,7 +568,7 @@ \def\pack_framed_add_background {\setbox\b_framed_normal\hbox % was vbox - {\pack_framed_forgetall % can be relaxed + {%\pack_framed_forgetall % can be relaxed \boxmaxdepth\maxdimen \framedbackgroundoffset\d_framed_backgroundoffset \framedbackgroundwidth \wd\b_framed_normal @@ -1014,6 +1014,7 @@ \else \d_framed_linewidth\zeropoint \fi +\forgetall \ifx\localformat\empty \setfalse\c_framed_has_format \else @@ -1133,12 +1134,12 @@ \fi \pack_framed_check_extra_offsets \edef\p_framed_background{\framedparameter\c!background}% - \ifx\p_framed_background\empty - \let\pack_framed_forgetall\forgetall - \else - \let\pack_framed_forgetall\relax - \forgetall - \fi +% \ifx\p_framed_background\empty +% \let\pack_framed_forgetall\forgetall +% \else +% \let\pack_framed_forgetall\relax +% \forgetall +% \fi \edef\framedwidth {\the\ifdim\d_framed_width >\zeropoint \d_framed_width \else\zeropoint\fi}% public \edef\framedheight{\the\ifdim\d_framed_height>\zeropoint \d_framed_height\else\zeropoint\fi}% public \edef\framedoffset{\the\dimexpr\ifconditional\c_framed_has_offset\localoffset \else\zeropoint\fi}% public @@ -1896,17 +1897,7 @@ %D The handlers: -\def\pack_framed_forgetall{\forgetall} - -% test: (saves one forgetall) -% -% \edef\framedbackground{\framedparameter\c!background}% -% \ifx\framedbackground\empty -% \let\pack_framed_forgetall\forgetall -% \else -% \let\pack_framed_forgetall\relax -% \forgetall -% \fi +% \def\pack_framed_forgetall{\forgetall} \def\pack_framed_set_foregroundcolor {\edef\p_framed_foregroundcolor{\framedparameter\c!foregroundcolor}% @@ -1921,7 +1912,7 @@ {\vbox to \d_framed_height \bgroup \let\postprocessframebox\relax - \pack_framed_forgetall +% \pack_framed_forgetall \iftrialtypesetting \else \pack_framed_set_foregroundcolor \fi @@ -1942,7 +1933,7 @@ {\vbox to \d_framed_height \bgroup \let\postprocessframebox\relax - \pack_framed_forgetall +% \pack_framed_forgetall \iftrialtypesetting \else \pack_framed_set_foregroundcolor \fi @@ -1963,7 +1954,7 @@ {\vbox to \d_framed_height \bgroup \let\postprocessframebox\relax - \pack_framed_forgetall +% \pack_framed_forgetall \iftrialtypesetting \else \pack_framed_set_foregroundcolor \fi @@ -1982,7 +1973,7 @@ {\vbox \bgroup \let\postprocessframebox\relax - \pack_framed_forgetall +% \pack_framed_forgetall \iftrialtypesetting \else \pack_framed_set_foregroundcolor \fi @@ -2002,7 +1993,7 @@ {\vbox to \d_framed_height \bgroup \let\postprocessframebox\relax - \pack_framed_forgetall +% \pack_framed_forgetall \iftrialtypesetting \else \pack_framed_set_foregroundcolor \fi @@ -2022,7 +2013,7 @@ {\hbox to \d_framed_width \bgroup \let\postprocessframebox\relax - \pack_framed_forgetall +% \pack_framed_forgetall \iftrialtypesetting \else \pack_framed_set_foregroundcolor \fi diff --git a/tex/context/base/page-sel.mkvi b/tex/context/base/page-sel.mkvi index 1fe3f2f38..a56c8453e 100644 --- a/tex/context/base/page-sel.mkvi +++ b/tex/context/base/page-sel.mkvi @@ -64,8 +64,8 @@ {\bgroup \dontcomplain \getfiguredimensions[#filename]% - \global\c_page_selectors_n\noffigurepages\relax - \setupcurrentwithpages[\c!width=\zeropoint,#settings]% + \setupcurrentwithpages[\c!width=\zeropoint,\c!n=\noffigurepages,#settings]% + \global\c_page_selectors_n\directwithpagesparameter\c!n\relax \scratchwidth\directwithpagesparameter\c!width\relax \doifinset0{#emptylist} {\emptyhbox\page}% @@ -82,8 +82,8 @@ {\bgroup \dontcomplain \getfiguredimensions[#filename]% - \global\c_page_selectors_n\noffigurepages\relax - \setupcurrentwithpages[\c!width=\zeropoint,#settings]% + \setupcurrentwithpages[\c!width=\zeropoint,\c!n=\noffigurepages,#settings]% + \global\c_page_selectors_n\directwithpagesparameter\c!n\relax \scratchwidth\directwithpagesparameter\c!width\relax \edef\p_selection{#selection}% \ifx\p_selection\v!even @@ -125,8 +125,8 @@ \def\page_selectors_copy[#filename][#settings][#figuresettings]% {\bgroup \getfiguredimensions[#filename]% - \global\c_page_selectors_n\noffigurepages\relax - \setupcurrentwithpages[\c!marking=\v!off,\c!offset=\zeropoint,#settings]% + \setupcurrentwithpages[\c!marking=\v!off,\c!offset=\zeropoint,\c!n=\noffigurepages,#settings]% + \global\c_page_selectors_n\directwithpagesparameter\c!n\relax \scratchoffset\directwithpagesparameter\c!offset\relax \dorecurse\c_page_selectors_n {\vbox to \textheight @@ -178,16 +178,17 @@ {\bgroup \dontcomplain \getfiguredimensions[#filename]% - \global\c_page_selectors_n\noffigurepages\relax \setupcurrentwithpages [\c!alternative=\v!a, - \c!nx=\plustwo,\c!ny=\plustwo,\c!start=\plusone,\c!stop=\maxcard, + \c!n=\noffigurepages,\c!nx=\plustwo,\c!ny=\plustwo, + \c!start=\plusone,\c!stop=\maxcard, \c!distance=\bodyfontsize, \c!bottom=\vfill,\c!top=\vss,\c!left=\hss,\c!right=\hss, \c!before=\page,\c!after=\page,\c!inbetween=\blank, \c!frame=,\c!background=,\c!backgroundcolor=, \c!name={#filename}, #settings]% + \global\c_page_selectors_n\directwithpagesparameter\c!n\relax \directwithpagesparameter\c!before \scratchnx\directwithpagesparameter\c!nx \scratchny\directwithpagesparameter\c!ny @@ -320,10 +321,10 @@ \dontcomplain \global\let\slicedpagenumber\!!zerocount \getfiguredimensions[#filename]% - \global\c_page_selectors_n\noffigurepages\relax \setupcurrentwithpages [\c!offset=\zeropoint,\c!hoffset=\zeropoint,\c!voffset=\zeropoint, - \c!width=\figurewidth,\c!height=\figureheight,#oddsettings]% + \c!width=\figurewidth,\c!height=\figureheight,\c!n=\noffigurepages,#oddsettings]% + \global\c_page_selectors_n\directwithpagesparameter\c!n\relax \ifnum\c_page_selectors_n>\zerocount \definepapersize [\s!dummy][\c!height=\directwithpagesparameter\c!height,\c!width=\directwithpagesparameter\c!width]% diff --git a/tex/context/base/spac-hor.mkiv b/tex/context/base/spac-hor.mkiv index d0d4660bc..8da1ce69e 100644 --- a/tex/context/base/spac-hor.mkiv +++ b/tex/context/base/spac-hor.mkiv @@ -343,10 +343,10 @@ \def\spac_spacecodes_setup_yes[#1]% {\csname\??spacecodemethod#1\endcsname - \updateraggedskips} % not needed, as sf codes are static + \updateraggedskips} \def\spac_spacecodes_setup_nop - {\updateraggedskips} % not needed, as sf codes are static + {\updateraggedskips} % This is not needed, as \updateraggedskips is taking care of it: diff --git a/tex/context/base/status-files.pdf b/tex/context/base/status-files.pdf Binary files differindex e69c31644..352eea4d5 100644 --- a/tex/context/base/status-files.pdf +++ b/tex/context/base/status-files.pdf diff --git a/tex/context/base/status-lua.pdf b/tex/context/base/status-lua.pdf Binary files differindex 8dd3e74b1..974d6c88d 100644 --- a/tex/context/base/status-lua.pdf +++ b/tex/context/base/status-lua.pdf diff --git a/tex/context/base/status-mkiv.lua b/tex/context/base/status-mkiv.lua index f8c6c692b..3b19284f6 100644 --- a/tex/context/base/status-mkiv.lua +++ b/tex/context/base/status-mkiv.lua @@ -3277,6 +3277,11 @@ return { }, { category = "lua", + filename = "l-function", + status = "todo", + }, + { + category = "lua", filename = "l-io", status = "todo", }, diff --git a/tex/context/base/strc-doc.lua b/tex/context/base/strc-doc.lua index 98d69f4ce..49a79826f 100644 --- a/tex/context/base/strc-doc.lua +++ b/tex/context/base/strc-doc.lua @@ -15,11 +15,12 @@ if not modules then modules = { } end modules ['strc-doc'] = { -- in section titles by default a zero aborts, so there we need: sectionset=bagger with \definestructureprefixset [bagger] [section-2,section-4] [] -- in lists however zero's are ignored, so there numbersegments=2:4 gives result -local next, type = next, type +local next, type, tonumber = next, type, tonumber local format, gsub, find, gmatch, match = string.format, string.gsub, string.find, string.gmatch, string.match -local concat = table.concat +local concat, fastcopy = table.concat, table.fastcopy local max, min = math.max, math.min local allocate, mark, accesstable = utilities.storage.allocate, utilities.storage.mark, utilities.tables.accesstable +local setmetatableindex = table.setmetatableindex local catcodenumbers = catcodes.numbers local ctxcatcodes = catcodenumbers.ctxcatcodes @@ -61,7 +62,7 @@ local a_internal = attributes.private('internal') -- -- -- document -- -- -- -local data +local data -- the current state function documents.initialize() data = allocate { -- whole data is marked @@ -92,11 +93,12 @@ documents.initialize() function documents.preset(numbers) local nofnumbers = #numbers - data.numbers = numbers - data.depth = nofnumbers - data.ownnumbers = { } + local ownnumbers = { } + data.numbers = numbers + data.ownnumbers = ownnumbers + data.depth = nofnumbers for i=1,nofnumbers do - data.ownnumbers[i] = "" + ownnumbers[i] = "" end sections.setnumber(nofnumbers,"-1") end @@ -109,12 +111,12 @@ local tobesaved = allocate() sections.collected = collected sections.tobesaved = tobesaved ---~ local function initializer() ---~ collected = sections.collected ---~ tobesaved = sections.tobesaved ---~ end - ---~ job.register('structures.sections.collected', tobesaved, initializer) +-- local function initializer() +-- collected = sections.collected +-- tobesaved = sections.tobesaved +-- end +-- +-- job.register('structures.sections.collected', tobesaved, initializer) sections.registered = sections.registered or allocate() local registered = sections.registered @@ -132,38 +134,39 @@ end function sections.save(sectiondata) -- local sectionnumber = helpers.simplify(section.sectiondata) -- maybe done earlier local numberdata = sectiondata.numberdata + local ntobesaved = #tobesaved if not numberdata or sectiondata.metadata.nolist then - return #tobesaved + return ntobesaved else - local n = #tobesaved + 1 - tobesaved[n] = numberdata - if not collected[n] then - collected[n] = numberdata + ntobesaved = ntobesaved + 1 + tobesaved[ntobesaved] = numberdata + if not collected[ntobesaved] then + collected[ntobesaved] = numberdata end - return n + return ntobesaved end end function sections.load() setmetatable(collected,nil) - local l = lists.collected - for i=1,#l do - local li = l[i] - local lm = li.metadata - if lm and lm.kind == "section" and not lm.nolist then - local ln = li.numberdata - if ln then - collected[#collected+1] = ln + local lists = lists.collected + for i=1,#lists do + local list = lists[i] + local metadata = list.metadata + if metadata and metadata.kind == "section" and not metadata.nolist then + local numberdata = list.numberdata + if numberdata then + collected[#collected+1] = numberdata end end end - sections.load = nil + sections.load = functions.dummy end -setmetatable(collected, { +table.setmetatableindex(collected, { __index = function(t,i) sections.load() - return t[i] or { } + return collected[i] or { } end }) @@ -195,12 +198,6 @@ function sections.getlevel(name) return levelmap[name] or 0 end -local byway = "^" .. v_by - -function sections.way(way) - context((gsub(way,byway,""))) -end - function sections.setblock(name) local block = name or data.block or "unknown" -- can be used to set the default data.block = block @@ -236,9 +233,12 @@ function sections.getcurrentlevel() context(data.depth) end +local saveset = { } -- experiment, see sections/tricky-001.tex + function sections.somelevel(given) -- old number local numbers = data.numbers + local ownnumbers = data.ownnumbers local forced = data.forced local status = data.status @@ -247,13 +247,13 @@ function sections.somelevel(given) local mappedlevel = levelmap[givenname] local newdepth = tonumber(mappedlevel or (olddepth > 0 and olddepth) or 1) -- hm, levelmap only works for section-* local directives = given.directives - local resetset = (directives and directives.resetset) or "" + local resetset = directives and directives.resetset or "" -- local resetter = sets.getall("structure:resets",data.block,resetset) - -- a trick to permits userdata to overload title, ownnumber and reference + -- a trick to permit userdata to overload title, ownnumber and reference -- normally these are passed as argument but nowadays we provide several -- interfaces (we need this because we want to be compatible) if trace_detail then - report_structure("name '%s', mapped level '%s', old depth '%s', new depth '%s', reset set '%s'", + report_structure("name: %s, mapped level: %s, old depth: %s, new depth: %s, reset set: %s", givenname, mappedlevel or "unknown", olddepth, newdepth, resetset) end local u = given.userdata @@ -266,11 +266,14 @@ function sections.somelevel(given) if u.label and u.label ~= "" then given.titledata.label = u.label ; u.label = nil end end -- so far for the trick + if saveset then + saveset[newdepth] = (resetset ~= "" and resetset) or saveset[newdepth] or "" + end if newdepth > olddepth then for i=olddepth+1,newdepth do - local s = tonumber(sets.get("structure:resets",data.block,resetset,i)) + local s = tonumber(sets.get("structure:resets",data.block,saveset and saveset[i] or resetset,i)) if trace_detail then - report_structure("new>old (%s>%s), reset set '%s', reset value '%s', current '%s'",olddepth,newdepth,resetset,s or "?",numbers[i] or "?") + report_structure("new>old (%s>%s), reset set: %s, reset value: %s, current: %s",olddepth,newdepth,resetset,s or "?",numbers[i] or "?") end if not s or s == 0 then numbers[i] = numbers[i] or 0 @@ -283,9 +286,9 @@ function sections.somelevel(given) end elseif newdepth < olddepth then for i=olddepth,newdepth+1,-1 do - local s = tonumber(sets.get("structure:resets",data.block,resetset,i)) + local s = tonumber(sets.get("structure:resets",data.block,saveset and saveset[i] or resetset,i)) if trace_detail then - report_structure("new<old (%s<%s), reset set '%s', reset value '%s', current '%s'",olddepth,newdepth,resetset,s or "?",numbers[i] or "?") + report_structure("new<old (%s<%s), reset set: %s, reset value: %s, current: %s",olddepth,newdepth,resetset,s or "?",numbers[i] or "?") end if not s or s == 0 then numbers[i] = numbers[i] or 0 @@ -317,24 +320,12 @@ function sections.somelevel(given) end forced[newdepth] = nil if trace_detail then - report_structure("old depth '%s', new depth '%s, old n '%s', new n '%s', forced '%s'",olddepth,newdepth,oldn,newn,concat(fd,"")) - end - elseif newn then - newn = oldn + 1 - if trace_detail then - report_structure("old depth '%s', new depth '%s, old n '%s', new n '%s', increment",olddepth,newdepth,oldn,newn) + report_structure("old depth: %s, new depth: %s, old n: %s, new n: %s, forced: %s",olddepth,newdepth,oldn,newn,concat(fd,"")) end else - local s = tonumber(sets.get("structure:resets",data.block,resetset,newdepth)) - if not s then - newn = oldn or 0 - elseif s == 0 then - newn = oldn or 0 - else - newn = s - 1 - end + newn = oldn + 1 if trace_detail then - report_structure("old depth '%s', new depth '%s, old n '%s', new n '%s', reset",olddepth,newdepth,oldn,newn) + report_structure("old depth: %s, new depth: %s, old n: %s, new n: %s, increment",olddepth,newdepth,oldn,newn) end end numbers[newdepth] = newn @@ -351,16 +342,19 @@ function sections.somelevel(given) numberdata = { } given.numberdata = numberdata end + local n = { } for i=1,newdepth do n[i] = numbers[i] end numberdata.numbers = n +-- numberdata.numbers = fastcopy(numbers) + if #ownnumbers > 0 then - numberdata.ownnumbers = table.fastcopy(ownnumbers) + numberdata.ownnumbers = fastcopy(ownnumbers) end if trace_detail then - report_structure("name '%s', numbers '%s', own numbers '%s'",givenname,concat(numberdata.numbers, " "),concat(numberdata.ownnumbers, " ")) + report_structure("name: %s, numbers: %s, own numbers: %s",givenname,concat(numberdata.numbers, " "),concat(numberdata.ownnumbers, " ")) end local metadata = given.metadata @@ -391,7 +385,7 @@ function sections.reportstructure() elseif d.directives and d.directives.hidenumber then report_structure("%s @ level %i : (%s) -> %s",m,depth,n,t) else - report_structure("%s @ level %i : %s -> %s",m,depth,n,t) + report_structure("%s @ level %i: %s -> %s",m,depth,n,t) end end end @@ -938,3 +932,10 @@ function commands.setsectionblock (name) context(sections.setblock(name)) end function commands.pushsectionblock(name) context(sections.pushblock(name)) end function commands.popsectionblock () context(sections.popblock()) end +-- + +local byway = "^" .. v_by -- ugly but downward compatible + +function commands.way(way) + context((gsub(way,byway,""))) +end diff --git a/tex/context/base/strc-itm.mkvi b/tex/context/base/strc-itm.mkvi index da81f37d5..07a32dd60 100644 --- a/tex/context/base/strc-itm.mkvi +++ b/tex/context/base/strc-itm.mkvi @@ -785,7 +785,7 @@ \doadaptleftskip {\itemgroupparameter\c!leftmargin}% \doadaptrightskip{\itemgroupparameter\c!rightmargin}% \fi - \dosetraggedcommand{\itemgroupparameter\c!align}\raggedcommand + \usealignparameter\itemgroupparameter \edef\m_strc_itemgroups_indenting{\itemgroupparameter\c!indenting}% \ifnum\c_strc_itemgroups_nesting>\zerocount \settrue\c_strc_itemgroups_first diff --git a/tex/context/base/strc-num.mkiv b/tex/context/base/strc-num.mkiv index d8815d423..0e5339000 100644 --- a/tex/context/base/strc-num.mkiv +++ b/tex/context/base/strc-num.mkiv @@ -44,7 +44,7 @@ \fi} \def\autostructureprefixsegments#1% todo: \c!prefixsegments=\v!auto - {2:\thenamedheadlevel{\ctxlua{structures.sections.way("#1\c!way")}}} + {2:\thenamedheadlevel{\ctxcommand{way("#1\c!way")}}} \def\counterparameter#1#2% this will become \named.... {\csname @@ -107,7 +107,7 @@ % % % % \def\strc_counters_way#1% slow, we need to store it at the tex end - {\ctxlua{structures.sections.way("\counterparameter{#1}\c!way")}} + {\ctxcommand{way("\counterparameter{#1}\c!way")}} % \def\thenamedcounterlevel#1% % {\thenamedheadlevel{\strc_counters_way{#1}}} diff --git a/tex/context/base/util-prs.lua b/tex/context/base/util-prs.lua index e7191d0e9..11623c294 100644 --- a/tex/context/base/util-prs.lua +++ b/tex/context/base/util-prs.lua @@ -8,10 +8,10 @@ if not modules then modules = { } end modules ['util-prs'] = { local lpeg, table, string = lpeg, table, string -local P, R, V, S, C, Ct, Cs, Carg, Cc = lpeg.P, lpeg.R, lpeg.V, lpeg.S, lpeg.C, lpeg.Ct, lpeg.Cs, lpeg.Carg, lpeg.Cc +local P, R, V, S, C, Ct, Cs, Carg, Cc, Cg, Cf = lpeg.P, lpeg.R, lpeg.V, lpeg.S, lpeg.C, lpeg.Ct, lpeg.Cs, lpeg.Carg, lpeg.Cc, lpeg.Cg, lpeg.Cf local lpegmatch, patterns = lpeg.match, lpeg.patterns local concat, format, gmatch, find = table.concat, string.format, string.gmatch, string.find -local tostring, type, next = tostring, type, next +local tostring, type, next, rawset = tostring, type, next, rawset utilities = utilities or {} utilities.parsers = utilities.parsers or { } @@ -66,6 +66,10 @@ local pattern_b = spaces * comma^0 * spaces * (key * ((spaces * equal * spaces * -- "a=1, b=2, c=3, d={a{b,c}d}, e=12345, f=xx{a{b,c}d}xx, g={}" : outer {} removes, leading spaces ignored +-- todo: rewrite to fold etc +-- +-- parse = lpeg.Cf(lpeg.Carg(1) * lpeg.Cg(key * equal * value) * separator^0,rawset)^0 -- lpeg.match(parse,"...",1,hash) + local hash = { } local function set(key,value) @@ -276,3 +280,27 @@ patterns.paragraphs = Ct((optionalwhitespace * Cs((whitespace^1*endofstring/"" + -- inspect(lpegmatch(patterns.paragraphs,str)) -- inspect(lpegmatch(patterns.sentences,str)) -- inspect(lpegmatch(patterns.words,str)) + +-- handy for k="v" [, ] k="v" + +local dquote = P('"') +local equal = P('=') +local escape = P('\\') +local separator = S(' ,') + +local key = C((1-equal)^1) +local value = dquote * C((1-dquote-escape*dquote)^0) * dquote + +local pattern = Cf(Ct("") * Cg(key * equal * value) * separator^0,rawset)^0 + +parsers.patterns.keq_to_hash_c = pattern + +function parsers.keq_to_hash(str) + if str and str ~= "" then + return lpegmatch(pattern,str) + else + return { } + end +end + +-- inspect(lpeg.match(pattern,[[key="value"]])) diff --git a/tex/context/base/util-sql-imp-library.lua b/tex/context/base/util-sql-imp-library.lua index f16739085..a32a9d09b 100644 --- a/tex/context/base/util-sql-imp-library.lua +++ b/tex/context/base/util-sql-imp-library.lua @@ -124,6 +124,7 @@ local function datafetched(specification,query,converter) end query = lpegmatch(querysplitter,query) local result, message, okay + -- todo: check if open ! for i=1,#query do local q = query[i] local r, m = connection:execute(q) diff --git a/tex/generic/context/luatex/luatex-fonts-merged.lua b/tex/generic/context/luatex/luatex-fonts-merged.lua index 5e8e3602a..5f0a7aaa0 100644 --- a/tex/generic/context/luatex/luatex-fonts-merged.lua +++ b/tex/generic/context/luatex/luatex-fonts-merged.lua @@ -1,6 +1,22 @@ -- merged file : luatex-fonts-merged.lua -- parent file : luatex-fonts.lua --- merge date : 10/22/12 23:51:08 +-- merge date : 10/28/12 13:23:51 + +do -- begin closure to overcome local limits and interference + +if not modules then modules = { } end modules ['l-functions'] = { + version = 1.001, + comment = "companion to luat-lib.mkiv", + author = "Hans Hagen, PRAGMA-ADE, Hasselt NL", + copyright = "PRAGMA ADE / ConTeXt Development Team", + license = "see context related readme files" +} + +functions = functions or { } + +function functions.dummy() end + +end -- closure do -- begin closure to overcome local limits and interference @@ -1037,25 +1053,25 @@ end function table.swapped(t,s) -- hash local n = { } if s then ---~ for i=1,#s do ---~ n[i] = s[i] ---~ end for k, v in next, s do n[k] = v end end ---~ for i=1,#t do ---~ local ti = t[i] -- don't ask but t[i] can be nil ---~ if ti then ---~ n[ti] = i ---~ end ---~ end for k, v in next, t do n[v] = k end return n end +function table.mirror(t) -- hash + local n = { } + for k, v in next, t do + n[v] = k + n[k] = v + end + return n +end + function table.reversed(t) if t then local tt, tn = { }, #t @@ -1763,7 +1779,7 @@ else end -local range = Cs(utf8byte) * (Cs(utf8byte) + Cc(false)) +local range = utf8byte * utf8byte + Cc(false) -- utf8byte is already a capture local utfchar = unicode and unicode.utf8 and unicode.utf8.char @@ -1780,7 +1796,7 @@ function lpeg.UR(str,more) end if first == last then return P(str) - elseif utfchar and last - first < 8 then -- a somewhat arbitrary criterium + elseif utfchar and (last - first < 8) then -- a somewhat arbitrary criterium local p = P(false) for i=first,last do p = p + P(utfchar(i)) @@ -1790,10 +1806,13 @@ function lpeg.UR(str,more) local f = function(b) return b >= first and b <= last end + -- tricky, these nested captures return utf8byte / f -- nil when invalid range end end +-- print(lpeg.match(lpeg.Cs((C(lpeg.UR("αω"))/{ ["χ"] = "OEPS" })^0),"αωχαω")) + --~ lpeg.print(lpeg.R("ab","cd","gh")) --~ lpeg.print(lpeg.P("a","b","c")) --~ lpeg.print(lpeg.S("a","b","c")) diff --git a/tex/generic/context/luatex/luatex-fonts.lua b/tex/generic/context/luatex/luatex-fonts.lua index 535519db7..dd2c902cd 100644 --- a/tex/generic/context/luatex/luatex-fonts.lua +++ b/tex/generic/context/luatex/luatex-fonts.lua @@ -132,6 +132,7 @@ else -- mess up ConTeXt code for the sake of general generality. Around -- version 1.0 there will be an official api defined. + loadmodule('l-function.lua') loadmodule('l-string.lua') loadmodule('l-table.lua') loadmodule('l-lpeg.lua') |