n3 2.2.2 → 2.2.3

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
@@ -1011,12 +1011,40 @@ class N3Parser {
1011
1011
  // If next token is a reifier, read it as such.
1012
1012
  if (token.type === 'IRI' || token.type === 'typeIRI' || token.type === 'type' || token.type === 'prefixed' || token.type === 'blank' || token.type === 'var') {
1013
1013
  this._reifier = this._readEntity(token);
1014
- return this._readPunctuation;
1014
+ return this._readAnnotationBlockOrPunctuation;
1015
1015
  }
1016
1016
  // Otherwise, emit and assert triple term.
1017
1017
  this._readTripleTerm();
1018
1018
  this._subject = null;
1019
- return this._readPunctuation(token);
1019
+ return this._getContextEndReader().call(this, token);
1020
+ }
1021
+
1022
+ // ### `_readAnnotationBlockOrPunctuation` reads what follows an explicit reifier:
1023
+ // either an annotation block, which reuses the reifier as its subject,
1024
+ // or punctuation, in which case the reifier stands alone and its triple
1025
+ // term still needs to be asserted here.
1026
+ _readAnnotationBlockOrPunctuation(token) {
1027
+ if (token.type === '{|') return this._readPunctuation(token);
1028
+ this._readTripleTerm();
1029
+ this._annotation = false;
1030
+ // A shared subject or predicate goes on to reify a *different* triple,
1031
+ // so the term just asserted must not be reused for the next one.
1032
+ this._tripleTerm = null;
1033
+ // The annotated triple was already emitted when the tilde was read,
1034
+ // so continue without letting `_readPunctuation` emit it a second time.
1035
+ switch (token.type) {
1036
+ // The subject stays shared with the next predicate-object pair
1037
+ case ';':
1038
+ return this._readPredicate;
1039
+ // The subject and predicate stay shared with the next object
1040
+ case ',':
1041
+ return this._readObject;
1042
+ default:
1043
+ this._subject = null;
1044
+ // Resume in the enclosing context, which is top-level punctuation
1045
+ // unless the reified triple sits inside a blank node property list
1046
+ return this._getContextEndReader().call(this, token);
1047
+ }
1020
1048
  }
1021
1049
  _readTripleTerm() {
1022
1050
  const stack = this._contextStack,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "n3",
3
- "version": "2.2.2",
3
+ "version": "2.2.3",
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
@@ -1096,12 +1096,42 @@ export default class N3Parser {
1096
1096
  // If next token is a reifier, read it as such.
1097
1097
  if (token.type === 'IRI' || token.type === 'typeIRI' || token.type === 'type' || token.type === 'prefixed' || token.type === 'blank' || token.type === 'var') {
1098
1098
  this._reifier = this._readEntity(token);
1099
- return this._readPunctuation;
1099
+ return this._readAnnotationBlockOrPunctuation;
1100
1100
  }
1101
1101
  // Otherwise, emit and assert triple term.
1102
1102
  this._readTripleTerm();
1103
1103
  this._subject = null;
1104
- return this._readPunctuation(token);
1104
+ return this._getContextEndReader().call(this, token);
1105
+ }
1106
+
1107
+ // ### `_readAnnotationBlockOrPunctuation` reads what follows an explicit reifier:
1108
+ // either an annotation block, which reuses the reifier as its subject,
1109
+ // or punctuation, in which case the reifier stands alone and its triple
1110
+ // term still needs to be asserted here.
1111
+ _readAnnotationBlockOrPunctuation(token) {
1112
+ if (token.type === '{|')
1113
+ return this._readPunctuation(token);
1114
+
1115
+ this._readTripleTerm();
1116
+ this._annotation = false;
1117
+ // A shared subject or predicate goes on to reify a *different* triple,
1118
+ // so the term just asserted must not be reused for the next one.
1119
+ this._tripleTerm = null;
1120
+ // The annotated triple was already emitted when the tilde was read,
1121
+ // so continue without letting `_readPunctuation` emit it a second time.
1122
+ switch (token.type) {
1123
+ // The subject stays shared with the next predicate-object pair
1124
+ case ';':
1125
+ return this._readPredicate;
1126
+ // The subject and predicate stay shared with the next object
1127
+ case ',':
1128
+ return this._readObject;
1129
+ default:
1130
+ this._subject = null;
1131
+ // Resume in the enclosing context, which is top-level punctuation
1132
+ // unless the reified triple sits inside a blank node property list
1133
+ return this._getContextEndReader().call(this, token);
1134
+ }
1105
1135
  }
1106
1136
 
1107
1137
  _readTripleTerm() {