buff-imp-nested.lua /size: 2380 b    last modification: 2020-07-01 14:35
1
if
not
modules
then
modules
=
{
}
end
modules
[
'
buff-imp-nested
'
]
=
{
2
version
=
1
.
001
,
3
comment
=
"
companion to buff-imp-nested.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
lpegmatch
,
patterns
=
lpeg
.
match
,
lpeg
.
patterns
10
local
P
,
V
,
Carg
=
lpeg
.
P
,
lpeg
.
V
,
lpeg
.
Carg
11 12
local
context
=
context
13
local
verbatim
=
context
.
verbatim
14
local
variables
=
interfaces
.
variables
15 16
local
makepattern
=
visualizers
.
makepattern
17
local
getvisualizer
=
visualizers
.
getvisualizer
18 19
local
nested
=
nil
20 21
local
donestedtypingstart
=
context
.
donestedtypingstart
22
local
donestedtypingstop
=
context
.
donestedtypingstop
23 24
local
v_none
=
variables
.
none
25
local
v_slanted
=
variables
.
slanted
26 27
local
handler
=
visualizers
.
newhandler
{
28
initialize
=
function
(
settings
)
29
local
option
=
settings
and
settings
.
option
30
if
not
option
or
option
=
=
"
"
then
31
nested
=
nil
32
elseif
option
=
=
v_slanted
then
33
nested
=
nil
34
elseif
option
=
=
v_none
then
35
nested
=
nil
36
else
37
nested
=
getvisualizer
(
option
,
"
direct
"
)
38
end
39
end
,
40
open
=
function
(
)
41
donestedtypingstart
(
)
42
end
,
43
close
=
function
(
)
44
donestedtypingstop
(
)
45
end
,
46
content
=
function
(
s
)
47
if
nested
then
48
nested
(
s
)
49
else
50
verbatim
(
s
)
51
end
52
end
,
53
}
54 55
local
open
=
P
(
"
<<
"
)
56
local
close
=
P
(
"
>>
"
)
57
local
rest
=
(
1
-
open
-
close
-
patterns
.
space
-
patterns
.
newline
)
^
1
58 59
local
grammar
=
visualizers
.
newgrammar
(
"
default
"
,
{
60 61
initialize
=
patterns
.
beginofstring
*
Carg
(
1
)
/
handler
.
initialize
,
62 63
open
=
makepattern
(
handler
,
"
open
"
,
open
)
,
64
close
=
makepattern
(
handler
,
"
close
"
,
close
)
,
65
rest
=
makepattern
(
handler
,
"
content
"
,
rest
)
,
66 67
nested
=
V
(
"
open
"
)
*
(
V
(
"
pattern
"
)
^
0
)
*
V
(
"
close
"
)
,
68
pattern
=
V
(
"
line
"
)
+
V
(
"
space
"
)
+
V
(
"
nested
"
)
+
V
(
"
rest
"
)
,
69 70
visualizer
=
V
(
"
initialize
"
)
*
(
V
(
"
pattern
"
)
^
1
)
71 72
}
)
73 74
local
parser
=
P
(
grammar
)
75 76
visualizers
.
register
(
"
nested
"
,
{
parser
=
parser
,
handler
=
handler
,
grammar
=
grammar
}
)
77 78
-- lpeg.match(parser,[[<<tf<<sl>>tf<<sl>>tf>>]]) context.par()
79
-- lpeg.match(parser,[[<<tf<<sl<<tf>>sl>>tf>>]]) context.par()
80
-- lpeg.match(parser,[[sl<<tf<<sl>>tf>>sl]]) context.par()
81