diff options
Diffstat (limited to 'tex/context/base/mkiv/meta-nod.lua')
-rw-r--r-- | tex/context/base/mkiv/meta-nod.lua | 76 |
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 } |