n3 2.4.0 → 2.5.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/browser/n3.esm.min.js +4 -4
- package/browser/n3.min.js +1 -1
- package/lib/N3Lexer.js +5 -0
- package/lib/N3Parser.js +22 -0
- package/package.json +1 -1
- package/src/N3Lexer.js +9 -0
- package/src/N3Parser.js +30 -0
package/lib/N3Lexer.js
CHANGED
|
@@ -88,6 +88,7 @@ class N3Lexer {
|
|
|
88
88
|
this._boolean = /^(?:true|false)(?=[.,;!\^\s#()\[\]\{\}"'<>])/;
|
|
89
89
|
this._atKeyword = /^@[a-z]+(?=[\s#<:])/i;
|
|
90
90
|
this._keyword = /^(?:PREFIX|BASE|VERSION|GRAPH)(?=[\s#<])/i;
|
|
91
|
+
this._n3Id = /^id(?=[\s#<])/;
|
|
91
92
|
this._shortPredicates = /^a(?=[\s#()\[\]\{\}"'<>])/;
|
|
92
93
|
this._newline = /^[ \t]*(?:#[^\n\r]*)?(?:\r\n|\n|\r)[ \t]*/;
|
|
93
94
|
this._comment = /#([^\n\r]*)/;
|
|
@@ -315,6 +316,10 @@ class N3Lexer {
|
|
|
315
316
|
// Try to find an abbreviated predicate
|
|
316
317
|
if (match = this._shortPredicates.exec(input)) type = 'abbreviation', value = 'a';else inconclusive = true;
|
|
317
318
|
break;
|
|
319
|
+
case 'i':
|
|
320
|
+
// Try to find the IRI property list identifier
|
|
321
|
+
if (this._n3Mode && (match = this._n3Id.exec(input))) type = 'id';else inconclusive = true;
|
|
322
|
+
break;
|
|
318
323
|
case '=':
|
|
319
324
|
// Try to find an implication arrow or equals sign
|
|
320
325
|
if (this._n3Mode && input.length > 1) {
|
package/lib/N3Parser.js
CHANGED
|
@@ -457,11 +457,33 @@ class N3Parser {
|
|
|
457
457
|
if (parentParent.type === '<<') {
|
|
458
458
|
return this._error('Unexpected compound blank node expression in reified triple', token);
|
|
459
459
|
}
|
|
460
|
+
if (token.type === 'id') return this._readIriPropertyListId;
|
|
460
461
|
this._predicate = null;
|
|
461
462
|
return this._readPredicate(token);
|
|
462
463
|
}
|
|
463
464
|
}
|
|
464
465
|
|
|
466
|
+
// ### `_readIriPropertyListId` replaces a property list's blank node with its IRI
|
|
467
|
+
_readIriPropertyListId(token) {
|
|
468
|
+
const iri = this._readEntity(token);
|
|
469
|
+
if (iri === undefined) return;
|
|
470
|
+
if (iri.termType !== 'NamedNode') return this._error(`Expected IRI after id but got ${token.type}`, token);
|
|
471
|
+
const placeholder = this._subject;
|
|
472
|
+
this._subject = iri;
|
|
473
|
+
const context = this._contextStack[this._contextStack.length - 1];
|
|
474
|
+
if (context.subject === placeholder) context.subject = iri;
|
|
475
|
+
if (context.predicate === placeholder) context.predicate = iri;
|
|
476
|
+
if (context.object === placeholder) context.object = iri;
|
|
477
|
+
this._predicate = null;
|
|
478
|
+
return this._readIriPropertyListPredicate;
|
|
479
|
+
}
|
|
480
|
+
|
|
481
|
+
// ### `_readIriPropertyListPredicate` requires properties after an IRI property list ID
|
|
482
|
+
_readIriPropertyListPredicate(token) {
|
|
483
|
+
if (token.type === ';' || token.type === ']' || token.type === '.' || token.type === '}') return this._error(`Expected predicate but got ${token.type}`, token);
|
|
484
|
+
return this._readPredicate(token);
|
|
485
|
+
}
|
|
486
|
+
|
|
465
487
|
// ### `_readBlankNodeTail` reads the end of a blank node
|
|
466
488
|
_readBlankNodeTail(token) {
|
|
467
489
|
if (token.type !== ']') return this._readBlankNodePunctuation(token);
|
package/package.json
CHANGED
package/src/N3Lexer.js
CHANGED
|
@@ -57,6 +57,7 @@ export default class N3Lexer {
|
|
|
57
57
|
this._boolean = /^(?:true|false)(?=[.,;!\^\s#()\[\]\{\}"'<>])/;
|
|
58
58
|
this._atKeyword = /^@[a-z]+(?=[\s#<:])/i;
|
|
59
59
|
this._keyword = /^(?:PREFIX|BASE|VERSION|GRAPH)(?=[\s#<])/i;
|
|
60
|
+
this._n3Id = /^id(?=[\s#<])/;
|
|
60
61
|
this._shortPredicates = /^a(?=[\s#()\[\]\{\}"'<>])/;
|
|
61
62
|
this._newline = /^[ \t]*(?:#[^\n\r]*)?(?:\r\n|\n|\r)[ \t]*/;
|
|
62
63
|
this._comment = /#([^\n\r]*)/;
|
|
@@ -318,6 +319,14 @@ export default class N3Lexer {
|
|
|
318
319
|
inconclusive = true;
|
|
319
320
|
break;
|
|
320
321
|
|
|
322
|
+
case 'i':
|
|
323
|
+
// Try to find the IRI property list identifier
|
|
324
|
+
if (this._n3Mode && (match = this._n3Id.exec(input)))
|
|
325
|
+
type = 'id';
|
|
326
|
+
else
|
|
327
|
+
inconclusive = true;
|
|
328
|
+
break;
|
|
329
|
+
|
|
321
330
|
case '=':
|
|
322
331
|
// Try to find an implication arrow or equals sign
|
|
323
332
|
if (this._n3Mode && input.length > 1) {
|
package/src/N3Parser.js
CHANGED
|
@@ -480,11 +480,41 @@ export default class N3Parser {
|
|
|
480
480
|
if (parentParent.type === '<<') {
|
|
481
481
|
return this._error('Unexpected compound blank node expression in reified triple', token);
|
|
482
482
|
}
|
|
483
|
+
if (token.type === 'id')
|
|
484
|
+
return this._readIriPropertyListId;
|
|
483
485
|
this._predicate = null;
|
|
484
486
|
return this._readPredicate(token);
|
|
485
487
|
}
|
|
486
488
|
}
|
|
487
489
|
|
|
490
|
+
// ### `_readIriPropertyListId` replaces a property list's blank node with its IRI
|
|
491
|
+
_readIriPropertyListId(token) {
|
|
492
|
+
const iri = this._readEntity(token);
|
|
493
|
+
if (iri === undefined)
|
|
494
|
+
return;
|
|
495
|
+
if (iri.termType !== 'NamedNode')
|
|
496
|
+
return this._error(`Expected IRI after id but got ${token.type}`, token);
|
|
497
|
+
|
|
498
|
+
const placeholder = this._subject;
|
|
499
|
+
this._subject = iri;
|
|
500
|
+
const context = this._contextStack[this._contextStack.length - 1];
|
|
501
|
+
if (context.subject === placeholder)
|
|
502
|
+
context.subject = iri;
|
|
503
|
+
if (context.predicate === placeholder)
|
|
504
|
+
context.predicate = iri;
|
|
505
|
+
if (context.object === placeholder)
|
|
506
|
+
context.object = iri;
|
|
507
|
+
this._predicate = null;
|
|
508
|
+
return this._readIriPropertyListPredicate;
|
|
509
|
+
}
|
|
510
|
+
|
|
511
|
+
// ### `_readIriPropertyListPredicate` requires properties after an IRI property list ID
|
|
512
|
+
_readIriPropertyListPredicate(token) {
|
|
513
|
+
if (token.type === ';' || token.type === ']' || token.type === '.' || token.type === '}')
|
|
514
|
+
return this._error(`Expected predicate but got ${token.type}`, token);
|
|
515
|
+
return this._readPredicate(token);
|
|
516
|
+
}
|
|
517
|
+
|
|
488
518
|
// ### `_readBlankNodeTail` reads the end of a blank node
|
|
489
519
|
_readBlankNodeTail(token) {
|
|
490
520
|
if (token.type !== ']')
|