n3 1.16.4 → 1.17.0

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/N3Lexer.js CHANGED
@@ -316,7 +316,6 @@ class N3Lexer {
316
316
  case ']':
317
317
  case '(':
318
318
  case ')':
319
- case '{':
320
319
  case '}':
321
320
  if (!this._lineMode) {
322
321
  matchLength = 1;
@@ -325,6 +324,21 @@ class N3Lexer {
325
324
 
326
325
  break;
327
326
 
327
+ case '{':
328
+ // We need at least 2 tokens lookahead to distinguish "{|" and "{ "
329
+ if (!this._lineMode && input.length >= 2) {
330
+ // Try to find a quoted triple annotation start
331
+ if (input[1] === '|') type = '{|', matchLength = 2;else type = firstChar, matchLength = 1;
332
+ }
333
+
334
+ break;
335
+
336
+ case '|':
337
+ // We need 2 tokens lookahead to parse "|}"
338
+ // Try to find a quoted triple annotation end
339
+ if (input.length >= 2 && input[1] === '}') type = '|}', matchLength = 2;
340
+ break;
341
+
328
342
  default:
329
343
  inconclusive = true;
330
344
  } // Some first characters do not allow an immediate decision, so inspect more
package/lib/N3Parser.js CHANGED
@@ -645,6 +645,23 @@ class N3Parser {
645
645
  case ',':
646
646
  next = this._readObject;
647
647
  break;
648
+ // {| means that the current triple is annotated with predicate-object pairs.
649
+
650
+ case '{|':
651
+ if (!this._supportsRDFStar) return this._error('Unexpected RDF* syntax', token); // Continue using the last triple as quoted triple subject for the predicate-object pairs.
652
+
653
+ const predicate = this._predicate,
654
+ object = this._object;
655
+ this._subject = this._quad(subject, predicate, object, this.DEFAULTGRAPH);
656
+ next = this._readPredicate;
657
+ break;
658
+ // |} means that the current quoted triple in annotation syntax is finalized.
659
+
660
+ case '|}':
661
+ if (this._subject.termType !== 'Quad') return this._error('Unexpected asserted triple closing', token);
662
+ this._subject = null;
663
+ next = this._readPunctuation;
664
+ break;
648
665
 
649
666
  default:
650
667
  // An entity means this is a quad (only allowed if not already inside a graph)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "n3",
3
- "version": "1.16.4",
3
+ "version": "1.17.0",
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/N3Lexer.js CHANGED
@@ -300,13 +300,28 @@ export default class N3Lexer {
300
300
  case ']':
301
301
  case '(':
302
302
  case ')':
303
- case '{':
304
303
  case '}':
305
304
  if (!this._lineMode) {
306
305
  matchLength = 1;
307
306
  type = firstChar;
308
307
  }
309
308
  break;
309
+ case '{':
310
+ // We need at least 2 tokens lookahead to distinguish "{|" and "{ "
311
+ if (!this._lineMode && input.length >= 2) {
312
+ // Try to find a quoted triple annotation start
313
+ if (input[1] === '|')
314
+ type = '{|', matchLength = 2;
315
+ else
316
+ type = firstChar, matchLength = 1;
317
+ }
318
+ break;
319
+ case '|':
320
+ // We need 2 tokens lookahead to parse "|}"
321
+ // Try to find a quoted triple annotation end
322
+ if (input.length >= 2 && input[1] === '}')
323
+ type = '|}', matchLength = 2;
324
+ break;
310
325
 
311
326
  default:
312
327
  inconclusive = true;
package/src/N3Parser.js CHANGED
@@ -614,6 +614,22 @@ export default class N3Parser {
614
614
  case ',':
615
615
  next = this._readObject;
616
616
  break;
617
+ // {| means that the current triple is annotated with predicate-object pairs.
618
+ case '{|':
619
+ if (!this._supportsRDFStar)
620
+ return this._error('Unexpected RDF* syntax', token);
621
+ // Continue using the last triple as quoted triple subject for the predicate-object pairs.
622
+ const predicate = this._predicate, object = this._object;
623
+ this._subject = this._quad(subject, predicate, object, this.DEFAULTGRAPH);
624
+ next = this._readPredicate;
625
+ break;
626
+ // |} means that the current quoted triple in annotation syntax is finalized.
627
+ case '|}':
628
+ if (this._subject.termType !== 'Quad')
629
+ return this._error('Unexpected asserted triple closing', token);
630
+ this._subject = null;
631
+ next = this._readPunctuation;
632
+ break;
617
633
  default:
618
634
  // An entity means this is a quad (only allowed if not already inside a graph)
619
635
  if (this._supportsQuads && this._graph === null && (graph = this._readEntity(token)) !== undefined) {