cldf-prs.lua /size: 3768 b    last modification: 2020-07-01 14:35
1
if
not
modules
then
modules
=
{
}
end
modules
[
'
cldf-bas
'
]
=
{
2
version
=
1
.
001
,
3
comment
=
"
companion to cldf-ini.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
-- used in chem-ini.lua
10 11
local
lpegmatch
,
patterns
=
lpeg
.
match
,
lpeg
.
patterns
12
local
P
,
R
,
V
,
Cc
,
Cs
=
lpeg
.
P
,
lpeg
.
R
,
lpeg
.
V
,
lpeg
.
Cc
,
lpeg
.
Cs
13
local
format
=
string
.
format
14 15
local
cpatterns
=
patterns
.
context
or
{
}
16
patterns
.
context
=
cpatterns
17 18
local
utf8character
=
patterns
.
utf8character
19
local
cardinal
=
patterns
.
cardinal
20 21
local
leftbrace
=
P
(
"
{
"
)
22
local
rightbrace
=
P
(
"
}
"
)
23
local
backslash
=
P
(
"
\\
"
)
24
local
csname
=
backslash
*
P
(
1
)
*
(
1
-
backslash
-
leftbrace
)
^
0
*
P
(
"
"
)
^
0
25
local
sign
=
P
(
"
+
"
)
/
"
\\textplus
"
26
+
P
(
"
-
"
)
/
"
\\textminus
"
27
local
nested
=
P
{
leftbrace
*
(
V
(
1
)
+
(
1
-
rightbrace
)
)
^
0
*
rightbrace
}
28
local
subscript
=
P
(
"
_
"
)
29
local
superscript
=
P
(
"
^
"
)
30 31
-- local scripts = P { "start",
32
-- start = V("csname") + V("lowfirst") + V("highfirst"),
33
-- csname = csname,
34
-- content = Cs(V("csname") + nested + sign^-1 * (cardinal + utf8character)),
35
-- lowfirst = subscript * ( Cc("\\lohi{%s}{%s}") * V("content") * superscript + Cc("\\low{%s}" ) ) * V("content") / format,
36
-- highfirst = superscript * ( Cc("\\hilo{%s}{%s}") * V("content") * subscript + Cc("\\high{%s}") ) * V("content") / format,
37
-- }
38 39
-- local scripts = P { "start",
40
-- start = (V("csname") + V("lowfirst") + V("highfirst"))^1,
41
-- csname = csname,
42
-- content = Cs(V("csname") + nested + sign^-1 * (cardinal + utf8character)),
43
-- lowfirst = (subscript /"") * ( Cc("\\lohi{") * V("content") * Cc("}{") * (superscript/"") + Cc("\\low{" ) ) * V("content") * Cc("}"),
44
-- highfirst = (superscript/"") * ( Cc("\\hilo{") * V("content") * Cc("}{") * (subscript /"") + Cc("\\high{") ) * V("content") * Cc("}"),
45
-- }
46 47
local
scripted
=
Cs
{
"
start
"
,
48
start
=
(
V
(
"
csname
"
)
+
V
(
"
nested
"
)
+
V
(
"
lowfirst
"
)
+
V
(
"
highfirst
"
)
+
V
(
"
character
"
)
)
^
1
,
49
rest
=
V
(
"
csname
"
)
+
V
(
"
nested
"
)
+
V
(
"
lowfirst
"
)
+
V
(
"
highfirst
"
)
,
50
csname
=
csname
,
51
character
=
utf8character
,
52
-- nested = leftbrace * (V("rest") + (V("character")-rightbrace))^0 * rightbrace,
53
nested
=
leftbrace
*
(
V
(
"
start
"
)
-
rightbrace
)
^
0
*
rightbrace
,
54
-- content = Cs(V("nested") + sign^-1 * (cardinal + V("character"))),
55
content
=
V
(
"
nested
"
)
+
sign
^
-1
*
(
cardinal
+
V
(
"
character
"
)
)
+
sign
,
56
lowfirst
=
(
subscript
/
"
"
)
*
(
Cc
(
"
\\lohi{
"
)
*
V
(
"
content
"
)
*
Cc
(
"
}{
"
)
*
(
superscript
/
"
"
)
+
Cc
(
"
\\low{
"
)
)
*
V
(
"
content
"
)
*
Cc
(
"
}
"
)
,
57
highfirst
=
(
superscript
/
"
"
)
*
(
Cc
(
"
\\hilo{
"
)
*
V
(
"
content
"
)
*
Cc
(
"
}{
"
)
*
(
subscript
/
"
"
)
+
Cc
(
"
\\high{
"
)
)
*
V
(
"
content
"
)
*
Cc
(
"
}
"
)
,
58
}
59 60
cpatterns
.
csname
=
csname
61
cpatterns
.
scripted
=
scripted
62
cpatterns
.
nested
=
nested
63 64
-- print(lpegmatch(scripted,"10^-3_x"))
65
-- print(lpegmatch(scripted,"\\L {C_5}"))
66
-- print(lpegmatch(scripted,"\\SL{}"))
67
-- print(lpegmatch(scripted,"\\SL{C_5}"))
68
-- print(lpegmatch(scripted,"\\SL{C_5}"))
69
-- print(lpegmatch(scripted,"{C_5}"))
70
-- print(lpegmatch(scripted,"{\\C_5}"))
71
-- print(lpegmatch(scripted,"10^-a"))
72 73