@retorquere/bibtex-parser 6.3.4 → 6.3.7

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.
Files changed (2) hide show
  1. package/grammar.js +676 -641
  2. package/package.json +16 -16
package/grammar.js CHANGED
@@ -1,4 +1,4 @@
1
- // Generated by Peggy 1.2.0.
1
+ // Generated by Peggy 2.0.1.
2
2
  //
3
3
  // https://peggyjs.org/
4
4
 
@@ -12,6 +12,7 @@ function peg$subclass(child, parent) {
12
12
 
13
13
  function peg$SyntaxError(message, expected, found, location) {
14
14
  var self = Error.call(this, message);
15
+ // istanbul ignore next Check is a necessary evil to support older environments
15
16
  if (Object.setPrototypeOf) {
16
17
  Object.setPrototypeOf(self, peg$SyntaxError.prototype);
17
18
  }
@@ -47,14 +48,15 @@ peg$SyntaxError.prototype.format = function(sources) {
47
48
  var loc = this.location.source + ":" + s.line + ":" + s.column;
48
49
  if (src) {
49
50
  var e = this.location.end;
50
- var filler = peg$padEnd("", s.line.toString().length);
51
+ var filler = peg$padEnd("", s.line.toString().length, ' ');
51
52
  var line = src[s.line - 1];
52
53
  var last = s.line === e.line ? e.column : line.length + 1;
54
+ var hatLen = (last - s.column) || 1;
53
55
  str += "\n --> " + loc + "\n"
54
56
  + filler + " |\n"
55
57
  + s.line + " | " + line + "\n"
56
- + filler + " | " + peg$padEnd("", s.column - 1)
57
- + peg$padEnd("", last - s.column, "^");
58
+ + filler + " | " + peg$padEnd("", s.column - 1, ' ')
59
+ + peg$padEnd("", hatLen, "^");
58
60
  } else {
59
61
  str += "\n at " + loc;
60
62
  }
@@ -75,7 +77,7 @@ peg$SyntaxError.buildMessage = function(expected, found) {
75
77
  : classEscape(part);
76
78
  });
77
79
 
78
- return "[" + (expectation.inverted ? "^" : "") + escapedParts + "]";
80
+ return "[" + (expectation.inverted ? "^" : "") + escapedParts.join("") + "]";
79
81
  },
80
82
 
81
83
  any: function() {
@@ -291,446 +293,480 @@ function peg$parse(input, options) {
291
293
  var peg$e60 = peg$otherExpectation("Optional Whitespace");
292
294
 
293
295
  var peg$f0 = function(r) {
294
- return {
295
- kind: 'Bibliography',
296
- loc: location(),
297
- source: text(),
298
- children: r,
299
- }
300
- };
296
+ return {
297
+ kind: 'Bibliography',
298
+ loc: location(),
299
+ source: text(),
300
+ children: r,
301
+ }
302
+ };
301
303
  var peg$f1 = function(v) {
302
- return {
303
- kind: 'BracedComment',
304
- loc: location(),
305
- source: text(),
306
- value: v.slice(1, -1),
307
- }
308
- };
304
+ return {
305
+ kind: 'BracedComment',
306
+ loc: location(),
307
+ source: text(),
308
+ value: v.slice(1, -1),
309
+ }
310
+ };
309
311
  var peg$f2 = function(v) {
310
- return {
311
- kind: 'LineComment',
312
- loc: location(),
313
- source: text(),
314
- value: normalizeWhitespace(v),
315
- }
316
- };
317
- var peg$f3 = function(v) {
318
- return {
319
- kind: 'NonEntryText',
320
- loc: location(),
321
- source: text(),
322
- value: normalizeWhitespace(v),
323
- }
312
+ return {
313
+ kind: 'LineComment',
314
+ loc: location(),
315
+ source: text(),
316
+ value: normalizeWhitespace(v),
317
+ }
324
318
  };
319
+ var peg$f3 = function(v) {
320
+ return {
321
+ kind: 'NonEntryText',
322
+ loc: location(),
323
+ source: text(),
324
+ value: normalizeWhitespace(v),
325
+ }
326
+ };
325
327
  var peg$f4 = function(n) { return n; };
326
328
  var peg$f5 = function(comment) { return '{' + comment.join('') + '}' };
327
329
  var peg$f6 = function(type, id, fields) {
328
- return {
329
- kind: 'Entry',
330
- id: id || '',
331
- type: type.toLowerCase(),
332
- loc: location(),
333
- source: text(),
334
- fields: fields,
335
- }
336
- };
330
+ return {
331
+ kind: 'Entry',
332
+ id: id || '',
333
+ type: type.toLowerCase(),
334
+ loc: location(),
335
+ source: text(),
336
+ fields: fields,
337
+ }
338
+ };
337
339
  var peg$f7 = function(opener, v, closer) {
338
- switch (opener + closer) {
339
- case '{}':
340
- case '()':
341
- break
342
- default:
343
- throw new Error(`Unbalanced opener-closer for preamble: ${opener}...${closer}`)
344
- break
345
- }
346
- return {
347
- kind: 'PreambleExpression',
348
- loc: location(),
349
- source: text(),
350
- value: v.reduce((a, b) => a.concat(b), []),
351
- }
352
- };
340
+ switch (opener + closer) {
341
+ case '{}':
342
+ case '()':
343
+ break
344
+ default:
345
+ throw new Error(`Unbalanced opener-closer for preamble: ${opener}...${closer}`)
346
+ break
347
+ }
348
+ return {
349
+ kind: 'PreambleExpression',
350
+ loc: location(),
351
+ source: text(),
352
+ value: v.reduce((a, b) => a.concat(b), []),
353
+ }
354
+ };
353
355
  var peg$f8 = function(k, v) {
354
- return {
355
- kind: 'StringDeclaration',
356
- loc: location(),
357
- source: text(),
358
- name: k,
359
- value: v.reduce((a, b) => a.concat(b), []),
360
- }
361
- };
356
+ return {
357
+ kind: 'StringDeclaration',
358
+ loc: location(),
359
+ source: text(),
360
+ name: k,
361
+ value: v.reduce((a, b) => a.concat(b), []),
362
+ }
363
+ };
362
364
  var peg$f9 = function(id) { return id; };
363
365
  var peg$f10 = function(name) { return isVerbatimField(name) && unnestFields.includes(name) };
364
366
  var peg$f11 = function(name, value) {
365
- // because this was abused so much, many processors treat double-outer-braces as single
366
- return {
367
- kind: 'Field',
368
- loc: location(),
369
- source: text(),
370
- name: name,
371
- loc: location(),
372
- value: [ protect(value) ]
373
- }
374
- };
367
+ // because this was abused so much, many processors treat double-outer-braces as single
368
+ return {
369
+ kind: 'Field',
370
+ loc: location(),
371
+ source: text(),
372
+ name: name,
373
+ loc: location(),
374
+ value: [ protect(value) ]
375
+ }
376
+ };
375
377
  var peg$f12 = function(name) { return isVerbatimField(name) };
376
378
  var peg$f13 = function(name, value) {
377
- return {
378
- kind: 'Field',
379
- loc: location(),
380
- source: text(),
381
- name: name,
382
- loc: location(),
383
- value: [ protect(value) ]
384
- }
385
- };
379
+ return {
380
+ kind: 'Field',
381
+ loc: location(),
382
+ source: text(),
383
+ name: name,
384
+ loc: location(),
385
+ value: [ protect(value) ]
386
+ }
387
+ };
386
388
  var peg$f14 = function(name, value) {
387
- // because this was abused so much, many processors treat double-outer-braces as single
388
- if (unnestFields.includes(name) && Array.isArray(value) && value.length === 1 && value[0].kind === 'Block') {
389
- if (options.unnestMode === 'preserve') {
390
- value[0].case = 'preserve'
391
- } else {
392
- value = value[0].value
393
- }
389
+ // because this was abused so much, many processors treat double-outer-braces as single
390
+ if (unnestFields.includes(name) && Array.isArray(value) && value.length === 1 && value[0].kind === 'Block') {
391
+ if (options.unnestMode === 'preserve') {
392
+ value[0].case = 'preserve'
393
+ } else {
394
+ value = value[0].value
394
395
  }
396
+ }
395
397
 
396
- return handle_markup_switches({
397
- kind: 'Field',
398
- loc: location(),
399
- source: text(),
400
- name: name,
401
- value: value,
402
- })
403
- };
398
+ return handle_markup_switches({
399
+ kind: 'Field',
400
+ loc: location(),
401
+ source: text(),
402
+ name: name,
403
+ value: value,
404
+ })
405
+ };
404
406
  var peg$f15 = function(name) { return name.toLowerCase() };
405
407
  var peg$f16 = function(v) {
406
- return basicTextConversions({
407
- kind: 'Text',
408
- loc: location(),
409
- source: text(),
410
- value: normalizeWhitespace((v || '').trim()),
411
- mode: 'verbatim',
412
- })
413
- };
408
+ return basicTextConversions({
409
+ kind: 'Text',
410
+ loc: location(),
411
+ source: text(),
412
+ value: normalizeWhitespace((v || '').trim()),
413
+ mode: 'verbatim',
414
+ })
415
+ };
414
416
  var peg$f17 = function(v) {
415
- return basicTextConversions({
416
- kind: 'Text',
417
- loc: location(),
418
- source: text(),
419
- value: normalizeWhitespace(v.join('').trim()),
420
- mode: 'verbatim',
421
- })
422
- };
417
+ return basicTextConversions({
418
+ kind: 'Text',
419
+ loc: location(),
420
+ source: text(),
421
+ value: normalizeWhitespace(v.join('').trim()),
422
+ mode: 'verbatim',
423
+ })
424
+ };
423
425
  var peg$f18 = function(v) { return v };
424
426
  var peg$f19 = function(v) { return '{' + v + '}' };
425
- var peg$f20 = function() { return math.set(false) };
426
- var peg$f21 = function(v) {
427
- return v.reduce((a, b) => a.concat(b), []);
428
- };
429
- var peg$f22 = function(v) { return v; };
427
+ var peg$f20 = function(v) { return v };
428
+ var peg$f21 = function(v) { return '{' + v + '}' };
429
+ var peg$f22 = function() { return math.set(false) };
430
430
  var peg$f23 = function(v) {
431
- return basicTextConversions({
432
- kind: 'Text',
433
- loc: location(),
434
- source: text(),
435
- value: v.join('').trim(),
436
- mode: 'verbatim',
437
- })
438
- };
439
- var peg$f24 = function(v) {
440
- return basicTextConversions({
441
- kind: 'Text',
442
- loc: location(),
443
- source: text(),
444
- value: normalizeWhitespace(v),
445
- mode: math.on ? 'math' : 'text',
446
- })
447
- };
431
+ return v.reduce((a, b) => a.concat(b), []);
432
+ };
433
+ var peg$f24 = function(v) { return v; };
448
434
  var peg$f25 = function(v) {
449
- return {
450
- kind: 'Number',
451
- loc: location(),
452
- source: text(),
453
- value: parseInt(v, 10),
454
- }
455
- };
456
- var peg$f26 = function(v) {
457
- return {
458
- kind: 'StringReference',
459
- loc: location(),
460
- source: text(),
461
- name: v,
462
- }
463
- };
464
- var peg$f27 = function(env, v, cenv) { return env === cenv };
465
- var peg$f28 = function(env, v, cenv) {
466
- if (markup[env]) {
467
- return {
468
- kind: 'Block',
469
- loc: location(),
470
- source: text(),
471
- value: v,
472
- markup: { [markup[env]]: true },
473
- }
474
- } else {
475
- return {
476
- kind: 'Environment',
477
- loc: location(),
478
- source: text(),
479
- value: v,
480
- env: env,
481
- }
482
- }
483
- };
484
- var peg$f29 = function(mark, char) {
485
- return {
486
- kind: 'DiacriticCommand',
487
- loc: location(),
488
- source: text(),
489
- mark: mark,
490
- dotless: !!char[1],
491
- character: char[1] || char[0],
492
- }
493
- };
435
+ return basicTextConversions({
436
+ kind: 'Text',
437
+ loc: location(),
438
+ source: text(),
439
+ value: v.join('').trim(),
440
+ mode: 'verbatim',
441
+ })
442
+ };
443
+ var peg$f26 = function(v) { return v; };
444
+ var peg$f27 = function(v) { return v; };
445
+ var peg$f28 = function(v) { return v; };
446
+ var peg$f29 = function(v) {
447
+ return basicTextConversions({
448
+ kind: 'Text',
449
+ loc: location(),
450
+ source: text(),
451
+ value: normalizeWhitespace(v),
452
+ mode: math.on ? 'math' : 'text',
453
+ })
454
+ };
494
455
  var peg$f30 = function(v) {
495
- return basicTextConversions({
496
- kind: 'Text',
497
- loc: location(),
498
- source: text(),
499
- value: v.join('').trim(),
500
- mode: 'verbatim',
501
- })
502
- };
456
+ return basicTextConversions({
457
+ kind: 'Text',
458
+ loc: location(),
459
+ source: text(),
460
+ value: normalizeWhitespace(v),
461
+ mode: math.on ? 'math' : 'text',
462
+ })
463
+ };
503
464
  var peg$f31 = function(v) {
504
- const block = {
465
+ return {
466
+ kind: 'Number',
467
+ loc: location(),
468
+ source: text(),
469
+ value: parseInt(v, 10),
470
+ }
471
+ };
472
+ var peg$f32 = function(v) {
473
+ return {
474
+ kind: 'StringReference',
475
+ loc: location(),
476
+ source: text(),
477
+ name: v,
478
+ }
479
+ };
480
+ var peg$f33 = function(env, v, cenv) { return env === cenv };
481
+ var peg$f34 = function(env, v, cenv) {
482
+ if (markup[env]) {
483
+ return {
505
484
  kind: 'Block',
506
485
  loc: location(),
507
486
  source: text(),
508
487
  value: v,
509
- markup: {},
510
- case: 'protect',
511
- }
512
-
513
- let leadingcmd = block.value.length && (block.value[0].kind.endsWith('Command') || block.value[0].kind === 'Environment') ? block.value[0] : null
514
- let leadingcmdblockarg = leadingcmd
515
- && leadingcmd.kind === 'RegularCommand'
516
- && leadingcmd.arguments.required.length
517
- && leadingcmd.arguments.required[0].kind === 'Block'
518
- && leadingcmd.arguments.required[0]
519
-
520
- // https://github.com/retorquere/zotero-better-bibtex/issues/541#issuecomment-240156274
521
- if (leadingcmd) {
522
- delete block.case
523
-
524
- // command with a block cancels out case protection with containing block
525
- // if a smallcaps block has set case to 'preserve' we want to keep this
526
- if (leadingcmdblockarg && leadingcmdblockarg.case === 'protect') delete leadingcmdblockarg.case
527
-
528
- // \sl, \it etc
529
- if (markup[leadingcmd.command]) {
530
- block.markup[markup[leadingcmd.command]] = true
531
- block.value.shift()
532
- }
488
+ markup: { [markup[env]]: true },
533
489
  }
534
-
535
- return handle_markup_switches(block)
536
- };
537
- var peg$f32 = function() { return !math.on };
538
- var peg$f33 = function(mode) { return math.set(true) };
539
- var peg$f34 = function(mode, v) { return math.set(false) };
540
- var peg$f35 = function(mode, v) {
490
+ } else {
541
491
  return {
542
- kind: mode == '$$' ? 'DisplayMath' : 'InlineMath',
492
+ kind: 'Environment',
543
493
  loc: location(),
544
494
  source: text(),
545
495
  value: v,
546
- case: 'protect',
547
- markup: {},
496
+ env: env,
548
497
  }
549
- };
498
+ }
499
+ };
500
+ var peg$f35 = function(mark, char) {
501
+ return {
502
+ kind: 'DiacriticCommand',
503
+ loc: location(),
504
+ source: text(),
505
+ mark: mark,
506
+ dotless: !!char[1],
507
+ character: char[1] || char[0],
508
+ }
509
+ };
550
510
  var peg$f36 = function(v) {
551
- return {
552
- kind: 'LineComment',
511
+ return basicTextConversions({
512
+ kind: 'Text',
553
513
  loc: location(),
554
514
  source: text(),
555
- value: v,
556
- }
557
- };
558
- var peg$f37 = function(mode, v) {
559
- if (v.kind === 'Block') v = v.value
515
+ value: v.join('').trim(),
516
+ mode: 'verbatim',
517
+ })
518
+ };
519
+ var peg$f37 = function(v) {
520
+ const block = {
521
+ kind: 'Block',
522
+ loc: location(),
523
+ source: text(),
524
+ value: v,
525
+ markup: {},
526
+ case: 'protect',
527
+ }
560
528
 
561
- return {
562
- kind: mode === '_' ? 'SubscriptCommand' : 'SuperscriptCommand',
563
- loc: location(),
564
- source: text(),
565
- value: v,
566
- }
567
- };
568
- var peg$f38 = function(mark, v) {
569
- return {
570
- kind: 'RegularCommand',
571
- loc: location(),
572
- source: text(),
573
- command: mark,
574
- arguments: {
575
- optional: [],
576
- required: [ protect(v) ],
577
- },
578
- }
579
- };
580
- var peg$f39 = function(v) {
581
- return {
582
- kind: 'SymbolCommand',
583
- loc: location(),
584
- source: text(),
585
- command: v,
586
- }
587
- };
588
- var peg$f40 = function(cmd, name) { return name.value.length == 1 && name.value[0].kind === 'RegularCommand' };
589
- var peg$f41 = function(cmd, name, optional, def) {
590
- return {
591
- kind: 'RegularCommand',
592
- loc: location(),
593
- source: text(),
594
- command: cmd,
595
- arguments: {
596
- optional: [],
597
- required: [name, def],
598
- },
599
- }
600
- };
601
- var peg$f42 = function(cmd, url, label) {
602
- return {
603
- kind: 'RegularCommand',
604
- loc: location(),
605
- source: text(),
606
- command: cmd,
607
- arguments: {
608
- optional: [],
609
- required: [url, label],
610
- },
611
- }
612
- };
613
- var peg$f43 = function(cmd) { return verbatimCommands.includes(cmd) && (has_arguments[cmd] === 2) };
614
- var peg$f44 = function(cmd, optional, req1, req2) {
615
- return {
616
- kind: 'RegularCommand',
617
- loc: location(),
618
- source: text(),
619
- command: cmd,
620
- arguments: {
621
- optional: optional,
622
- required: [protect(req1), protect(req2)],
623
- },
624
- }
625
- };
626
- var peg$f45 = function(cmd) { return verbatimCommands.includes(cmd) && (has_arguments[cmd] === 1) };
627
- var peg$f46 = function(cmd, optional, req) {
628
- return {
629
- kind: 'RegularCommand',
630
- loc: location(),
631
- source: text(),
632
- command: cmd,
633
- arguments: {
634
- optional: optional,
635
- required: [protect(req)],
636
- },
637
- }
638
- };
639
- var peg$f47 = function(cmd) { return (has_arguments[cmd] === 2) };
640
- var peg$f48 = function(cmd, optional, req1, req2) {
641
- return {
642
- kind: 'RegularCommand',
643
- loc: location(),
644
- source: text(),
645
- command: cmd,
646
- arguments: {
647
- optional: optional,
648
- required: [req1, req2],
649
- },
529
+ let leadingcmd = block.value.length && (block.value[0].kind.endsWith('Command') || block.value[0].kind === 'Environment') ? block.value[0] : null
530
+ let leadingcmdblockarg = leadingcmd
531
+ && leadingcmd.kind === 'RegularCommand'
532
+ && leadingcmd.arguments.required.length
533
+ && leadingcmd.arguments.required[0].kind === 'Block'
534
+ && leadingcmd.arguments.required[0]
535
+
536
+ // https://github.com/retorquere/zotero-better-bibtex/issues/541#issuecomment-240156274
537
+ if (leadingcmd) {
538
+ delete block.case
539
+
540
+ // command with a block cancels out case protection with containing block
541
+ // if a smallcaps block has set case to 'preserve' we want to keep this
542
+ if (leadingcmdblockarg && leadingcmdblockarg.case === 'protect') delete leadingcmdblockarg.case
543
+
544
+ // \sl, \it etc
545
+ if (markup[leadingcmd.command]) {
546
+ block.markup[markup[leadingcmd.command]] = true
547
+ block.value.shift()
650
548
  }
651
- };
652
- var peg$f49 = function(cmd) { return (has_arguments[cmd] === 1) };
653
- var peg$f50 = function(cmd, optional, req) {
654
- let m
655
- if (req.kind === 'Block') {
656
- switch (cmd) {
657
- case 'textsuperscript':
658
- case 'sp':
659
- req.markup.sup = true
660
- break
661
- case 'textsubscript':
662
- case 'sb':
663
- req.markup.sub = true
664
- break
665
- case 'textsc':
666
- req.markup.smallCaps = true
667
- break
668
- case 'enquote':
669
- case 'mkbibquote':
670
- req.markup.enquote = true
671
- break
672
- case 'textbf':
673
- case 'mkbibbold':
674
- req.markup.bold = true
675
- break
676
- case 'emph':
677
- case 'textit':
678
- case 'mkbibitalic':
679
- case 'mkbibemph':
680
- req.markup.italics = true
681
- break
682
- default:
683
- if (m = cmd.match(/^((sub)*)section$/)) {
684
- req.markup[`h${(m[1].length / 3) + 1}`] = true
685
- }
686
- }
549
+ }
550
+
551
+ return handle_markup_switches(block)
552
+ };
553
+ var peg$f38 = function() { return !math.on };
554
+ var peg$f39 = function(mode) { return math.set(true) };
555
+ var peg$f40 = function(mode, v) { return math.set(false) };
556
+ var peg$f41 = function(mode, v) {
557
+ return {
558
+ kind: mode == '$$' ? 'DisplayMath' : 'InlineMath',
559
+ loc: location(),
560
+ source: text(),
561
+ value: v,
562
+ case: 'protect',
563
+ markup: {},
564
+ }
565
+ };
566
+ var peg$f42 = function(v) {
567
+ return {
568
+ kind: 'LineComment',
569
+ loc: location(),
570
+ source: text(),
571
+ value: v,
572
+ }
573
+ };
574
+ var peg$f43 = function(mode, v) {
575
+ if (v.kind === 'Block') v = v.value
576
+
577
+ return {
578
+ kind: mode === '_' ? 'SubscriptCommand' : 'SuperscriptCommand',
579
+ loc: location(),
580
+ source: text(),
581
+ value: v,
582
+ }
583
+ };
584
+ var peg$f44 = function(mark, char) {
585
+ return {
586
+ kind: 'DiacriticCommand',
587
+ loc: location(),
588
+ source: text(),
589
+ mark: mark,
590
+ dotless: !!char[1],
591
+ character: char[1] || char[0],
592
+ }
593
+ };
594
+ var peg$f45 = function(mark, char) {
595
+ return {
596
+ kind: 'DiacriticCommand',
597
+ loc: location(),
598
+ source: text(),
599
+ mark: mark,
600
+ dotless: !!char[1],
601
+ character: char[1] || char[0],
602
+ }
603
+ };
604
+ var peg$f46 = function(mark, v) {
605
+ return {
606
+ kind: 'RegularCommand',
607
+ loc: location(),
608
+ source: text(),
609
+ command: mark,
610
+ arguments: {
611
+ optional: [],
612
+ required: [ protect(v) ],
613
+ },
614
+ }
615
+ };
616
+ var peg$f47 = function(v) {
617
+ return {
618
+ kind: 'SymbolCommand',
619
+ loc: location(),
620
+ source: text(),
621
+ command: v,
622
+ }
623
+ };
624
+ var peg$f48 = function(cmd, name) { return name.value.length == 1 && name.value[0].kind === 'RegularCommand' };
625
+ var peg$f49 = function(cmd, name, optional, def) {
626
+ return {
627
+ kind: 'RegularCommand',
628
+ loc: location(),
629
+ source: text(),
630
+ command: cmd,
631
+ arguments: {
632
+ optional: [],
633
+ required: [name, def],
634
+ },
635
+ }
636
+ };
637
+ var peg$f50 = function(cmd, url, label) {
638
+ return {
639
+ kind: 'RegularCommand',
640
+ loc: location(),
641
+ source: text(),
642
+ command: cmd,
643
+ arguments: {
644
+ optional: [],
645
+ required: [url, label],
646
+ },
647
+ }
648
+ };
649
+ var peg$f51 = function(cmd) { return verbatimCommands.includes(cmd) && (has_arguments[cmd] === 2) };
650
+ var peg$f52 = function(cmd, optional, req1, req2) {
651
+ return {
652
+ kind: 'RegularCommand',
653
+ loc: location(),
654
+ source: text(),
655
+ command: cmd,
656
+ arguments: {
657
+ optional: optional,
658
+ required: [protect(req1), protect(req2)],
659
+ },
660
+ }
661
+ };
662
+ var peg$f53 = function(cmd) { return verbatimCommands.includes(cmd) && (has_arguments[cmd] === 1) };
663
+ var peg$f54 = function(cmd, optional, req) {
664
+ return {
665
+ kind: 'RegularCommand',
666
+ loc: location(),
667
+ source: text(),
668
+ command: cmd,
669
+ arguments: {
670
+ optional: optional,
671
+ required: [protect(req)],
672
+ },
673
+ }
674
+ };
675
+ var peg$f55 = function(cmd) { return (has_arguments[cmd] === 2) };
676
+ var peg$f56 = function(cmd, optional, req1, req2) {
677
+ return {
678
+ kind: 'RegularCommand',
679
+ loc: location(),
680
+ source: text(),
681
+ command: cmd,
682
+ arguments: {
683
+ optional: optional,
684
+ required: [req1, req2],
685
+ },
686
+ }
687
+ };
688
+ var peg$f57 = function(cmd) { return (has_arguments[cmd] === 1) };
689
+ var peg$f58 = function(cmd, optional, req) {
690
+ let m
691
+ if (req.kind === 'Block') {
692
+ switch (cmd) {
693
+ case 'textsuperscript':
694
+ case 'sp':
695
+ req.markup.sup = true
696
+ break
697
+ case 'textsubscript':
698
+ case 'sb':
699
+ req.markup.sub = true
700
+ break
701
+ case 'textsc':
702
+ req.markup.smallCaps = true
703
+ break
704
+ case 'enquote':
705
+ case 'mkbibquote':
706
+ req.markup.enquote = true
707
+ break
708
+ case 'textbf':
709
+ case 'mkbibbold':
710
+ req.markup.bold = true
711
+ break
712
+ case 'emph':
713
+ case 'textit':
714
+ case 'mkbibitalic':
715
+ case 'mkbibemph':
716
+ req.markup.italics = true
717
+ break
718
+ default:
719
+ if (m = cmd.match(/^((sub)*)section$/)) {
720
+ req.markup[`h${(m[1].length / 3) + 1}`] = true
721
+ }
687
722
  }
723
+ }
688
724
 
689
- // ignore case stuff on bibcyr
690
- if (cmd === 'bibcyr') delete req.case
725
+ // ignore case stuff on bibcyr
726
+ if (cmd === 'bibcyr') delete req.case
691
727
 
692
- return {
693
- kind: 'RegularCommand',
694
- loc: location(),
695
- source: text(),
696
- command: cmd,
697
- arguments: {
698
- optional: optional,
699
- required: [req],
700
- }
728
+ return {
729
+ kind: 'RegularCommand',
730
+ loc: location(),
731
+ source: text(),
732
+ command: cmd,
733
+ arguments: {
734
+ optional: optional,
735
+ required: [req],
701
736
  }
702
- };
703
- var peg$f51 = function(cmd, optional) {
704
- return {
705
- kind: 'RegularCommand',
706
- loc: location(),
707
- source: text(),
708
- command: cmd,
709
- arguments: {
710
- optional: optional,
711
- required: [],
712
- }
737
+ }
738
+ };
739
+ var peg$f59 = function(cmd, optional) {
740
+ return {
741
+ kind: 'RegularCommand',
742
+ loc: location(),
743
+ source: text(),
744
+ command: cmd,
745
+ arguments: {
746
+ optional: optional,
747
+ required: [],
713
748
  }
714
- };
715
- var peg$f52 = function(v) {
716
- return basicTextConversions({
717
- kind: 'Text', // this isn't really correct but I don't need these right now
718
- loc: location(),
719
- source: text(),
720
- value: v,
721
- mode: math.on ? 'math' : 'text',
722
- })
723
- };
724
- var peg$f53 = function(v) {
725
- return basicTextConversions({
726
- kind: 'Text',
727
- loc: location(),
728
- source: text(),
729
- value: normalizeWhitespace([v]),
730
- mode: math.on ? 'math' : 'text',
731
- })
732
- };
733
-
749
+ }
750
+ };
751
+ var peg$f60 = function(v) {
752
+ return basicTextConversions({
753
+ kind: 'Text', // this isn't really correct but I don't need these right now
754
+ loc: location(),
755
+ source: text(),
756
+ value: v,
757
+ mode: math.on ? 'math' : 'text',
758
+ })
759
+ };
760
+ var peg$f61 = function(v) {
761
+ return basicTextConversions({
762
+ kind: 'Text',
763
+ loc: location(),
764
+ source: text(),
765
+ value: normalizeWhitespace([v]),
766
+ mode: math.on ? 'math' : 'text',
767
+ })
768
+ };
769
+ var peg$f62 = function(v) { return v };
734
770
  var peg$currPos = 0;
735
771
  var peg$savedPos = 0;
736
772
  var peg$posDetailsCache = [{ line: 1, column: 1 }];
@@ -1852,7 +1888,7 @@ function peg$parse(input, options) {
1852
1888
  }
1853
1889
  if (s1 !== peg$FAILED) {
1854
1890
  peg$savedPos = s0;
1855
- s1 = peg$f18(s1);
1891
+ s1 = peg$f20(s1);
1856
1892
  }
1857
1893
  s0 = s1;
1858
1894
  if (s0 === peg$FAILED) {
@@ -1882,7 +1918,7 @@ function peg$parse(input, options) {
1882
1918
  }
1883
1919
  if (s3 !== peg$FAILED) {
1884
1920
  peg$savedPos = s0;
1885
- s0 = peg$f19(s2);
1921
+ s0 = peg$f21(s2);
1886
1922
  } else {
1887
1923
  peg$currPos = s0;
1888
1924
  s0 = peg$FAILED;
@@ -1903,7 +1939,7 @@ function peg$parse(input, options) {
1903
1939
  if (s0 === peg$FAILED) {
1904
1940
  s0 = peg$currPos;
1905
1941
  peg$savedPos = peg$currPos;
1906
- s1 = peg$f20();
1942
+ s1 = peg$f22();
1907
1943
  if (s1) {
1908
1944
  s1 = undefined;
1909
1945
  } else {
@@ -1923,7 +1959,7 @@ function peg$parse(input, options) {
1923
1959
  }
1924
1960
  }
1925
1961
  peg$savedPos = s0;
1926
- s0 = peg$f21(s2);
1962
+ s0 = peg$f23(s2);
1927
1963
  } else {
1928
1964
  peg$currPos = s0;
1929
1965
  s0 = peg$FAILED;
@@ -1988,7 +2024,7 @@ function peg$parse(input, options) {
1988
2024
  s4 = null;
1989
2025
  }
1990
2026
  peg$savedPos = s0;
1991
- s0 = peg$f22(s2);
2027
+ s0 = peg$f24(s2);
1992
2028
  } else {
1993
2029
  peg$currPos = s0;
1994
2030
  s0 = peg$FAILED;
@@ -2043,7 +2079,7 @@ function peg$parse(input, options) {
2043
2079
  s5 = null;
2044
2080
  }
2045
2081
  peg$savedPos = s0;
2046
- s0 = peg$f23(s3);
2082
+ s0 = peg$f25(s3);
2047
2083
  } else {
2048
2084
  peg$currPos = s0;
2049
2085
  s0 = peg$FAILED;
@@ -2109,7 +2145,7 @@ function peg$parse(input, options) {
2109
2145
  s4 = null;
2110
2146
  }
2111
2147
  peg$savedPos = s0;
2112
- s0 = peg$f22(s2);
2148
+ s0 = peg$f26(s2);
2113
2149
  } else {
2114
2150
  peg$currPos = s0;
2115
2151
  s0 = peg$FAILED;
@@ -2127,7 +2163,7 @@ function peg$parse(input, options) {
2127
2163
  s2 = null;
2128
2164
  }
2129
2165
  peg$savedPos = s0;
2130
- s0 = peg$f22(s1);
2166
+ s0 = peg$f27(s1);
2131
2167
  } else {
2132
2168
  peg$currPos = s0;
2133
2169
  s0 = peg$FAILED;
@@ -2150,7 +2186,7 @@ function peg$parse(input, options) {
2150
2186
  s2 = null;
2151
2187
  }
2152
2188
  peg$savedPos = s0;
2153
- s0 = peg$f22(s1);
2189
+ s0 = peg$f28(s1);
2154
2190
  } else {
2155
2191
  peg$currPos = s0;
2156
2192
  s0 = peg$FAILED;
@@ -2187,7 +2223,7 @@ function peg$parse(input, options) {
2187
2223
  }
2188
2224
  if (s1 !== peg$FAILED) {
2189
2225
  peg$savedPos = s0;
2190
- s1 = peg$f24(s1);
2226
+ s1 = peg$f29(s1);
2191
2227
  }
2192
2228
  s0 = s1;
2193
2229
 
@@ -2222,7 +2258,7 @@ function peg$parse(input, options) {
2222
2258
  }
2223
2259
  if (s1 !== peg$FAILED) {
2224
2260
  peg$savedPos = s0;
2225
- s1 = peg$f24(s1);
2261
+ s1 = peg$f30(s1);
2226
2262
  }
2227
2263
  s0 = s1;
2228
2264
 
@@ -2263,7 +2299,7 @@ function peg$parse(input, options) {
2263
2299
  }
2264
2300
  if (s1 !== peg$FAILED) {
2265
2301
  peg$savedPos = s0;
2266
- s1 = peg$f25(s1);
2302
+ s1 = peg$f31(s1);
2267
2303
  }
2268
2304
  s0 = s1;
2269
2305
 
@@ -2277,7 +2313,7 @@ function peg$parse(input, options) {
2277
2313
  s1 = peg$parseVariableName();
2278
2314
  if (s1 !== peg$FAILED) {
2279
2315
  peg$savedPos = s0;
2280
- s1 = peg$f26(s1);
2316
+ s1 = peg$f32(s1);
2281
2317
  }
2282
2318
  s0 = s1;
2283
2319
 
@@ -2409,7 +2445,7 @@ function peg$parse(input, options) {
2409
2445
  }
2410
2446
  if (s7 !== peg$FAILED) {
2411
2447
  peg$savedPos = peg$currPos;
2412
- s8 = peg$f27(s2, s4, s6);
2448
+ s8 = peg$f33(s2, s4, s6);
2413
2449
  if (s8) {
2414
2450
  s8 = undefined;
2415
2451
  } else {
@@ -2417,7 +2453,7 @@ function peg$parse(input, options) {
2417
2453
  }
2418
2454
  if (s8 !== peg$FAILED) {
2419
2455
  peg$savedPos = s0;
2420
- s0 = peg$f28(s2, s4, s6);
2456
+ s0 = peg$f34(s2, s4, s6);
2421
2457
  } else {
2422
2458
  peg$currPos = s0;
2423
2459
  s0 = peg$FAILED;
@@ -2511,7 +2547,7 @@ function peg$parse(input, options) {
2511
2547
  }
2512
2548
  if (s5 !== peg$FAILED) {
2513
2549
  peg$savedPos = s0;
2514
- s0 = peg$f29(s2, s4);
2550
+ s0 = peg$f35(s2, s4);
2515
2551
  } else {
2516
2552
  peg$currPos = s0;
2517
2553
  s0 = peg$FAILED;
@@ -2570,7 +2606,7 @@ function peg$parse(input, options) {
2570
2606
  }
2571
2607
  if (s4 !== peg$FAILED) {
2572
2608
  peg$savedPos = s0;
2573
- s0 = peg$f30(s3);
2609
+ s0 = peg$f36(s3);
2574
2610
  } else {
2575
2611
  peg$currPos = s0;
2576
2612
  s0 = peg$FAILED;
@@ -2632,7 +2668,7 @@ function peg$parse(input, options) {
2632
2668
  }
2633
2669
  if (s3 !== peg$FAILED) {
2634
2670
  peg$savedPos = s0;
2635
- s0 = peg$f31(s2);
2671
+ s0 = peg$f37(s2);
2636
2672
  } else {
2637
2673
  peg$currPos = s0;
2638
2674
  s0 = peg$FAILED;
@@ -2652,7 +2688,7 @@ function peg$parse(input, options) {
2652
2688
 
2653
2689
  s0 = peg$currPos;
2654
2690
  peg$savedPos = peg$currPos;
2655
- s1 = peg$f32();
2691
+ s1 = peg$f38();
2656
2692
  if (s1) {
2657
2693
  s1 = undefined;
2658
2694
  } else {
@@ -2686,7 +2722,7 @@ function peg$parse(input, options) {
2686
2722
  }
2687
2723
  if (s2 !== peg$FAILED) {
2688
2724
  peg$savedPos = peg$currPos;
2689
- s3 = peg$f33(s2);
2725
+ s3 = peg$f39(s2);
2690
2726
  if (s3) {
2691
2727
  s3 = undefined;
2692
2728
  } else {
@@ -2738,7 +2774,7 @@ function peg$parse(input, options) {
2738
2774
  }
2739
2775
  if (s5 !== peg$FAILED) {
2740
2776
  peg$savedPos = peg$currPos;
2741
- s6 = peg$f34(s2, s4);
2777
+ s6 = peg$f40(s2, s4);
2742
2778
  if (s6) {
2743
2779
  s6 = undefined;
2744
2780
  } else {
@@ -2746,7 +2782,7 @@ function peg$parse(input, options) {
2746
2782
  }
2747
2783
  if (s6 !== peg$FAILED) {
2748
2784
  peg$savedPos = s0;
2749
- s0 = peg$f35(s2, s4);
2785
+ s0 = peg$f41(s2, s4);
2750
2786
  } else {
2751
2787
  peg$currPos = s0;
2752
2788
  s0 = peg$FAILED;
@@ -2825,7 +2861,7 @@ function peg$parse(input, options) {
2825
2861
  }
2826
2862
  if (s4 !== peg$FAILED) {
2827
2863
  peg$savedPos = s0;
2828
- s0 = peg$f36(s3);
2864
+ s0 = peg$f42(s3);
2829
2865
  } else {
2830
2866
  peg$currPos = s0;
2831
2867
  s0 = peg$FAILED;
@@ -2875,7 +2911,7 @@ function peg$parse(input, options) {
2875
2911
  s3 = peg$parseArgument();
2876
2912
  if (s3 !== peg$FAILED) {
2877
2913
  peg$savedPos = s0;
2878
- s0 = peg$f37(s1, s3);
2914
+ s0 = peg$f43(s1, s3);
2879
2915
  } else {
2880
2916
  peg$currPos = s0;
2881
2917
  s0 = peg$FAILED;
@@ -2941,7 +2977,7 @@ function peg$parse(input, options) {
2941
2977
  }
2942
2978
  if (s4 !== peg$FAILED) {
2943
2979
  peg$savedPos = s0;
2944
- s0 = peg$f29(s2, s4);
2980
+ s0 = peg$f44(s2, s4);
2945
2981
  } else {
2946
2982
  peg$currPos = s0;
2947
2983
  s0 = peg$FAILED;
@@ -3020,7 +3056,7 @@ function peg$parse(input, options) {
3020
3056
  }
3021
3057
  if (s5 !== peg$FAILED) {
3022
3058
  peg$savedPos = s0;
3023
- s0 = peg$f29(s2, s4);
3059
+ s0 = peg$f45(s2, s4);
3024
3060
  } else {
3025
3061
  peg$currPos = s0;
3026
3062
  s0 = peg$FAILED;
@@ -3073,7 +3109,7 @@ function peg$parse(input, options) {
3073
3109
  s4 = peg$parseRegularValue();
3074
3110
  if (s4 !== peg$FAILED) {
3075
3111
  peg$savedPos = s0;
3076
- s0 = peg$f38(s2, s4);
3112
+ s0 = peg$f46(s2, s4);
3077
3113
  } else {
3078
3114
  peg$currPos = s0;
3079
3115
  s0 = peg$FAILED;
@@ -3123,7 +3159,7 @@ function peg$parse(input, options) {
3123
3159
  }
3124
3160
  if (s2 !== peg$FAILED) {
3125
3161
  peg$savedPos = s0;
3126
- s0 = peg$f39(s2);
3162
+ s0 = peg$f47(s2);
3127
3163
  } else {
3128
3164
  peg$currPos = s0;
3129
3165
  s0 = peg$FAILED;
@@ -3159,7 +3195,7 @@ function peg$parse(input, options) {
3159
3195
  s3 = peg$parseBlock();
3160
3196
  if (s3 !== peg$FAILED) {
3161
3197
  peg$savedPos = peg$currPos;
3162
- s4 = peg$f40(s2, s3);
3198
+ s4 = peg$f48(s2, s3);
3163
3199
  if (s4) {
3164
3200
  s4 = undefined;
3165
3201
  } else {
@@ -3175,7 +3211,7 @@ function peg$parse(input, options) {
3175
3211
  s6 = peg$parseArgument();
3176
3212
  if (s6 !== peg$FAILED) {
3177
3213
  peg$savedPos = s0;
3178
- s0 = peg$f41(s2, s3, s5, s6);
3214
+ s0 = peg$f49(s2, s3, s5, s6);
3179
3215
  } else {
3180
3216
  peg$currPos = s0;
3181
3217
  s0 = peg$FAILED;
@@ -3237,7 +3273,7 @@ function peg$parse(input, options) {
3237
3273
  s6 = peg$parseArgument();
3238
3274
  if (s6 !== peg$FAILED) {
3239
3275
  peg$savedPos = s0;
3240
- s0 = peg$f42(s2, s5, s6);
3276
+ s0 = peg$f50(s2, s5, s6);
3241
3277
  } else {
3242
3278
  peg$currPos = s0;
3243
3279
  s0 = peg$FAILED;
@@ -3332,7 +3368,7 @@ function peg$parse(input, options) {
3332
3368
  }
3333
3369
  if (s4 !== peg$FAILED) {
3334
3370
  peg$savedPos = peg$currPos;
3335
- s5 = peg$f43(s4);
3371
+ s5 = peg$f51(s4);
3336
3372
  if (s5) {
3337
3373
  s5 = undefined;
3338
3374
  } else {
@@ -3368,7 +3404,7 @@ function peg$parse(input, options) {
3368
3404
  s10 = peg$parseVerbatimFieldValue();
3369
3405
  if (s10 !== peg$FAILED) {
3370
3406
  peg$savedPos = s0;
3371
- s0 = peg$f44(s4, s6, s9, s10);
3407
+ s0 = peg$f52(s4, s6, s9, s10);
3372
3408
  } else {
3373
3409
  peg$currPos = s0;
3374
3410
  s0 = peg$FAILED;
@@ -3475,7 +3511,7 @@ function peg$parse(input, options) {
3475
3511
  }
3476
3512
  if (s4 !== peg$FAILED) {
3477
3513
  peg$savedPos = peg$currPos;
3478
- s5 = peg$f45(s4);
3514
+ s5 = peg$f53(s4);
3479
3515
  if (s5) {
3480
3516
  s5 = undefined;
3481
3517
  } else {
@@ -3509,7 +3545,7 @@ function peg$parse(input, options) {
3509
3545
  s9 = peg$parseVerbatimFieldValue();
3510
3546
  if (s9 !== peg$FAILED) {
3511
3547
  peg$savedPos = s0;
3512
- s0 = peg$f46(s4, s6, s9);
3548
+ s0 = peg$f54(s4, s6, s9);
3513
3549
  } else {
3514
3550
  peg$currPos = s0;
3515
3551
  s0 = peg$FAILED;
@@ -3612,7 +3648,7 @@ function peg$parse(input, options) {
3612
3648
  }
3613
3649
  if (s4 !== peg$FAILED) {
3614
3650
  peg$savedPos = peg$currPos;
3615
- s5 = peg$f47(s4);
3651
+ s5 = peg$f55(s4);
3616
3652
  if (s5) {
3617
3653
  s5 = undefined;
3618
3654
  } else {
@@ -3631,7 +3667,7 @@ function peg$parse(input, options) {
3631
3667
  s9 = peg$parseArgument();
3632
3668
  if (s9 !== peg$FAILED) {
3633
3669
  peg$savedPos = s0;
3634
- s0 = peg$f48(s4, s6, s8, s9);
3670
+ s0 = peg$f56(s4, s6, s8, s9);
3635
3671
  } else {
3636
3672
  peg$currPos = s0;
3637
3673
  s0 = peg$FAILED;
@@ -3734,7 +3770,7 @@ function peg$parse(input, options) {
3734
3770
  }
3735
3771
  if (s4 !== peg$FAILED) {
3736
3772
  peg$savedPos = peg$currPos;
3737
- s5 = peg$f49(s4);
3773
+ s5 = peg$f57(s4);
3738
3774
  if (s5) {
3739
3775
  s5 = undefined;
3740
3776
  } else {
@@ -3751,7 +3787,7 @@ function peg$parse(input, options) {
3751
3787
  s8 = peg$parseArgument();
3752
3788
  if (s8 !== peg$FAILED) {
3753
3789
  peg$savedPos = s0;
3754
- s0 = peg$f50(s4, s6, s8);
3790
+ s0 = peg$f58(s4, s6, s8);
3755
3791
  } else {
3756
3792
  peg$currPos = s0;
3757
3793
  s0 = peg$FAILED;
@@ -3857,7 +3893,7 @@ function peg$parse(input, options) {
3857
3893
  }
3858
3894
  s6 = peg$parse__();
3859
3895
  peg$savedPos = s0;
3860
- s0 = peg$f51(s4, s5);
3896
+ s0 = peg$f59(s4, s5);
3861
3897
  } else {
3862
3898
  peg$currPos = s0;
3863
3899
  s0 = peg$FAILED;
@@ -3936,7 +3972,7 @@ function peg$parse(input, options) {
3936
3972
  }
3937
3973
  if (s5 !== peg$FAILED) {
3938
3974
  peg$savedPos = s0;
3939
- s0 = peg$f52(s3);
3975
+ s0 = peg$f60(s3);
3940
3976
  } else {
3941
3977
  peg$currPos = s0;
3942
3978
  s0 = peg$FAILED;
@@ -3967,7 +4003,7 @@ function peg$parse(input, options) {
3967
4003
  }
3968
4004
  if (s2 !== peg$FAILED) {
3969
4005
  peg$savedPos = s0;
3970
- s0 = peg$f53(s2);
4006
+ s0 = peg$f61(s2);
3971
4007
  } else {
3972
4008
  peg$currPos = s0;
3973
4009
  s0 = peg$FAILED;
@@ -3980,7 +4016,7 @@ function peg$parse(input, options) {
3980
4016
  }
3981
4017
  if (s1 !== peg$FAILED) {
3982
4018
  peg$savedPos = s0;
3983
- s1 = peg$f18(s1);
4019
+ s1 = peg$f62(s1);
3984
4020
  }
3985
4021
  s0 = s1;
3986
4022
  }
@@ -4351,249 +4387,248 @@ function peg$parse(input, options) {
4351
4387
  }
4352
4388
 
4353
4389
 
4354
- /*
4355
- MIT License
4390
+ /*
4391
+ MIT License
4356
4392
 
4357
- Copyright (c) 2017 Derek P Sifford, parts copyright (c) 2019 by Emiliano Heyns
4393
+ Copyright (c) 2017 Derek P Sifford, parts copyright (c) 2019 by Emiliano Heyns
4358
4394
 
4359
- Permission is hereby granted, free of charge, to any person obtaining a copy
4360
- of this software and associated documentation files (the "Software"), to deal
4361
- in the Software without restriction, including without limitation the rights
4362
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
4363
- copies of the Software, and to permit persons to whom the Software is
4364
- furnished to do so, subject to the following conditions:
4395
+ Permission is hereby granted, free of charge, to any person obtaining a copy
4396
+ of this software and associated documentation files (the "Software"), to deal
4397
+ in the Software without restriction, including without limitation the rights
4398
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
4399
+ copies of the Software, and to permit persons to whom the Software is
4400
+ furnished to do so, subject to the following conditions:
4365
4401
 
4366
- The above copyright notice and this permission notice shall be included in all
4367
- copies or substantial portions of the Software.
4402
+ The above copyright notice and this permission notice shall be included in all
4403
+ copies or substantial portions of the Software.
4368
4404
 
4369
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
4370
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
4371
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
4372
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
4373
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
4374
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
4375
- SOFTWARE.
4376
- */
4405
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
4406
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
4407
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
4408
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
4409
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
4410
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
4411
+ SOFTWARE.
4412
+ */
4377
4413
 
4378
- const markup = {
4379
- sl: 'italics',
4380
- em: 'italics',
4381
- it: 'italics',
4382
- itshape: 'italics',
4414
+ const markup = {
4415
+ sl: 'italics',
4416
+ em: 'italics',
4417
+ it: 'italics',
4418
+ itshape: 'italics',
4383
4419
 
4384
- bf: 'bold',
4385
- bfseries: 'bold',
4420
+ bf: 'bold',
4421
+ bfseries: 'bold',
4386
4422
 
4387
- sc: 'smallCaps',
4388
- scshape: 'smallCaps',
4423
+ sc: 'smallCaps',
4424
+ scshape: 'smallCaps',
4389
4425
 
4390
- tt: 'fixedWidth',
4391
- texttt: 'fixedWidth',
4392
- rm: 'roman',
4393
- sf: 'sansSerif',
4394
- verb: 'verbatim',
4395
- }
4426
+ tt: 'fixedWidth',
4427
+ texttt: 'fixedWidth',
4428
+ rm: 'roman',
4429
+ sf: 'sansSerif',
4430
+ verb: 'verbatim',
4431
+ }
4396
4432
 
4397
- const unnestFields = (options.unnestFields || []).map(field => field.toLowerCase())
4398
- const verbatimFields = (options.verbatimFields || [ 'urlraw', 'url', 'doi', 'file', 'files', 'eprint', 'verba', 'verbb', 'verbc' ]).map(field => typeof field === 'string' ? field.toLowerCase() : field)
4399
- const verbatimCommands = (options.verbatimCommands || [ 'texttt', 'url' ])
4433
+ const unnestFields = (options.unnestFields || []).map(field => field.toLowerCase())
4434
+ const verbatimFields = (options.verbatimFields || [ 'urlraw', 'url', 'doi', 'file', 'files', 'eprint', 'verba', 'verbb', 'verbc' ]).map(field => typeof field === 'string' ? field.toLowerCase() : field)
4435
+ const verbatimCommands = (options.verbatimCommands || [ 'texttt', 'url' ])
4400
4436
 
4401
- function isVerbatimField(name) {
4402
- return verbatimFields.find(p => (typeof p === 'string') ? name === p : name.match(p))
4403
- }
4437
+ function isVerbatimField(name) {
4438
+ return verbatimFields.find(p => (typeof p === 'string') ? name === p : name.match(p))
4439
+ }
4404
4440
 
4405
- function normalizeWhitespace(textArr) {
4406
- if (typeof textArr === 'string') textArr = Array.from(textArr)
4441
+ function normalizeWhitespace(textArr) {
4442
+ if (typeof textArr === 'string') textArr = Array.from(textArr)
4407
4443
 
4408
- return textArr.reduce((prev, curr) => {
4409
- if (/\s/.test(curr)) {
4410
- if (/\s/.test(prev[prev.length - 1])) {
4411
- return prev;
4412
- } else {
4413
- return prev + ' ';
4414
- }
4444
+ return textArr.reduce((prev, curr) => {
4445
+ if (/\s/.test(curr)) {
4446
+ if (/\s/.test(prev[prev.length - 1])) {
4447
+ return prev;
4448
+ } else {
4449
+ return prev + ' ';
4415
4450
  }
4416
- return prev + curr;
4417
- }, '');
4418
- }
4419
-
4420
- const has_arguments = {
4421
- ElsevierGlyph: 1,
4422
- end: 1,
4423
- begin: 1,
4424
- bibcyr: 1,
4425
- bibstring: 1,
4426
- chsf: 1,
4427
- cite: 1,
4428
- cyrchar: 1,
4429
- ding: 1,
4430
- emph: 1,
4431
- enquote: 1,
4432
- frac: 2,
4433
- href: 2,
4434
- hspace: 1,
4435
- mathrm: 1,
4436
- mbox: 1,
4437
- mkbibbold: 1,
4438
- mkbibemph: 1,
4439
- mkbibitalic: 1,
4440
- mkbibquote: 1,
4441
- newcommand: 2,
4442
- noopsort: 1,
4443
- ocirc: 1,
4444
- section: 1,
4445
- sb: 1,
4446
- sp: 1,
4447
- subsection: 1,
4448
- subsubsection: 1,
4449
- subsubsubsection: 1,
4450
- t: 1,
4451
- textbf: 1,
4452
- textit: 1,
4453
- textrm: 1,
4454
- textsc: 1,
4455
- textsubscript: 1,
4456
- textsuperscript: 1,
4457
- texttt: 1,
4458
- url: 1,
4459
- vphantom: 1,
4460
- vspace: 1,
4461
- }
4462
-
4463
- if (options.combiningDiacritics) {
4464
- for (const cmd of options.combiningDiacritics) {
4465
- has_arguments[cmd] = 1
4466
4451
  }
4467
- }
4452
+ return prev + curr;
4453
+ }, '');
4454
+ }
4468
4455
 
4469
- function say() {
4470
- console.log(JSON.stringify(Array.from(arguments), null, 2))
4471
- return true
4472
- }
4456
+ const has_arguments = {
4457
+ ElsevierGlyph: 1,
4458
+ end: 1,
4459
+ begin: 1,
4460
+ bibcyr: 1,
4461
+ bibstring: 1,
4462
+ chsf: 1,
4463
+ cite: 1,
4464
+ cyrchar: 1,
4465
+ ding: 1,
4466
+ emph: 1,
4467
+ enquote: 1,
4468
+ frac: 2,
4469
+ href: 2,
4470
+ hspace: 1,
4471
+ mathrm: 1,
4472
+ mbox: 1,
4473
+ mkbibbold: 1,
4474
+ mkbibemph: 1,
4475
+ mkbibitalic: 1,
4476
+ mkbibquote: 1,
4477
+ newcommand: 2,
4478
+ noopsort: 1,
4479
+ ocirc: 1,
4480
+ section: 1,
4481
+ sb: 1,
4482
+ sp: 1,
4483
+ subsection: 1,
4484
+ subsubsection: 1,
4485
+ subsubsubsection: 1,
4486
+ t: 1,
4487
+ textbf: 1,
4488
+ textit: 1,
4489
+ textrm: 1,
4490
+ textsc: 1,
4491
+ textsubscript: 1,
4492
+ textsuperscript: 1,
4493
+ texttt: 1,
4494
+ url: 1,
4495
+ vphantom: 1,
4496
+ vspace: 1,
4497
+ }
4473
4498
 
4474
- function peek(n) {
4475
- return input.substr(peg$savedPos, n)
4499
+ if (options.combiningDiacritics) {
4500
+ for (const cmd of options.combiningDiacritics) {
4501
+ has_arguments[cmd] = 1
4476
4502
  }
4503
+ }
4477
4504
 
4478
- const math = {
4479
- on: false,
4505
+ function say() {
4506
+ console.log(JSON.stringify(Array.from(arguments), null, 2))
4507
+ return true
4508
+ }
4480
4509
 
4481
- set: function(state) {
4482
- this.on = state
4483
- return true
4484
- }
4485
- }
4510
+ function peek(n) {
4511
+ return input.substr(peg$savedPos, n)
4512
+ }
4486
4513
 
4487
- function basicTextConversions(node) {
4488
- if (node.kind !== 'Text') throw new Error(node.kind + ' is not a Text node')
4514
+ const math = {
4515
+ on: false,
4489
4516
 
4490
- switch (node.mode) {
4491
- case 'verbatim':
4492
- break
4517
+ set: function(state) {
4518
+ this.on = state
4519
+ return true
4520
+ }
4521
+ }
4493
4522
 
4494
- case 'math':
4495
- node.value = node.value.replace(/~/g, '\u00A0')
4496
- break
4523
+ function basicTextConversions(node) {
4524
+ if (node.kind !== 'Text') throw new Error(node.kind + ' is not a Text node')
4497
4525
 
4498
- case 'text':
4499
- node.value = node.value
4500
- .replace(/---/g, '\u2014')
4501
- .replace(/--/g, '\u2013')
4502
- .replace(/</g, '\u00A1')
4503
- .replace(/>/g, '\u00BF')
4504
- .replace(/~/g, '\u00A0')
4505
- .replace(/``/g, options.markup.enquote.open)
4506
- .replace(/''/g, options.markup.enquote.close)
4507
- break
4526
+ switch (node.mode) {
4527
+ case 'verbatim':
4528
+ break
4508
4529
 
4509
- default:
4510
- throw new Error(`Unexpected text mode ${node.mode}`)
4511
- }
4530
+ case 'math':
4531
+ node.value = node.value.replace(/~/g, '\u00A0')
4532
+ break
4512
4533
 
4513
- return node
4534
+ case 'text':
4535
+ node.value = node.value
4536
+ .replace(/---/g, '\u2014')
4537
+ .replace(/--/g, '\u2013')
4538
+ .replace(/</g, '\u00A1')
4539
+ .replace(/>/g, '\u00BF')
4540
+ .replace(/~/g, '\u00A0')
4541
+ .replace(/``/g, options.markup.enquote.open)
4542
+ .replace(/''/g, options.markup.enquote.close)
4543
+ break
4544
+
4545
+ default:
4546
+ throw new Error(`Unexpected text mode ${node.mode}`)
4514
4547
  }
4515
4548
 
4516
- function protect(v) {
4517
- let source
4518
- if (Array.isArray(v)) {
4519
- source = v.map(e => e.source).join('')
4520
- } else {
4521
- v = [ v ]
4522
- source = v.source
4523
- }
4549
+ return node
4550
+ }
4524
4551
 
4525
- return {
4526
- kind: 'Block',
4527
- value: v,
4528
- markup: {},
4529
- case: 'protect',
4530
- source: source,
4531
- }
4552
+ function protect(v) {
4553
+ let source
4554
+ if (Array.isArray(v)) {
4555
+ source = v.map(e => e.source).join('')
4556
+ } else {
4557
+ v = [ v ]
4558
+ source = v.source
4532
4559
  }
4533
4560
 
4534
- function handle_markup_switches(block) {
4535
- const value = block.value
4536
- if (!Array.isArray(value)) return block
4561
+ return {
4562
+ kind: 'Block',
4563
+ value: v,
4564
+ markup: {},
4565
+ case: 'protect',
4566
+ source: source,
4567
+ }
4568
+ }
4537
4569
 
4538
- block.value = []
4570
+ function handle_markup_switches(block) {
4571
+ const value = block.value
4572
+ if (!Array.isArray(value)) return block
4539
4573
 
4540
- const pseudo = {
4541
- block: null,
4542
- markup: {},
4543
- }
4544
- function pseudo_block() {
4545
- pseudo.block = {
4546
- kind: 'Block',
4547
- loc: location(),
4548
- source: '',
4549
- value: [],
4550
- markup: JSON.parse(JSON.stringify(pseudo.markup)),
4551
- pseudo: true,
4552
- }
4553
- block.value.push(pseudo.block)
4574
+ block.value = []
4575
+
4576
+ const pseudo = {
4577
+ block: null,
4578
+ markup: {},
4579
+ }
4580
+ function pseudo_block() {
4581
+ pseudo.block = {
4582
+ kind: 'Block',
4583
+ loc: location(),
4584
+ source: '',
4585
+ value: [],
4586
+ markup: JSON.parse(JSON.stringify(pseudo.markup)),
4587
+ pseudo: true,
4554
4588
  }
4555
- for (const node of value) {
4556
- if (node.kind === 'Environment' || node.kind === 'Block') {
4557
- block.value.push(node)
4589
+ block.value.push(pseudo.block)
4590
+ }
4591
+ for (const node of value) {
4592
+ if (node.kind === 'Environment' || node.kind === 'Block') {
4593
+ block.value.push(node)
4558
4594
 
4559
- if (Object.keys(pseudo.markup).length) {
4560
- pseudo_block()
4561
- } else {
4562
- pseudo.block = null
4563
- }
4564
- continue
4595
+ if (Object.keys(pseudo.markup).length) {
4596
+ pseudo_block()
4597
+ } else {
4598
+ pseudo.block = null
4565
4599
  }
4600
+ continue
4601
+ }
4566
4602
 
4567
- if (node.kind === 'RegularCommand' && markup[node.command]) {
4568
- if (pseudo.markup.italics) { // https://github.com/citation-js/bibtex-parser-experiments/commit/cae475f075a05d1c074485a061b08ed245170c7e
4569
- delete pseudo.markup.italics
4570
- if (markup[node.command] !== 'italics') pseudo.markup[markup[node.command]] = true
4571
- } else {
4572
- pseudo.markup[markup[node.command]] = true
4573
- }
4574
-
4575
- if (Object.keys(pseudo.markup).length) {
4576
- pseudo_block()
4577
- } else {
4578
- pseudo.block = null
4579
- }
4603
+ if (node.kind === 'RegularCommand' && markup[node.command]) {
4604
+ if (pseudo.markup.italics) { // https://github.com/citation-js/bibtex-parser-experiments/commit/cae475f075a05d1c074485a061b08ed245170c7e
4605
+ delete pseudo.markup.italics
4606
+ if (markup[node.command] !== 'italics') pseudo.markup[markup[node.command]] = true
4607
+ } else {
4608
+ pseudo.markup[markup[node.command]] = true
4580
4609
  }
4581
4610
 
4582
- if (pseudo.block) {
4583
- pseudo.block.source += node.source
4584
- pseudo.block.value.push(node)
4585
-
4611
+ if (Object.keys(pseudo.markup).length) {
4612
+ pseudo_block()
4586
4613
  } else {
4587
- block.value.push(node)
4588
-
4614
+ pseudo.block = null
4589
4615
  }
4590
4616
  }
4591
4617
 
4592
- block.value = block.value.filter(node => !(node.pseudo && node.value.length === 0))
4618
+ if (pseudo.block) {
4619
+ pseudo.block.source += node.source
4620
+ pseudo.block.value.push(node)
4593
4621
 
4594
- return block
4622
+ } else {
4623
+ block.value.push(node)
4624
+
4625
+ }
4595
4626
  }
4596
4627
 
4628
+ block.value = block.value.filter(node => !(node.pseudo && node.value.length === 0))
4629
+
4630
+ return block
4631
+ }
4597
4632
 
4598
4633
  peg$result = peg$startRuleFunction();
4599
4634