publ-oth.lua /size: 4020 b    last modification: 2020-07-01 14:35
1
if
not
modules
then
modules
=
{
}
end
modules
[
'
publ-oth
'
]
=
{
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
,
S
,
C
,
Ct
,
Cf
,
Cg
,
Cmt
,
Carg
=
lpeg
.
P
,
lpeg
.
S
,
lpeg
.
C
,
lpeg
.
Ct
,
lpeg
.
Cf
,
lpeg
.
Cg
,
lpeg
.
Cmt
,
lpeg
.
Carg
10
local
lpegmatch
=
lpeg
.
match
11 12
local
p_endofline
=
lpeg
.
patterns
.
newline
13 14
local
publications
=
publications
15 16
local
loaders
=
publications
.
loaders
17
local
getindex
=
publications
.
getindex
18 19
local
function
addfield
(
t
,
k
,
v
,
fields
)
20
k
=
fields
[
k
]
21
if
k
then
22
local
tk
=
t
[
k
]
23
if
tk
then
24
t
[
k
]
=
tk
.
.
"
and
"
.
.
v
25
else
26
t
[
k
]
=
v
27
end
28
end
29
return
t
30
end
31 32
local
function
checkfield
(
_
,
_
,
t
,
categories
,
all
)
33
local
tag
=
t
.
tag
34
if
tag
then
35
local
category
=
t
.
category
36
t
.
tag
=
nil
37
t
.
category
=
categories
[
category
]
or
category
38
all
[
tag
]
=
t
39
end
40
return
true
41
end
42 43
-- endnotes --
44 45
local
fields
=
{
46
[
"
@
"
]
=
"
tag
"
,
47
[
"
0
"
]
=
"
category
"
,
48
[
"
A
"
]
=
"
author
"
,
49
[
"
E
"
]
=
"
editor
"
,
50
[
"
T
"
]
=
"
title
"
,
51
[
"
D
"
]
=
"
year
"
,
52
[
"
I
"
]
=
"
publisher
"
,
53
}
54 55
local
categories
=
{
56
[
"
Journal Article
"
]
=
"
article
"
,
57
}
58 59
local
entry
=
P
(
"
%
"
)
*
Cg
(
C
(
1
)
*
(
S
(
"
\t
"
)
^
1
)
*
C
(
(
1
-
p_endofline
)
^
0
)
*
Carg
(
1
)
)
*
p_endofline
60
local
record
=
Cf
(
Ct
(
"
"
)
*
(
entry
^
1
)
,
addfield
)
61
local
records
=
(
Cmt
(
record
*
Carg
(
2
)
*
Carg
(
3
)
,
checkfield
)
*
P
(
1
)
)
^
1
62 63
function
publications
.
endnotes_to_btx
(
data
)
64
local
all
=
{
}
65
lpegmatch
(
records
,
data
,
1
,
fields
,
categories
,
all
)
66
return
all
67
end
68 69
function
loaders
.
endnote
(
dataset
,
filename
)
70
-- we could combine the next into checkfield but let's not create too messy code
71
local
dataset
,
fullname
=
publications
.
resolvedname
(
dataset
,
filename
)
72
if
fullname
then
73
loaders
.
lua
(
dataset
,
publications
.
endnotes_to_btx
(
io
.
loaddata
(
fullname
)
or
"
"
)
)
74
end
75
end
76 77
-- refman --
78 79
local
entry
=
Cg
(
C
(
(
1
-
lpeg
.
S
(
"
\t
"
)
-
p_endofline
)
^
1
)
*
(
S
(
"
\t-
"
)
^
1
)
*
C
(
(
1
-
p_endofline
)
^
0
)
*
Carg
(
1
)
)
*
p_endofline
80
local
record
=
Cf
(
Ct
(
"
"
)
*
(
entry
^
1
)
,
addfield
)
81
local
records
=
(
Cmt
(
record
*
Carg
(
2
)
*
Carg
(
3
)
,
checkfield
)
*
P
(
1
)
)
^
1
82 83
local
fields
=
{
84
[
"
SN
"
]
=
"
tag
"
,
85
[
"
TY
"
]
=
"
category
"
,
86
[
"
A1
"
]
=
"
author
"
,
87
[
"
E1
"
]
=
"
editor
"
,
88
[
"
T1
"
]
=
"
title
"
,
89
[
"
Y1
"
]
=
"
year
"
,
90
[
"
PB
"
]
=
"
publisher
"
,
91
}
92 93
local
categories
=
{
94
[
"
JOUR
"
]
=
"
article
"
,
95
}
96 97
function
publications
.
refman_to_btx
(
data
)
98
local
all
=
{
}
99
lpegmatch
(
records
,
data
,
1
,
fields
,
categories
,
all
)
100
return
all
101
end
102 103
function
loaders
.
refman
(
dataset
,
filename
)
104
-- we could combine the next into checkfield but let's not create too messy code
105
local
dataset
,
fullname
=
publications
.
resolvedname
(
dataset
,
filename
)
106
if
fullname
then
107
loaders
.
lua
(
dataset
,
publications
.
refman_to_btx
(
io
.
loaddata
(
fullname
)
or
"
"
)
)
108
end
109
end
110 111
-- test --
112 113
-- local endnote = [[
114
-- %0 Journal Article
115
-- %T Scientific Visualization, Overviews, Methodologies, and Techniques
116
-- %A Nielson, Gregory M
117
-- %A Hagen, Hans
118
-- %A Müller, Heinrich
119
-- %@ 0818677776
120
-- %D 1994
121
-- %I IEEE Computer Society
122
--
123
-- %0 Journal Article
124
-- %T Scientific Visualization, Overviews, Methodologies, and Techniques
125
-- %A Nielson, Gregory M
126
-- %A Hagen, Hans
127
-- %A Müller, Heinrich
128
-- %@ 0818677775
129
-- %D 1994
130
-- %I IEEE Computer Society
131
-- ]]
132
--
133
-- local refman = [[
134
-- TY - JOUR
135
-- T1 - Scientific Visualization, Overviews, Methodologies, and Techniques
136
-- A1 - Nielson, Gregory M
137
-- A1 - Hagen, Hans
138
-- A1 - Müller, Heinrich
139
-- SN - 0818677776
140
-- Y1 - 1994
141
-- PB - IEEE Computer Society
142
--
143
-- TY - JOUR
144
-- T1 - Scientific Visualization, Overviews, Methodologies, and Techniques
145
-- A1 - Nielson, Gregory M
146
-- A1 - Hagen, Hans
147
-- A1 - Müller, Heinrich
148
-- SN - 0818677775
149
-- Y1 - 1994
150
-- PB - IEEE Computer Society
151
-- ]]
152
--
153
-- inspect(publications.endnotes_to_btx(endnote))
154
-- inspect(publications.refman_to_btx(refman))
155