n3 2.2.0 → 2.2.2

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/lib/N3Parser.js CHANGED
@@ -488,6 +488,11 @@ class N3Parser {
488
488
  if (!this._n3Mode) return this._error('Unexpected graph', token);
489
489
  this._saveContext('formula', this._graph, this._subject, this._predicate, this._graph = this._factory.blankNode());
490
490
  return this._readSubject;
491
+ case '<<(':
492
+ this._saveContext('<<(', this._graph, null, null, null);
493
+ this._graph = null;
494
+ next = this._readSubject;
495
+ break;
491
496
  case '<<':
492
497
  this._saveContext('<<', this._graph, null, null, null);
493
498
  this._graph = null;
@@ -500,8 +505,8 @@ class N3Parser {
500
505
  // Create a new blank node if no item head was assigned yet
501
506
  if (list === null) this._subject = list = this._factory.blankNode();
502
507
 
503
- // When reading a reified triple, store the list as subject in the stack, as this will be overridden when reading the triple.
504
- if (token.type === '<<') stack[stack.length - 1].subject = this._subject;
508
+ // When reading a reified triple or triple term, store the list as subject in the stack, as this will be overridden when reading the triple.
509
+ if (token.type === '<<' || token.type === '<<(') stack[stack.length - 1].subject = this._subject;
505
510
 
506
511
  // Is this the first element of the list?
507
512
  if (previousList === null) {
@@ -684,12 +689,17 @@ class N3Parser {
684
689
  break;
685
690
  // ~ is allowed in the annotation syntax
686
691
  case '~':
692
+ // Only invalidate the cache for a genuinely new triple - chained annotation blocks on the
693
+ // same triple (subject already null from a preceding annotation) must keep reusing it.
694
+ if (subject !== null) this._tripleTerm = null;
687
695
  next = this._readReifierInAnnotation;
688
696
  startingAnnotation = true;
689
697
  break;
690
698
  // {| means that the current triple is annotated with predicate-object pairs.
691
699
  case '{|':
692
700
  // Continue using the last triple as reified triple subject for the predicate-object pairs.
701
+ // Same staleness rule as ~ above.
702
+ if (subject !== null) this._tripleTerm = null;
693
703
  this._subject = this._readTripleTerm();
694
704
  this._validAnnotation = false;
695
705
  startingAnnotation = true;
@@ -929,6 +939,13 @@ class N3Parser {
929
939
  const quad = this._factory.quad(this._subject, this._predicate, this._object, this._graph || this.DEFAULTGRAPH);
930
940
  this._restoreContext('<<(', token);
931
941
 
942
+ // If we're in a list, continue processing that list
943
+ const stack = this._contextStack,
944
+ parent = stack.length && stack[stack.length - 1];
945
+ if (parent && parent.type === 'list') {
946
+ this._emit(this._subject, this.RDF_FIRST, quad, this._graph);
947
+ return this._getContextEndReader();
948
+ }
932
949
  // If the triple was the subject, continue by reading the predicate.
933
950
  if (this._subject === null) {
934
951
  this._subject = quad;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "n3",
3
- "version": "2.2.0",
3
+ "version": "2.2.2",
4
4
  "description": "Lightning fast, asynchronous, streaming Turtle / N3 / RDF library.",
5
5
  "author": "Ruben Verborgh <ruben.verborgh@gmail.com>",
6
6
  "keywords": [
package/src/N3Parser.js CHANGED
@@ -520,6 +520,11 @@ export default class N3Parser {
520
520
  this._saveContext('formula', this._graph, this._subject, this._predicate,
521
521
  this._graph = this._factory.blankNode());
522
522
  return this._readSubject;
523
+ case '<<(':
524
+ this._saveContext('<<(', this._graph, null, null, null);
525
+ this._graph = null;
526
+ next = this._readSubject;
527
+ break;
523
528
  case '<<':
524
529
  this._saveContext('<<', this._graph, null, null, null);
525
530
  this._graph = null;
@@ -534,8 +539,8 @@ export default class N3Parser {
534
539
  if (list === null)
535
540
  this._subject = list = this._factory.blankNode();
536
541
 
537
- // When reading a reified triple, store the list as subject in the stack, as this will be overridden when reading the triple.
538
- if (token.type === '<<')
542
+ // When reading a reified triple or triple term, store the list as subject in the stack, as this will be overridden when reading the triple.
543
+ if (token.type === '<<' || token.type === '<<(')
539
544
  stack[stack.length - 1].subject = this._subject;
540
545
 
541
546
  // Is this the first element of the list?
@@ -741,12 +746,19 @@ export default class N3Parser {
741
746
  break;
742
747
  // ~ is allowed in the annotation syntax
743
748
  case '~':
749
+ // Only invalidate the cache for a genuinely new triple - chained annotation blocks on the
750
+ // same triple (subject already null from a preceding annotation) must keep reusing it.
751
+ if (subject !== null)
752
+ this._tripleTerm = null;
744
753
  next = this._readReifierInAnnotation;
745
754
  startingAnnotation = true;
746
755
  break;
747
756
  // {| means that the current triple is annotated with predicate-object pairs.
748
757
  case '{|':
749
758
  // Continue using the last triple as reified triple subject for the predicate-object pairs.
759
+ // Same staleness rule as ~ above.
760
+ if (subject !== null)
761
+ this._tripleTerm = null;
750
762
  this._subject = this._readTripleTerm();
751
763
  this._validAnnotation = false;
752
764
  startingAnnotation = true;
@@ -1012,6 +1024,12 @@ export default class N3Parser {
1012
1024
  this._graph || this.DEFAULTGRAPH);
1013
1025
  this._restoreContext('<<(', token);
1014
1026
 
1027
+ // If we're in a list, continue processing that list
1028
+ const stack = this._contextStack, parent = stack.length && stack[stack.length - 1];
1029
+ if (parent && parent.type === 'list') {
1030
+ this._emit(this._subject, this.RDF_FIRST, quad, this._graph);
1031
+ return this._getContextEndReader();
1032
+ }
1015
1033
  // If the triple was the subject, continue by reading the predicate.
1016
1034
  if (this._subject === null) {
1017
1035
  this._subject = quad;