summaryrefslogtreecommitdiff
path: root/tex/context/base/mkiv/meta-nod.lua
diff options
context:
space:
mode:
authorHans Hagen <pragma@wxs.nl>2018-07-10 16:30:53 +0200
committerContext Git Mirror Bot <phg42.2a@gmail.com>2018-07-10 16:30:53 +0200
commitff693671b6540fa81d2ad7aecdbe786a4df97335 (patch)
tree979066b446d6d47fcec40fa7da9978c31a2bf802 /tex/context/base/mkiv/meta-nod.lua
parentf58860178fcd1497d52acaa3cb2ceda7531e46ac (diff)
downloadcontext-ff693671b6540fa81d2ad7aecdbe786a4df97335.tar.gz
2018-07-10 16:00:00
Diffstat (limited to 'tex/context/base/mkiv/meta-nod.lua')
-rw-r--r--tex/context/base/mkiv/meta-nod.lua76
1 files changed, 64 insertions, 12 deletions
diff --git a/tex/context/base/mkiv/meta-nod.lua b/tex/context/base/mkiv/meta-nod.lua
index 119c276e2..422b4ee14 100644
--- a/tex/context/base/mkiv/meta-nod.lua
+++ b/tex/context/base/mkiv/meta-nod.lua
@@ -6,24 +6,76 @@ if not modules then modules = { } end modules ['meta-nod'] = {
license = "see context related readme files"
}
+local tonumber = tonumber
+local P, R, Cs, lpegmatch = lpeg.P, lpeg.R, lpeg.Cs, lpeg.match
+
local references = { }
+local trace = false
+local report = logs.reporter("metapost","nodes")
-metapost.nodes = {
+local context = context
+local implement = interfaces.implement
- initialize = function()
- references = { }
- end,
+trackers.register("metapost.nodes", function(v) trace = v end)
- register = function(s,r)
- references[s] = r
- end,
+local word = R("AZ","az","__")^1
- resolve = function(s)
- context(references[s] or ("\\number " .. (tonumber(s) or 0)))
- end,
+local pattern = Cs (
+ (
+ word / function(s) return references[s] or s end
+ + P("{") / "["
+ + P("}") / "]"
+ + P(1)
+ )^1
+)
+
+implement {
+ name = "grph_nodes_initialize",
+ actions = function()
+ references = { }
+ end
+}
- reset = function()
+implement {
+ name = "grph_nodes_reset",
+ actions = function()
references = { }
- end,
+ end
+}
+
+implement {
+ name = "grph_nodes_register",
+ arguments = { "string", "integer" },
+ actions = function(s,r)
+ if not tonumber(s) then
+ if trace then
+ report("register %i as %a",t,s)
+ end
+ references[s] = r
+ end
+ end
+}
+implement {
+ name = "grph_nodes_resolve",
+ arguments = "string",
+ actions = function(s)
+ local r = references[s]
+ if r then
+ if trace then
+ report("resolve %a to %i",s,r)
+ end
+ context(r)
+ return
+ end
+ local n = lpegmatch(pattern,s)
+ if s ~= n then
+ if trace then
+ report("resolve '%s' to %s",s,n)
+ end
+ context(n)
+ return
+ end
+ context(s)
+ end
}