n3 2.2.1 → 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/browser/n3.esm.min.js +1 -1
- package/browser/n3.min.js +1 -1
- package/lib/N3Parser.js +35 -2
- package/package.json +1 -1
- package/src/N3Parser.js +39 -2
package/lib/N3Parser.js
CHANGED
|
@@ -689,12 +689,17 @@ class N3Parser {
|
|
|
689
689
|
break;
|
|
690
690
|
// ~ is allowed in the annotation syntax
|
|
691
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;
|
|
692
695
|
next = this._readReifierInAnnotation;
|
|
693
696
|
startingAnnotation = true;
|
|
694
697
|
break;
|
|
695
698
|
// {| means that the current triple is annotated with predicate-object pairs.
|
|
696
699
|
case '{|':
|
|
697
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;
|
|
698
703
|
this._subject = this._readTripleTerm();
|
|
699
704
|
this._validAnnotation = false;
|
|
700
705
|
startingAnnotation = true;
|
|
@@ -1006,12 +1011,40 @@ class N3Parser {
|
|
|
1006
1011
|
// If next token is a reifier, read it as such.
|
|
1007
1012
|
if (token.type === 'IRI' || token.type === 'typeIRI' || token.type === 'type' || token.type === 'prefixed' || token.type === 'blank' || token.type === 'var') {
|
|
1008
1013
|
this._reifier = this._readEntity(token);
|
|
1009
|
-
return this.
|
|
1014
|
+
return this._readAnnotationBlockOrPunctuation;
|
|
1010
1015
|
}
|
|
1011
1016
|
// Otherwise, emit and assert triple term.
|
|
1012
1017
|
this._readTripleTerm();
|
|
1013
1018
|
this._subject = null;
|
|
1014
|
-
return this.
|
|
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
|
+
}
|
|
1015
1048
|
}
|
|
1016
1049
|
_readTripleTerm() {
|
|
1017
1050
|
const stack = this._contextStack,
|
package/package.json
CHANGED
package/src/N3Parser.js
CHANGED
|
@@ -746,12 +746,19 @@ export default class N3Parser {
|
|
|
746
746
|
break;
|
|
747
747
|
// ~ is allowed in the annotation syntax
|
|
748
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;
|
|
749
753
|
next = this._readReifierInAnnotation;
|
|
750
754
|
startingAnnotation = true;
|
|
751
755
|
break;
|
|
752
756
|
// {| means that the current triple is annotated with predicate-object pairs.
|
|
753
757
|
case '{|':
|
|
754
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;
|
|
755
762
|
this._subject = this._readTripleTerm();
|
|
756
763
|
this._validAnnotation = false;
|
|
757
764
|
startingAnnotation = true;
|
|
@@ -1089,12 +1096,42 @@ export default class N3Parser {
|
|
|
1089
1096
|
// If next token is a reifier, read it as such.
|
|
1090
1097
|
if (token.type === 'IRI' || token.type === 'typeIRI' || token.type === 'type' || token.type === 'prefixed' || token.type === 'blank' || token.type === 'var') {
|
|
1091
1098
|
this._reifier = this._readEntity(token);
|
|
1092
|
-
return this.
|
|
1099
|
+
return this._readAnnotationBlockOrPunctuation;
|
|
1093
1100
|
}
|
|
1094
1101
|
// Otherwise, emit and assert triple term.
|
|
1095
1102
|
this._readTripleTerm();
|
|
1096
1103
|
this._subject = null;
|
|
1097
|
-
return this.
|
|
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
|
+
}
|
|
1098
1135
|
}
|
|
1099
1136
|
|
|
1100
1137
|
_readTripleTerm() {
|