@retorquere/bibtex-parser 6.4.4 → 6.4.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/grammar.js +31 -30
- package/index.d.ts +7 -0
- package/index.js +11 -3
- package/package.json +1 -1
package/grammar.js
CHANGED
|
@@ -1544,7 +1544,7 @@ function peg$parse(input, options) {
|
|
|
1544
1544
|
}
|
|
1545
1545
|
|
|
1546
1546
|
function peg$parseField() {
|
|
1547
|
-
var s0, s1, s2, s3, s4, s5, s6, s7, s8;
|
|
1547
|
+
var s0, s1, s2, s3, s4, s5, s6, s7, s8, s9;
|
|
1548
1548
|
|
|
1549
1549
|
s0 = peg$currPos;
|
|
1550
1550
|
s1 = peg$parseFieldName();
|
|
@@ -1594,7 +1594,12 @@ function peg$parse(input, options) {
|
|
|
1594
1594
|
if (peg$silentFails === 0) { peg$fail(peg$e7); }
|
|
1595
1595
|
}
|
|
1596
1596
|
if (s7 !== peg$FAILED) {
|
|
1597
|
-
s8 =
|
|
1597
|
+
s8 = [];
|
|
1598
|
+
s9 = peg$parseFieldTerminator();
|
|
1599
|
+
while (s9 !== peg$FAILED) {
|
|
1600
|
+
s8.push(s9);
|
|
1601
|
+
s9 = peg$parseFieldTerminator();
|
|
1602
|
+
}
|
|
1598
1603
|
peg$savedPos = s0;
|
|
1599
1604
|
s0 = peg$f11(s1, s6);
|
|
1600
1605
|
} else {
|
|
@@ -1641,7 +1646,12 @@ function peg$parse(input, options) {
|
|
|
1641
1646
|
if (s3 !== peg$FAILED) {
|
|
1642
1647
|
s4 = peg$parseVerbatimFieldValue();
|
|
1643
1648
|
if (s4 !== peg$FAILED) {
|
|
1644
|
-
s5 =
|
|
1649
|
+
s5 = [];
|
|
1650
|
+
s6 = peg$parseFieldTerminator();
|
|
1651
|
+
while (s6 !== peg$FAILED) {
|
|
1652
|
+
s5.push(s6);
|
|
1653
|
+
s6 = peg$parseFieldTerminator();
|
|
1654
|
+
}
|
|
1645
1655
|
peg$savedPos = s0;
|
|
1646
1656
|
s0 = peg$f13(s1, s4);
|
|
1647
1657
|
} else {
|
|
@@ -1668,7 +1678,12 @@ function peg$parse(input, options) {
|
|
|
1668
1678
|
if (s2 !== peg$FAILED) {
|
|
1669
1679
|
s3 = peg$parseFieldValue();
|
|
1670
1680
|
if (s3 !== peg$FAILED) {
|
|
1671
|
-
s4 =
|
|
1681
|
+
s4 = [];
|
|
1682
|
+
s5 = peg$parseFieldTerminator();
|
|
1683
|
+
while (s5 !== peg$FAILED) {
|
|
1684
|
+
s4.push(s5);
|
|
1685
|
+
s5 = peg$parseFieldTerminator();
|
|
1686
|
+
}
|
|
1672
1687
|
peg$savedPos = s0;
|
|
1673
1688
|
s0 = peg$f14(s1, s3);
|
|
1674
1689
|
} else {
|
|
@@ -4240,35 +4255,21 @@ function peg$parse(input, options) {
|
|
|
4240
4255
|
}
|
|
4241
4256
|
|
|
4242
4257
|
function peg$parseFieldTerminator() {
|
|
4243
|
-
var s0
|
|
4258
|
+
var s0;
|
|
4244
4259
|
|
|
4245
|
-
s0 = peg$
|
|
4246
|
-
|
|
4247
|
-
|
|
4248
|
-
|
|
4249
|
-
|
|
4250
|
-
|
|
4251
|
-
|
|
4252
|
-
|
|
4253
|
-
|
|
4254
|
-
|
|
4255
|
-
|
|
4256
|
-
}
|
|
4257
|
-
s3 = peg$parse__h();
|
|
4258
|
-
s4 = [];
|
|
4259
|
-
s5 = peg$parseLineComment();
|
|
4260
|
-
if (s5 === peg$FAILED) {
|
|
4261
|
-
s5 = peg$parseEOL();
|
|
4262
|
-
}
|
|
4263
|
-
while (s5 !== peg$FAILED) {
|
|
4264
|
-
s4.push(s5);
|
|
4265
|
-
s5 = peg$parseLineComment();
|
|
4266
|
-
if (s5 === peg$FAILED) {
|
|
4267
|
-
s5 = peg$parseEOL();
|
|
4260
|
+
s0 = peg$parse_();
|
|
4261
|
+
if (s0 === peg$FAILED) {
|
|
4262
|
+
if (input.charCodeAt(peg$currPos) === 44) {
|
|
4263
|
+
s0 = peg$c6;
|
|
4264
|
+
peg$currPos++;
|
|
4265
|
+
} else {
|
|
4266
|
+
s0 = peg$FAILED;
|
|
4267
|
+
if (peg$silentFails === 0) { peg$fail(peg$e14); }
|
|
4268
|
+
}
|
|
4269
|
+
if (s0 === peg$FAILED) {
|
|
4270
|
+
s0 = peg$parseLineComment();
|
|
4268
4271
|
}
|
|
4269
4272
|
}
|
|
4270
|
-
s1 = [s1, s2, s3, s4];
|
|
4271
|
-
s0 = s1;
|
|
4272
4273
|
|
|
4273
4274
|
return s0;
|
|
4274
4275
|
}
|
package/index.d.ts
CHANGED
|
@@ -63,6 +63,13 @@ export interface Entry {
|
|
|
63
63
|
* will be set to `true` if sentence casing was applied to the entry
|
|
64
64
|
*/
|
|
65
65
|
sentenceCased?: boolean;
|
|
66
|
+
/**
|
|
67
|
+
* list of fields that have been inherited/donated using crossref/xdata
|
|
68
|
+
*/
|
|
69
|
+
crossref: {
|
|
70
|
+
donated: string[];
|
|
71
|
+
inherited: string[];
|
|
72
|
+
};
|
|
66
73
|
}
|
|
67
74
|
/**
|
|
68
75
|
* Markup mapping. As the bibtex file is parsed, markup will be transformed according to this table
|
package/index.js
CHANGED
|
@@ -387,12 +387,16 @@ class Parser {
|
|
|
387
387
|
}
|
|
388
388
|
return this.parsed();
|
|
389
389
|
}
|
|
390
|
-
|
|
390
|
+
applyCrossrefField(parent, parentfield, child, childfield) {
|
|
391
391
|
let applied = false;
|
|
392
392
|
for (const field of ['fields', 'creators']) {
|
|
393
393
|
if (!child[field][childfield] && parent[field][parentfield]) {
|
|
394
394
|
child[field][childfield] = parent[field][parentfield];
|
|
395
395
|
applied = true;
|
|
396
|
+
if (!child.crossref.inherited.includes(childfield))
|
|
397
|
+
child.crossref.inherited.push(childfield);
|
|
398
|
+
if (!parent.crossref.donated.includes(parentfield))
|
|
399
|
+
parent.crossref.donated.push(parentfield);
|
|
396
400
|
}
|
|
397
401
|
}
|
|
398
402
|
return applied;
|
|
@@ -408,11 +412,11 @@ class Parser {
|
|
|
408
412
|
for (const mappings of [crossref_json_1.default[entry.type], crossref_json_1.default['*']].filter(m => m)) {
|
|
409
413
|
for (const mapping of [mappings[parent.type], mappings['*']].filter(m => m)) {
|
|
410
414
|
for (const [target, source] of Object.entries(mapping)) {
|
|
411
|
-
if (this.
|
|
415
|
+
if (this.applyCrossrefField(parent, source, entry, target))
|
|
412
416
|
applied = true;
|
|
413
417
|
}
|
|
414
418
|
for (const field of (fields_json_1.default[entry.type] || [])) {
|
|
415
|
-
if (this.
|
|
419
|
+
if (this.applyCrossrefField(parent, field, entry, field))
|
|
416
420
|
applied = true;
|
|
417
421
|
}
|
|
418
422
|
}
|
|
@@ -1297,6 +1301,10 @@ class Parser {
|
|
|
1297
1301
|
type: node.type,
|
|
1298
1302
|
fields: {},
|
|
1299
1303
|
creators: {},
|
|
1304
|
+
crossref: {
|
|
1305
|
+
inherited: [],
|
|
1306
|
+
donated: [],
|
|
1307
|
+
},
|
|
1300
1308
|
};
|
|
1301
1309
|
this.entries.push(this.entry);
|
|
1302
1310
|
// order these first for language-dependent sentence casing
|