diff options
author | Marius <mariausol@gmail.com> | 2013-05-19 20:40:34 +0300 |
---|---|---|
committer | Marius <mariausol@gmail.com> | 2013-05-19 20:40:34 +0300 |
commit | 13ec4b540e0d46c97fd7b089e0b7413da81e0a9f (patch) | |
tree | bebfa563a17c06b3bd3bf8f6f4ba6d025e00d107 /tex/context/base/typo-prc.lua | |
parent | 69ad13650cda027526271179e95b5294694143a1 (diff) | |
download | context-13ec4b540e0d46c97fd7b089e0b7413da81e0a9f.tar.gz |
beta 2013.05.19 19:27
Diffstat (limited to 'tex/context/base/typo-prc.lua')
-rw-r--r-- | tex/context/base/typo-prc.lua | 250 |
1 files changed, 125 insertions, 125 deletions
diff --git a/tex/context/base/typo-prc.lua b/tex/context/base/typo-prc.lua index 5b74abd0b..4fb64d0f5 100644 --- a/tex/context/base/typo-prc.lua +++ b/tex/context/base/typo-prc.lua @@ -1,125 +1,125 @@ -if not modules then modules = { } end modules ['typo-prc'] = { - version = 1.001, - comment = "companion to typo-prc.mkiv", - author = "Hans Hagen, PRAGMA-ADE, Hasselt NL", - copyright = "PRAGMA ADE / ConTeXt Development Team", - license = "see context related readme files" -} - --- moved from strc-ini.lua - - -local formatters = string.formatters -local lpegmatch, patterns, P, C, Cs = lpeg.match, lpeg.patterns, lpeg.P, lpeg.C, lpeg.Cs - --- processors: syntax: processor->data ... not ok yet - -typesetters.processors = typesetters.processors or { } -local processors = typesetters.processors - -local trace_processors = false -local report_processors = logs.reporter("processors") -local registered = { } - -trackers.register("typesetters.processors", function(v) trace_processors = v end) - -function processors.register(p) - registered[p] = true -end - -function processors.reset(p) - registered[p] = nil -end - ---~ local splitter = lpeg.splitat("->",true) -- also support => - -local becomes = P('->') -local processor = (1-becomes)^1 -local splitter = C(processor) * becomes * Cs(patterns.argument + patterns.content) - -function processors.split(str) - local p, s = lpegmatch(splitter,str) - if registered[p] then - return p, s - else - return false, str - end -end - -function processors.apply(p,s) - local str = p - if s == nil then - p, s = lpegmatch(splitter,p) - end - if p and registered[p] then - if trace_processors then - report_processors("applying %s processor %a, argument: %s","known",p,s) - end - context.applyprocessor(p,s) - elseif s then - if trace_processors then - report_processors("applying %s processor %a, argument: %s","unknown",p,s) - end - context(s) - elseif str then - if trace_processors then - report_processors("applying %s processor, data: %s","ignored",str) - end - context(str) - end -end - -function processors.startapply(p,s) - local str = p - if s == nil then - p, s = lpegmatch(splitter,p) - end - if p and registered[p] then - if trace_processors then - report_processors("start applying %s processor %a","known",p) - end - context.applyprocessor(p) - context("{") - return s - elseif p then - if trace_processors then - report_processors("start applying %s processor %a","unknown",p) - end - context.firstofoneargument() - context("{") - return s - else - if trace_processors then - report_processors("start applying %s processor","ignored") - end - context.firstofoneargument() - context("{") - return str - end -end - -function processors.stopapply() - context("}") - if trace_processors then - report_processors("stop applying processor") - end -end - -function processors.tostring(str) - local p, s = lpegmatch(splitter,str) - if registered[p] then - return formatters["\\applyprocessor{%s}{%s}"](p,s) - else - return str - end -end - -function processors.stripped(str) - local p, s = lpegmatch(splitter,str) - return s or str -end - --- interface - -commands.registerstructureprocessor = processors.register -commands.resetstructureprocessor = processors.reset +if not modules then modules = { } end modules ['typo-prc'] = {
+ version = 1.001,
+ comment = "companion to typo-prc.mkiv",
+ author = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
+ copyright = "PRAGMA ADE / ConTeXt Development Team",
+ license = "see context related readme files"
+}
+
+-- moved from strc-ini.lua
+
+
+local formatters = string.formatters
+local lpegmatch, patterns, P, C, Cs = lpeg.match, lpeg.patterns, lpeg.P, lpeg.C, lpeg.Cs
+
+-- processors: syntax: processor->data ... not ok yet
+
+typesetters.processors = typesetters.processors or { }
+local processors = typesetters.processors
+
+local trace_processors = false
+local report_processors = logs.reporter("processors")
+local registered = { }
+
+trackers.register("typesetters.processors", function(v) trace_processors = v end)
+
+function processors.register(p)
+ registered[p] = true
+end
+
+function processors.reset(p)
+ registered[p] = nil
+end
+
+--~ local splitter = lpeg.splitat("->",true) -- also support =>
+
+local becomes = P('->')
+local processor = (1-becomes)^1
+local splitter = C(processor) * becomes * Cs(patterns.argument + patterns.content)
+
+function processors.split(str)
+ local p, s = lpegmatch(splitter,str)
+ if registered[p] then
+ return p, s
+ else
+ return false, str
+ end
+end
+
+function processors.apply(p,s)
+ local str = p
+ if s == nil then
+ p, s = lpegmatch(splitter,p)
+ end
+ if p and registered[p] then
+ if trace_processors then
+ report_processors("applying %s processor %a, argument: %s","known",p,s)
+ end
+ context.applyprocessor(p,s)
+ elseif s then
+ if trace_processors then
+ report_processors("applying %s processor %a, argument: %s","unknown",p,s)
+ end
+ context(s)
+ elseif str then
+ if trace_processors then
+ report_processors("applying %s processor, data: %s","ignored",str)
+ end
+ context(str)
+ end
+end
+
+function processors.startapply(p,s)
+ local str = p
+ if s == nil then
+ p, s = lpegmatch(splitter,p)
+ end
+ if p and registered[p] then
+ if trace_processors then
+ report_processors("start applying %s processor %a","known",p)
+ end
+ context.applyprocessor(p)
+ context("{")
+ return s
+ elseif p then
+ if trace_processors then
+ report_processors("start applying %s processor %a","unknown",p)
+ end
+ context.firstofoneargument()
+ context("{")
+ return s
+ else
+ if trace_processors then
+ report_processors("start applying %s processor","ignored")
+ end
+ context.firstofoneargument()
+ context("{")
+ return str
+ end
+end
+
+function processors.stopapply()
+ context("}")
+ if trace_processors then
+ report_processors("stop applying processor")
+ end
+end
+
+function processors.tostring(str)
+ local p, s = lpegmatch(splitter,str)
+ if registered[p] then
+ return formatters["\\applyprocessor{%s}{%s}"](p,s)
+ else
+ return str
+ end
+end
+
+function processors.stripped(str)
+ local p, s = lpegmatch(splitter,str)
+ return s or str
+end
+
+-- interface
+
+commands.registerstructureprocessor = processors.register
+commands.resetstructureprocessor = processors.reset
|