diff options
author | Marius <mariausol@gmail.com> | 2012-08-27 18:20:19 +0300 |
---|---|---|
committer | Marius <mariausol@gmail.com> | 2012-08-27 18:20:19 +0300 |
commit | 47d1a628ec1cbebf26ac6eeac1cdbdb71009e3fc (patch) | |
tree | 03b44a3953c1c3ae1665f96556bc7022a3eb81aa /tex | |
parent | ef3bfc9ea7ed3326ea07cd48ccf2c3d8d55ea435 (diff) | |
download | context-47d1a628ec1cbebf26ac6eeac1cdbdb71009e3fc.tar.gz |
beta 2012.08.27 17:12
Diffstat (limited to 'tex')
-rw-r--r-- | tex/context/base/cont-new.mkii | 2 | ||||
-rw-r--r-- | tex/context/base/cont-new.mkiv | 2 | ||||
-rw-r--r-- | tex/context/base/context.mkii | 2 | ||||
-rw-r--r-- | tex/context/base/context.mkiv | 2 | ||||
-rw-r--r-- | tex/context/base/l-lpeg.lua | 17 | ||||
-rw-r--r-- | tex/context/base/lxml-lpt.lua | 11 | ||||
-rw-r--r-- | tex/context/base/phys-dim.mkiv | 10 | ||||
-rw-r--r-- | tex/context/base/status-files.pdf | bin | 24399 -> 24378 bytes | |||
-rw-r--r-- | tex/context/base/status-lua.pdf | bin | 191269 -> 191343 bytes | |||
-rw-r--r-- | tex/context/base/trac-lmx.lua | 18 | ||||
-rw-r--r-- | tex/context/base/util-sql.lua | 171 | ||||
-rw-r--r-- | tex/generic/context/luatex/luatex-fonts-merged.lua | 19 |
12 files changed, 224 insertions, 30 deletions
diff --git a/tex/context/base/cont-new.mkii b/tex/context/base/cont-new.mkii index 7ed6ae120..d2d1fa4a6 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.08.25 12:53} +\newcontextversion{2012.08.27 17:12} %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 a4f413280..d12e7ddf1 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.08.25 12:53} +\newcontextversion{2012.08.27 17:12} %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.mkii b/tex/context/base/context.mkii index 7a6b5aa5b..b49c39293 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.08.25 12:53} +\edef\contextversion{2012.08.27 17:12} %D For those who want to use this: diff --git a/tex/context/base/context.mkiv b/tex/context/base/context.mkiv index 0f03278e3..8089824fc 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.08.25 12:53} +\edef\contextversion{2012.08.27 17:12} %D For those who want to use this: diff --git a/tex/context/base/l-lpeg.lua b/tex/context/base/l-lpeg.lua index fee76ac4b..73a276f8a 100644 --- a/tex/context/base/l-lpeg.lua +++ b/tex/context/base/l-lpeg.lua @@ -32,7 +32,22 @@ local report = texio and texio.write_nl or print -- -- local p = C("@") * C("!") / "%2%1" -- lpeg.print(p) print(lpeg.match(p,"@!")) - +-- +-- TRICKY: +-- +-- local P, R, Cs = lpeg.P, lpeg.R, lpeg.Cs +-- +-- local p = Cs(P("+")^0 * R("09")^1 * P(-1)) / function(s) return "l==" .. s end +-- print(lpeg.match(Cs(p),"+10")) +-- +-- local p = P("+")^0 * R("09")^1 * P(-1) / function(s) return "l==" .. s end +-- print(lpeg.match(Cs(p),"+10")) +-- +-- local p = Cs(P("+")^0 * R("09")^1 * P(-1)) / "l==%1" +-- print(lpeg.match(Cs(p),"+10")) +-- +-- local p = P("+")^0 * R("09")^1 * P(-1) / "l==%1" +-- print(lpeg.match(Cs(p),"+10")) -- local lpmatch = lpeg.match -- local lpprint = lpeg.print diff --git a/tex/context/base/lxml-lpt.lua b/tex/context/base/lxml-lpt.lua index b04c80550..9c784d3f5 100644 --- a/tex/context/base/lxml-lpt.lua +++ b/tex/context/base/lxml-lpt.lua @@ -540,10 +540,13 @@ local lp_builtin = P ( local lp_attribute = (P("@") + P("attribute::")) / "" * Cc("(ll.at and ll.at['") * ((R("az","AZ") + S("-_:"))^1) * Cc("'])") ------ lp_fastpos_p = (P("+")^0 * R("09")^1 * P(-1)) / function(s) return "l==" .. s end ------ lp_fastpos_n = (P("-") * R("09")^1 * P(-1)) / function(s) return "(" .. s .. "<0 and (#list+".. s .. "==l))" end -local lp_fastpos_p = (P("+")^0 * R("09")^1 * P(-1)) / "l==%1" -local lp_fastpos_n = (P("-") * R("09")^1 * P(-1)) / "(%1<0 and (#list+%1==l))" +-- lp_fastpos_p = (P("+")^0 * R("09")^1 * P(-1)) / function(s) return "l==" .. s end +-- lp_fastpos_n = (P("-") * R("09")^1 * P(-1)) / function(s) return "(" .. s .. "<0 and (#list+".. s .. "==l))" end +-- +-- Cs really needed here: + +lp_fastpos_p = C(P("+")^0 * R("09")^1 * P(-1)) / "l==%1" +lp_fastpos_n = C(P("-") * R("09")^1 * P(-1)) / "(%1<0 and (#list+%1==l))" local lp_fastpos = lp_fastpos_n + lp_fastpos_p diff --git a/tex/context/base/phys-dim.mkiv b/tex/context/base/phys-dim.mkiv index 84c3c7a2a..ec4ac7a22 100644 --- a/tex/context/base/phys-dim.mkiv +++ b/tex/context/base/phys-dim.mkiv @@ -639,12 +639,10 @@ \definelabelclass [prefix] [2] \definelabelclass [suffix] [2] % This is only a label because we want to show them in a table. -\ctxlua{ - languages.labels.define("setupprefixtext","prefixes")% - languages.labels.define("setupunittext","units")% - languages.labels.define("setupoperatortext","operators")% - languages.labels.define("setupsuffixtext","suffixes")% -} +\ctxcommand{definelabels("prefix", "prefixes" )} +\ctxcommand{definelabels("unit", "units" )} +\ctxcommand{definelabels("operator","operators")} +\ctxcommand{definelabels("suffix", "suffixes" )} %D You can define additional units: %D diff --git a/tex/context/base/status-files.pdf b/tex/context/base/status-files.pdf Binary files differindex 524302525..2ac601dce 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 a30438a00..ae15165ed 100644 --- a/tex/context/base/status-lua.pdf +++ b/tex/context/base/status-lua.pdf diff --git a/tex/context/base/trac-lmx.lua b/tex/context/base/trac-lmx.lua index 82b241688..04740d0d5 100644 --- a/tex/context/base/trac-lmx.lua +++ b/tex/context/base/trac-lmx.lua @@ -129,7 +129,11 @@ end) local function loadedfile(name) name = (resolvers and resolvers.findfile and resolvers.findfile(name)) or name - return io.loaddata(name) + local data = io.loaddata(name) + if not data or data == "" then + report_lmx("empty file: %s",name) + end + return data end lmx.loadedfile = loadedfile @@ -448,7 +452,11 @@ local function lmxresult(self,variables) if self then local converter = self.converter if converter then - return converter(variables) + local converted = converter(variables) + if trace_variables then -- will become templates + report_lmx("converted size: %s",#converted) + end + return converted else return lmxerror("invalid converter") end @@ -467,6 +475,9 @@ function lmx.convertstring(templatestring,variables) end function lmx.convertfile(templatefile,variables) + if trace_variables then -- will become templates + report_lmx("converting file: %s",templatefile) + end local converter = loadedfiles[templatefile] if not converter then converter = lmxnew(loadedfile(templatefile)) @@ -476,6 +487,9 @@ function lmx.convertfile(templatefile,variables) end function lmxconvert(templatefile,resultfile,variables) -- or (templatefile,variables) + if trace_variables then -- will become templates + report_lmx("converting file: %s",templatefile) + end if not variables and type(resultfile) == "table" then variables = resultfile end diff --git a/tex/context/base/util-sql.lua b/tex/context/base/util-sql.lua index 9c1feba7f..1e07bfc3c 100644 --- a/tex/context/base/util-sql.lua +++ b/tex/context/base/util-sql.lua @@ -13,7 +13,7 @@ if not modules then modules = { } end modules ['util-sql'] = { -- buffer template local format = string.format -local rawset, setmetatable, loadstring = rawset, setmetatable, loadstring +local rawset, setmetatable, loadstring, type = rawset, setmetatable, loadstring, type local P, S, V, C, Cs, Ct, Cc, Cg, Cf, patterns, lpegmatch = lpeg.P, lpeg.S, lpeg.V, lpeg.C, lpeg.Cs, lpeg.Ct, lpeg.Cc, lpeg.Cg, lpeg.Cf, lpeg.patterns, lpeg.match local concat = table.concat @@ -183,7 +183,7 @@ local function datafetched(specification) report_state("fetchtime: %.3f sec",osclock()-t) -- not okay under linux else os.execute(command) --- return os.resultof(command) + -- return os.resultof(command) end return true end @@ -213,9 +213,14 @@ local function dataconverted(data) end end +sql.splitdata = splitdata + +local methods = { } +sql.methods = methods + -- todo: new, etc -function sql.fetch(specification) +local function fetch(specification) if trace_sql then report_state("fetching") end @@ -245,28 +250,172 @@ function sql.fetch(specification) return data, keys end -function sql.reuse(specification) +-- local function reuse(specification) +-- if trace_sql then +-- report_state("reusing") +-- end +-- if not validspecification(specification) then +-- report("error in specification") +-- return +-- end +-- local data = dataloaded(specification) +-- if not data then +-- report("error in loading") +-- return +-- end +-- local data, keys = dataconverted(data) +-- if not data then +-- report("error in converting") +-- return +-- end +-- return data, keys +-- end + +sql.fetch = fetch + +methods.client = { + fetch = fetch, +} + +local mysql = nil +local cache = { } + +local function validspecification(specification) + local presets = specification.presets + if type(presets) == "string" then + presets = dofile(presets) + end + if type(presets) == "table" then + setmetatable(presets,defaults) + setmetatable(specification,{ __index = presets }) + else + setmetatable(specification,defaults) + end + return true +end + +local function dataprepared(specification) + local query = false + if specification.template then + query = replacetemplate(specification.template,specification.variables) + elseif specification.templatefile then + query = loadtemplate(specification.templatefile,specification.variables) + end + if query then + return query + end +end + +local function connect(session,specification) + return session:connect( + specification.database or "", + specification.username or "", + specification.password or "", + specification.host or "", + specification.port + ) +end + +local function datafetched(specification,query) + local id = specification.id + local session, connection +-- id = nil + if id then + local c = cache[id] + if c then + session = c.session + connection = c.connection + end + if not connection then + session = mysql() + connection = connect(session,specification) + cache[id] = { session = session, connection = connection } + end + else + session = mysql() + connection = connect(session,specification) + end + if not connection then + return { }, { } + end + local result, message = connection:execute(query) + if not result and id then + if session then + session:close() + end + if connection then + connection:close() + end + session = mysql() -- maybe not needed + connection = connect(session,specification) + cache[id] = { session = session, connection = connection } + result, message = connection:execute(query) + end + local data, keys + if result and type(result) ~= "number" then + keys = result:getcolnames() + if keys then + local n = result:numrows() or 0 + if n == 0 then + data = { } + elseif n == 1 then + data = { result:fetch({},"a") } + else + data = { } + for i=1,n do + data[i] = result:fetch({},"a") + end + end + end + result:close() + elseif message then + report_state("message %s",message) + end + if not keys then + keys = { } + end + if not data then + data = { } + end + if not id then + connection:close() + session:close() + end + return data, keys +end + +local function fetch(specification) + if not mysql then + local lib = require("luasql.mysql") + if lib then + mysql = lib.mysql + else + report_state("error in loading luasql.mysql") + end + end if trace_sql then - report_state("reusing") + report_state("fetching") end if not validspecification(specification) then report("error in specification") return end - local data = dataloaded(specification) - if not data then - report("error in loading") + local query = dataprepared(specification) + if not query then + report("error in preparation") return end - local data, keys = dataconverted(data) + local data, keys = datafetched(specification,query) if not data then - report("error in converting") + report("error in fetching") return end return data, keys end -sql.splitdata = splitdata +methods.library = { + fetch = fetch, +} -- -- -- diff --git a/tex/generic/context/luatex/luatex-fonts-merged.lua b/tex/generic/context/luatex/luatex-fonts-merged.lua index f17a3e045..670573dd8 100644 --- a/tex/generic/context/luatex/luatex-fonts-merged.lua +++ b/tex/generic/context/luatex/luatex-fonts-merged.lua @@ -1,6 +1,6 @@ -- merged file : luatex-fonts-merged.lua -- parent file : luatex-fonts.lua --- merge date : 08/25/12 12:53:08 +-- merge date : 08/27/12 17:12:53 do -- begin closure to overcome local limits and interference @@ -1150,7 +1150,22 @@ local report = texio and texio.write_nl or print -- -- local p = C("@") * C("!") / "%2%1" -- lpeg.print(p) print(lpeg.match(p,"@!")) - +-- +-- TRICKY: +-- +-- local P, R, Cs = lpeg.P, lpeg.R, lpeg.Cs +-- +-- local p = Cs(P("+")^0 * R("09")^1 * P(-1)) / function(s) return "l==" .. s end +-- print(lpeg.match(Cs(p),"+10")) +-- +-- local p = P("+")^0 * R("09")^1 * P(-1) / function(s) return "l==" .. s end +-- print(lpeg.match(Cs(p),"+10")) +-- +-- local p = Cs(P("+")^0 * R("09")^1 * P(-1)) / "l==%1" +-- print(lpeg.match(Cs(p),"+10")) +-- +-- local p = P("+")^0 * R("09")^1 * P(-1) / "l==%1" +-- print(lpeg.match(Cs(p),"+10")) -- local lpmatch = lpeg.match -- local lpprint = lpeg.print |