publ-usr.lua /size: 4291 b    last modification: 2020-07-01 14:35
1
if
not
modules
then
modules
=
{
}
end
modules
[
'
publ-usr
'
]
=
{
2
version
=
1
.
001
,
3
comment
=
"
this module part of publication support
"
,
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
P
,
Cs
,
R
,
Cc
,
C
,
Carg
=
lpeg
.
P
,
lpeg
.
Cs
,
lpeg
.
R
,
lpeg
.
Cc
,
lpeg
.
C
,
lpeg
.
Carg
10
local
lpegmatch
=
lpeg
.
match
11
local
settings_to_hash
=
utilities
.
parsers
.
settings_to_hash
12 13
local
publications
=
publications
14
local
datasets
=
publications
.
datasets
15 16
local
report
=
logs
.
reporter
(
"
publications
"
)
17
local
trace
=
false
trackers
.
register
(
"
publications
"
,
function
(
v
)
trace
=
v
end
)
18 19
-- local str = [[
20
-- \startpublication[k=Berdnikov:TB21-2-129,t=article,a={{Berdnikov},{}},y=2000,n=2257,s=BHHJ00]
21
-- \artauthor[]{Alexander}[A.]{}{Berdnikov}
22
-- \artauthor[]{Hans}[H.]{}{Hagen}
23
-- \artauthor[]{Taco}[T.]{}{Hoekwater}
24
-- \artauthor[]{Bogus{\l}aw}[B.]{}{Jackowski}
25
-- \pubyear{2000}
26
-- \arttitle{{Even more MetaFun with \MP: A request for permission}}
27
-- \journal{TUGboat}
28
-- \issn{0896-3207}
29
-- \volume{21}
30
-- \issue{2}
31
-- \pages{129--130}
32
-- \month{6}
33
-- \stoppublication
34
-- ]]
35 36
local
lists
=
{
37
author
=
true
,
38
editor
=
true
,
39
-- artauthor = true,
40
-- arteditor = true,
41
}
42 43
local
function
registervalue
(
target
,
key
,
value
)
44
target
[
key
]
=
value
45
end
46 47
-- Instead of being generic we just hardcode the old stuff:
48 49
local
function
registerauthor
(
target
,
key
,
juniors
,
firstnames
,
initials
,
vons
,
surnames
)
50
local
value
=
target
[
key
]
51
target
[
key
]
=
(
(
value
and
value
.
.
"
and {
"
)
or
"
{
"
)
.
.
52
vons
.
.
"
},{
"
.
.
53
surnames
.
.
"
},{
"
.
.
54
juniors
.
.
"
},{
"
.
.
55
firstnames
.
.
"
},{
"
.
.
56
initials
.
.
"
}
"
57
end
58 59
local
leftbrace
=
P
(
"
{
"
)
60
local
rightbrace
=
P
(
"
}
"
)
61
local
leftbracket
=
P
(
"
[
"
)
62
local
rightbracket
=
P
(
"
]
"
)
63
local
backslash
=
P
(
"
\\
"
)
64
local
letter
=
R
(
"
az
"
,
"
AZ
"
)
65 66
local
skipspaces
=
lpeg
.
patterns
.
whitespace
^
0
67
local
key
=
Cs
(
letter
^
1
)
68
local
value
=
leftbrace
*
Cs
(
lpeg
.
patterns
.
balanced
)
*
rightbrace
69
local
optional
=
leftbracket
*
Cs
(
(
1
-
rightbracket
)
^
0
)
*
rightbracket
70 71
local
authorkey
=
(
P
(
"
artauthor
"
)
+
P
(
"
author
"
)
)
/
"
author
"
72
+
(
P
(
"
arteditor
"
)
+
P
(
"
editor
"
)
)
/
"
editor
"
73
local
authorvalue
=
(
optional
+
Cc
(
"
{}
"
)
)
*
skipspaces
-- [juniors]
74
*
(
value
+
Cc
(
"
{}
"
)
)
*
skipspaces
-- {firstnames}
75
*
(
optional
+
Cc
(
"
{}
"
)
)
*
skipspaces
-- [initials]
76
*
(
value
+
Cc
(
"
{}
"
)
)
*
skipspaces
-- {vons}
77
*
(
value
+
Cc
(
"
{}
"
)
)
*
skipspaces
-- {surnames}
78 79
local
keyvalue
=
Carg
(
1
)
*
authorkey
*
skipspaces
*
authorvalue
/
registerauthor
80
+
Carg
(
1
)
*
key
*
skipspaces
*
value
/
registervalue
81 82
local
pattern
=
(
backslash
*
keyvalue
+
P
(
1
)
)
^
0
83 84
local
function
addtexentry
(
dataset
,
settings
,
content
)
85
local
current
=
datasets
[
dataset
]
86
local
settings
=
settings_to_hash
(
settings
)
87
local
data
=
{
88
tag
=
settings
.
tag
or
settings
.
k
or
"
no tag
"
,
89
category
=
settings
.
category
or
settings
.
t
or
"
article
"
,
90
}
91
lpegmatch
(
pattern
,
content
,
1
,
data
)
-- can set tag too
92
local
tag
=
data
.
tag
93
local
index
=
publications
.
getindex
(
dataset
,
current
.
luadata
,
tag
)
94
current
.
ordered
[
index
]
=
data
95
current
.
luadata
[
tag
]
=
data
96
current
.
userdata
[
tag
]
=
data
97
current
.
details
[
tag
]
=
nil
98
return
data
99
end
100 101
local
pattern
=
(
Carg
(
1
)
102
*
P
(
"
\\startpublication
"
)
103
*
skipspaces
104
*
optional
105
*
C
(
(
1
-
P
(
"
\\stoppublication
"
)
)
^
1
)
106
*
P
(
"
\\stoppublication
"
)
/
addtexentry
107
+
P
(
"
%
"
)
*
(
1
-
lpeg
.
patterns
.
newline
)
^
0
108
+
P
(
1
)
109
)
^
0
110 111
function
publications
.
loaders
.
bbl
(
dataset
,
filename
)
112
local
dataset
,
fullname
=
publications
.
resolvedname
(
dataset
,
filename
)
113
if
not
fullname
then
114
return
115
end
116
local
data
=
io
.
loaddata
(
filename
)
or
"
"
117
if
data
=
=
"
"
then
118
report
(
"
empty file %a, nothing loaded
"
,
fullname
)
119
return
120
end
121
if
trace
then
122
report
(
"
loading file %a
"
,
fullname
)
123
end
124
lpegmatch
(
pattern
,
data
,
1
,
dataset
)
125
end
126 127
publications
.
addtexentry
=
addtexentry
128
commands
.
addbtxentry
=
addtexentry
129