meta-nod.lua /size: 1859 b    last modification: 2020-07-01 14:35
1
if
not
modules
then
modules
=
{
}
end
modules
[
'
meta-nod
'
]
=
{
2
version
=
1
.
001
,
3
comment
=
"
companion to meta-nod.mkiv
"
,
4
author
=
"
Hans Hagen, PRAGMA-ADE, Hasselt NL
"
,
5
copyright
=
"
PRAGMA ADE / ConTeXt Development Team
"
,
6
license
=
"
see context related readme files
"
7
}
8 9
local
tonumber
=
tonumber
10
local
P
,
R
,
Cs
,
lpegmatch
=
lpeg
.
P
,
lpeg
.
R
,
lpeg
.
Cs
,
lpeg
.
match
11 12
local
references
=
{
}
13
local
trace
=
false
14
local
report
=
logs
.
reporter
(
"
metapost
"
,
"
nodes
"
)
15 16
local
context
=
context
17
local
implement
=
interfaces
.
implement
18 19
trackers
.
register
(
"
metapost.nodes
"
,
function
(
v
)
trace
=
v
end
)
20 21
local
word
=
R
(
"
AZ
"
,
"
az
"
,
"
__
"
)
^
1
22 23
local
pattern
=
Cs
(
24
(
25
word
/
function
(
s
)
return
references
[
s
]
or
s
end
26
+
P
(
"
{
"
)
/
"
[
"
27
+
P
(
"
}
"
)
/
"
]
"
28
+
P
(
1
)
29
)
^
1
30
)
31 32
implement
{
33
name
=
"
grph_nodes_initialize
"
,
34
actions
=
function
(
)
35
references
=
{
}
36
end
37
}
38 39
implement
{
40
name
=
"
grph_nodes_reset
"
,
41
actions
=
function
(
)
42
references
=
{
}
43
end
44
}
45 46
implement
{
47
name
=
"
grph_nodes_register
"
,
48
arguments
=
{
"
string
"
,
"
integer
"
}
,
49
actions
=
function
(
s
,
r
)
50
if
not
tonumber
(
s
)
then
51
if
trace
then
52
report
(
"
register %i as %a
"
,
t
,
s
)
53
end
54
references
[
s
]
=
r
55
end
56
end
57
}
58 59
implement
{
60
name
=
"
grph_nodes_resolve
"
,
61
arguments
=
"
string
"
,
62
actions
=
function
(
s
)
63
local
r
=
references
[
s
]
64
if
r
then
65
if
trace
then
66
report
(
"
resolve %a to %i
"
,
s
,
r
)
67
end
68
context
(
r
)
69
return
70
end
71
local
n
=
lpegmatch
(
pattern
,
s
)
72
if
s
~
=
n
then
73
if
trace
then
74
report
(
"
resolve '%s' to %s
"
,
s
,
n
)
75
end
76
context
(
n
)
77
return
78
end
79
context
(
s
)
80
end
81
}
82