Comparing version 1.23.0 to 1.23.1
@@ -168,3 +168,3 @@ "use strict"; | ||
if (iri === null) return this._error('Invalid IRI', token); | ||
value = this._namedNode(iri); | ||
value = this._factory.namedNode(iri); | ||
break; | ||
@@ -176,11 +176,11 @@ // Read a prefixed name | ||
if (prefix === undefined) return this._error(`Undefined prefix "${token.prefix}:"`, token); | ||
value = this._namedNode(prefix + token.value); | ||
value = this._factory.namedNode(prefix + token.value); | ||
break; | ||
// Read a blank node | ||
case 'blank': | ||
value = this._blankNode(this._prefixes[token.prefix] + token.value); | ||
value = this._factory.blankNode(this._prefixes[token.prefix] + token.value); | ||
break; | ||
// Read a variable | ||
case 'var': | ||
value = this._variable(token.value.substr(1)); | ||
value = this._factory.variable(token.value.substr(1)); | ||
break; | ||
@@ -202,3 +202,3 @@ // Everything else is not an entity | ||
// Start a new quad with a new blank node as subject | ||
this._saveContext('blank', this._graph, this._subject = this._blankNode(), null, null); | ||
this._saveContext('blank', this._graph, this._subject = this._factory.blankNode(), null, null); | ||
return this._readBlankNodeHead; | ||
@@ -213,3 +213,3 @@ case '(': | ||
if (!this._n3Mode) return this._error('Unexpected graph', token); | ||
this._saveContext('formula', this._graph, this._graph = this._blankNode(), null, null); | ||
this._saveContext('formula', this._graph, this._graph = this._factory.blankNode(), null, null); | ||
return this._readSubject; | ||
@@ -223,3 +223,3 @@ case '}': | ||
this._predicate = this.N3_FORSOME; | ||
this._quantifier = this._blankNode; | ||
this._quantifier = 'blankNode'; | ||
return this._readQuantifierList; | ||
@@ -230,3 +230,3 @@ case '@forAll': | ||
this._predicate = this.N3_FORALL; | ||
this._quantifier = this._variable; | ||
this._quantifier = 'variable'; | ||
return this._readQuantifierList; | ||
@@ -238,3 +238,3 @@ case 'literal': | ||
return this._completeSubjectLiteral; | ||
} else this._subject = this._literal(token.value, this._namedNode(token.prefix)); | ||
} else this._subject = this._factory.literal(token.value, this._factory.namedNode(token.prefix)); | ||
break; | ||
@@ -280,3 +280,3 @@ case '<<': | ||
// Start a new quad with a new blank node as subject | ||
this._saveContext('blank', this._graph, this._subject, this._subject = this._blankNode(), null); | ||
this._saveContext('blank', this._graph, this._subject, this._subject = this._factory.blankNode(), null); | ||
return this._readBlankNodeHead; | ||
@@ -303,7 +303,7 @@ } | ||
// Pre-datatyped string literal (prefix stores the datatype) | ||
else this._object = this._literal(token.value, this._namedNode(token.prefix)); | ||
else this._object = this._factory.literal(token.value, this._factory.namedNode(token.prefix)); | ||
break; | ||
case '[': | ||
// Start a new quad with a new blank node as subject | ||
this._saveContext('blank', this._graph, this._subject, this._predicate, this._subject = this._blankNode()); | ||
this._saveContext('blank', this._graph, this._subject, this._predicate, this._subject = this._factory.blankNode()); | ||
return this._readBlankNodeHead; | ||
@@ -318,3 +318,3 @@ case '(': | ||
if (!this._n3Mode) return this._error('Unexpected graph', token); | ||
this._saveContext('formula', this._graph, this._subject, this._predicate, this._graph = this._blankNode()); | ||
this._saveContext('formula', this._graph, this._subject, this._predicate, this._graph = this._factory.blankNode()); | ||
return this._readSubject; | ||
@@ -408,3 +408,3 @@ case '<<': | ||
// Stack the current list quad and start a new quad with a blank node as subject | ||
this._saveContext('blank', this._graph, list = this._blankNode(), this.RDF_FIRST, this._subject = item = this._blankNode()); | ||
this._saveContext('blank', this._graph, list = this._factory.blankNode(), this.RDF_FIRST, this._subject = item = this._factory.blankNode()); | ||
next = this._readBlankNodeHead; | ||
@@ -414,3 +414,3 @@ break; | ||
// Stack the current list quad and start a new list | ||
this._saveContext('list', this._graph, list = this._blankNode(), this.RDF_FIRST, this.RDF_NIL); | ||
this._saveContext('list', this._graph, list = this._factory.blankNode(), this.RDF_FIRST, this.RDF_NIL); | ||
this._subject = null; | ||
@@ -448,3 +448,3 @@ break; | ||
else { | ||
item = this._literal(token.value, this._namedNode(token.prefix)); | ||
item = this._factory.literal(token.value, this._factory.namedNode(token.prefix)); | ||
next = this._getContextEndReader(); | ||
@@ -456,3 +456,3 @@ } | ||
if (!this._n3Mode) return this._error('Unexpected graph', token); | ||
this._saveContext('formula', this._graph, this._subject, this._predicate, this._graph = this._blankNode()); | ||
this._saveContext('formula', this._graph, this._subject, this._predicate, this._graph = this._factory.blankNode()); | ||
return this._readSubject; | ||
@@ -464,3 +464,3 @@ default: | ||
// Create a new blank node if no item head was assigned yet | ||
if (list === null) this._subject = list = this._blankNode(); | ||
if (list === null) this._subject = list = this._factory.blankNode(); | ||
@@ -504,3 +504,3 @@ // Is this the first element of the list? | ||
// Create a simple string literal by default | ||
let literal = this._literal(this._literalValue); | ||
let literal = this._factory.literal(this._literalValue); | ||
switch (token.type) { | ||
@@ -512,3 +512,3 @@ // Create a datatyped literal | ||
if (datatype === undefined) return; // No datatype means an error occurred | ||
literal = this._literal(this._literalValue, datatype); | ||
literal = this._factory.literal(this._literalValue, datatype); | ||
token = null; | ||
@@ -518,3 +518,3 @@ break; | ||
case 'langcode': | ||
literal = this._literal(this._literalValue, token.value); | ||
literal = this._factory.literal(this._literalValue, token.value); | ||
token = null; | ||
@@ -599,3 +599,3 @@ break; | ||
object = this._object; | ||
this._subject = this._quad(subject, predicate, object, this.DEFAULTGRAPH); | ||
this._subject = this._factory.quad(subject, predicate, object, this.DEFAULTGRAPH); | ||
next = this._readPredicate; | ||
@@ -693,3 +693,3 @@ break; | ||
if (token.type !== ']') return this._error('Invalid graph label', token); | ||
this._subject = this._blankNode(); | ||
this._subject = this._factory.blankNode(); | ||
return this._readGraph; | ||
@@ -720,9 +720,9 @@ } | ||
// Without explicit quantifiers, map entities to a quantified entity | ||
if (!this._explicitQuantifiers) this._quantified[entity.id] = this._quantifier(this._blankNode().value); | ||
if (!this._explicitQuantifiers) this._quantified[entity.id] = this._factory[this._quantifier](this._factory.blankNode().value); | ||
// With explicit quantifiers, output the reified quantifier | ||
else { | ||
// If this is the first item, start a new quantifier list | ||
if (this._subject === null) this._emit(this._graph || this.DEFAULTGRAPH, this._predicate, this._subject = this._blankNode(), this.QUANTIFIERS_GRAPH); | ||
if (this._subject === null) this._emit(this._graph || this.DEFAULTGRAPH, this._predicate, this._subject = this._factory.blankNode(), this.QUANTIFIERS_GRAPH); | ||
// Otherwise, continue the previous list | ||
else this._emit(this._subject, this.RDF_REST, this._subject = this._blankNode(), this.QUANTIFIERS_GRAPH); | ||
else this._emit(this._subject, this.RDF_REST, this._subject = this._factory.blankNode(), this.QUANTIFIERS_GRAPH); | ||
// Output the list item | ||
@@ -786,3 +786,3 @@ this._emit(this._subject, this.RDF_FIRST, entity, this.QUANTIFIERS_GRAPH); | ||
let subject, predicate; | ||
const object = this._blankNode(); | ||
const object = this._factory.blankNode(); | ||
// The next token is the predicate | ||
@@ -801,3 +801,3 @@ if ((predicate = this._readEntity(token)) === undefined) return; | ||
_readBackwardPath(token) { | ||
const subject = this._blankNode(); | ||
const subject = this._factory.blankNode(); | ||
let predicate, object; | ||
@@ -829,3 +829,3 @@ // The next token is the predicate | ||
// Read the quad and restore the previous context | ||
const quad = this._quad(this._subject, this._predicate, this._object, this._graph || this.DEFAULTGRAPH); | ||
const quad = this._factory.quad(this._subject, this._predicate, this._object, this._graph || this.DEFAULTGRAPH); | ||
this._restoreContext('<<', token); | ||
@@ -862,3 +862,3 @@ // If the triple was the subject, continue by reading the predicate. | ||
_emit(subject, predicate, object, graph) { | ||
this._callback(null, this._quad(subject, predicate, object, graph || this.DEFAULTGRAPH)); | ||
this._callback(null, this._factory.quad(subject, predicate, object, graph || this.DEFAULTGRAPH)); | ||
} | ||
@@ -1035,24 +1035,18 @@ | ||
function initDataFactory(parser, factory) { | ||
// Set factory methods | ||
const namedNode = factory.namedNode; | ||
parser._namedNode = namedNode; | ||
parser._blankNode = factory.blankNode; | ||
parser._literal = factory.literal; | ||
parser._variable = factory.variable; | ||
parser._quad = factory.quad; | ||
parser._factory = factory; | ||
parser.DEFAULTGRAPH = factory.defaultGraph(); | ||
// Set common named nodes | ||
parser.RDF_FIRST = namedNode(_IRIs.default.rdf.first); | ||
parser.RDF_REST = namedNode(_IRIs.default.rdf.rest); | ||
parser.RDF_NIL = namedNode(_IRIs.default.rdf.nil); | ||
parser.N3_FORALL = namedNode(_IRIs.default.r.forAll); | ||
parser.N3_FORSOME = namedNode(_IRIs.default.r.forSome); | ||
parser.RDF_FIRST = factory.namedNode(_IRIs.default.rdf.first); | ||
parser.RDF_REST = factory.namedNode(_IRIs.default.rdf.rest); | ||
parser.RDF_NIL = factory.namedNode(_IRIs.default.rdf.nil); | ||
parser.N3_FORALL = factory.namedNode(_IRIs.default.r.forAll); | ||
parser.N3_FORSOME = factory.namedNode(_IRIs.default.r.forSome); | ||
parser.ABBREVIATIONS = { | ||
'a': namedNode(_IRIs.default.rdf.type), | ||
'=': namedNode(_IRIs.default.owl.sameAs), | ||
'>': namedNode(_IRIs.default.log.implies) | ||
'a': factory.namedNode(_IRIs.default.rdf.type), | ||
'=': factory.namedNode(_IRIs.default.owl.sameAs), | ||
'>': factory.namedNode(_IRIs.default.log.implies) | ||
}; | ||
parser.QUANTIFIERS_GRAPH = namedNode('urn:n3:quantifiers'); | ||
parser.QUANTIFIERS_GRAPH = factory.namedNode('urn:n3:quantifiers'); | ||
} | ||
initDataFactory(N3Parser.prototype, _N3DataFactory.default); |
{ | ||
"name": "n3", | ||
"version": "1.23.0", | ||
"version": "1.23.1", | ||
"description": "Lightning fast, asynchronous, streaming Turtle / N3 / RDF library.", | ||
@@ -41,3 +41,3 @@ "author": "Ruben Verborgh <ruben.verborgh@gmail.com>", | ||
"docco": "^0.9.1", | ||
"eslint": "^9.12.0", | ||
"eslint": "^8.57.1", | ||
"eslint-plugin-import": "^2.29.1", | ||
@@ -44,0 +44,0 @@ "eslint-plugin-jest": "^28.8.3", |
@@ -162,3 +162,3 @@ // **N3Parser** parses N3 documents. | ||
return this._error('Invalid IRI', token); | ||
value = this._namedNode(iri); | ||
value = this._factory.namedNode(iri); | ||
break; | ||
@@ -171,11 +171,11 @@ // Read a prefixed name | ||
return this._error(`Undefined prefix "${token.prefix}:"`, token); | ||
value = this._namedNode(prefix + token.value); | ||
value = this._factory.namedNode(prefix + token.value); | ||
break; | ||
// Read a blank node | ||
case 'blank': | ||
value = this._blankNode(this._prefixes[token.prefix] + token.value); | ||
value = this._factory.blankNode(this._prefixes[token.prefix] + token.value); | ||
break; | ||
// Read a variable | ||
case 'var': | ||
value = this._variable(token.value.substr(1)); | ||
value = this._factory.variable(token.value.substr(1)); | ||
break; | ||
@@ -199,3 +199,3 @@ // Everything else is not an entity | ||
this._saveContext('blank', this._graph, | ||
this._subject = this._blankNode(), null, null); | ||
this._subject = this._factory.blankNode(), null, null); | ||
return this._readBlankNodeHead; | ||
@@ -212,3 +212,3 @@ case '(': | ||
this._saveContext('formula', this._graph, | ||
this._graph = this._blankNode(), null, null); | ||
this._graph = this._factory.blankNode(), null, null); | ||
return this._readSubject; | ||
@@ -223,3 +223,3 @@ case '}': | ||
this._predicate = this.N3_FORSOME; | ||
this._quantifier = this._blankNode; | ||
this._quantifier = 'blankNode'; | ||
return this._readQuantifierList; | ||
@@ -231,3 +231,3 @@ case '@forAll': | ||
this._predicate = this.N3_FORALL; | ||
this._quantifier = this._variable; | ||
this._quantifier = 'variable'; | ||
return this._readQuantifierList; | ||
@@ -243,3 +243,3 @@ case 'literal': | ||
else | ||
this._subject = this._literal(token.value, this._namedNode(token.prefix)); | ||
this._subject = this._factory.literal(token.value, this._factory.namedNode(token.prefix)); | ||
@@ -292,3 +292,3 @@ break; | ||
this._saveContext('blank', this._graph, this._subject, | ||
this._subject = this._blankNode(), null); | ||
this._subject = this._factory.blankNode(), null); | ||
return this._readBlankNodeHead; | ||
@@ -318,3 +318,3 @@ } | ||
else | ||
this._object = this._literal(token.value, this._namedNode(token.prefix)); | ||
this._object = this._factory.literal(token.value, this._factory.namedNode(token.prefix)); | ||
break; | ||
@@ -324,3 +324,3 @@ case '[': | ||
this._saveContext('blank', this._graph, this._subject, this._predicate, | ||
this._subject = this._blankNode()); | ||
this._subject = this._factory.blankNode()); | ||
return this._readBlankNodeHead; | ||
@@ -337,3 +337,3 @@ case '(': | ||
this._saveContext('formula', this._graph, this._subject, this._predicate, | ||
this._graph = this._blankNode()); | ||
this._graph = this._factory.blankNode()); | ||
return this._readSubject; | ||
@@ -433,4 +433,4 @@ case '<<': | ||
this._saveContext('blank', this._graph, | ||
list = this._blankNode(), this.RDF_FIRST, | ||
this._subject = item = this._blankNode()); | ||
list = this._factory.blankNode(), this.RDF_FIRST, | ||
this._subject = item = this._factory.blankNode()); | ||
next = this._readBlankNodeHead; | ||
@@ -441,3 +441,3 @@ break; | ||
this._saveContext('list', this._graph, | ||
list = this._blankNode(), this.RDF_FIRST, this.RDF_NIL); | ||
list = this._factory.blankNode(), this.RDF_FIRST, this.RDF_NIL); | ||
this._subject = null; | ||
@@ -478,3 +478,3 @@ break; | ||
else { | ||
item = this._literal(token.value, this._namedNode(token.prefix)); | ||
item = this._factory.literal(token.value, this._factory.namedNode(token.prefix)); | ||
next = this._getContextEndReader(); | ||
@@ -488,3 +488,3 @@ } | ||
this._saveContext('formula', this._graph, this._subject, this._predicate, | ||
this._graph = this._blankNode()); | ||
this._graph = this._factory.blankNode()); | ||
return this._readSubject; | ||
@@ -498,3 +498,3 @@ default: | ||
if (list === null) | ||
this._subject = list = this._blankNode(); | ||
this._subject = list = this._factory.blankNode(); | ||
@@ -543,3 +543,3 @@ // Is this the first element of the list? | ||
// Create a simple string literal by default | ||
let literal = this._literal(this._literalValue); | ||
let literal = this._factory.literal(this._literalValue); | ||
@@ -552,3 +552,3 @@ switch (token.type) { | ||
if (datatype === undefined) return; // No datatype means an error occurred | ||
literal = this._literal(this._literalValue, datatype); | ||
literal = this._factory.literal(this._literalValue, datatype); | ||
token = null; | ||
@@ -558,3 +558,3 @@ break; | ||
case 'langcode': | ||
literal = this._literal(this._literalValue, token.value); | ||
literal = this._factory.literal(this._literalValue, token.value); | ||
token = null; | ||
@@ -642,3 +642,3 @@ break; | ||
const predicate = this._predicate, object = this._object; | ||
this._subject = this._quad(subject, predicate, object, this.DEFAULTGRAPH); | ||
this._subject = this._factory.quad(subject, predicate, object, this.DEFAULTGRAPH); | ||
next = this._readPredicate; | ||
@@ -744,3 +744,3 @@ break; | ||
return this._error('Invalid graph label', token); | ||
this._subject = this._blankNode(); | ||
this._subject = this._factory.blankNode(); | ||
return this._readGraph; | ||
@@ -775,3 +775,3 @@ } | ||
if (!this._explicitQuantifiers) | ||
this._quantified[entity.id] = this._quantifier(this._blankNode().value); | ||
this._quantified[entity.id] = this._factory[this._quantifier](this._factory.blankNode().value); | ||
// With explicit quantifiers, output the reified quantifier | ||
@@ -782,7 +782,7 @@ else { | ||
this._emit(this._graph || this.DEFAULTGRAPH, this._predicate, | ||
this._subject = this._blankNode(), this.QUANTIFIERS_GRAPH); | ||
this._subject = this._factory.blankNode(), this.QUANTIFIERS_GRAPH); | ||
// Otherwise, continue the previous list | ||
else | ||
this._emit(this._subject, this.RDF_REST, | ||
this._subject = this._blankNode(), this.QUANTIFIERS_GRAPH); | ||
this._subject = this._factory.blankNode(), this.QUANTIFIERS_GRAPH); | ||
// Output the list item | ||
@@ -844,3 +844,3 @@ this._emit(this._subject, this.RDF_FIRST, entity, this.QUANTIFIERS_GRAPH); | ||
let subject, predicate; | ||
const object = this._blankNode(); | ||
const object = this._factory.blankNode(); | ||
// The next token is the predicate | ||
@@ -862,3 +862,3 @@ if ((predicate = this._readEntity(token)) === undefined) | ||
_readBackwardPath(token) { | ||
const subject = this._blankNode(); | ||
const subject = this._factory.blankNode(); | ||
let predicate, object; | ||
@@ -895,3 +895,3 @@ // The next token is the predicate | ||
// Read the quad and restore the previous context | ||
const quad = this._quad(this._subject, this._predicate, this._object, | ||
const quad = this._factory.quad(this._subject, this._predicate, this._object, | ||
this._graph || this.DEFAULTGRAPH); | ||
@@ -931,3 +931,3 @@ this._restoreContext('<<', token); | ||
_emit(subject, predicate, object, graph) { | ||
this._callback(null, this._quad(subject, predicate, object, graph || this.DEFAULTGRAPH)); | ||
this._callback(null, this._factory.quad(subject, predicate, object, graph || this.DEFAULTGRAPH)); | ||
} | ||
@@ -1112,24 +1112,19 @@ | ||
function initDataFactory(parser, factory) { | ||
// Set factory methods | ||
const namedNode = factory.namedNode; | ||
parser._namedNode = namedNode; | ||
parser._blankNode = factory.blankNode; | ||
parser._literal = factory.literal; | ||
parser._variable = factory.variable; | ||
parser._quad = factory.quad; | ||
parser._factory = factory; | ||
parser.DEFAULTGRAPH = factory.defaultGraph(); | ||
// Set common named nodes | ||
parser.RDF_FIRST = namedNode(namespaces.rdf.first); | ||
parser.RDF_REST = namedNode(namespaces.rdf.rest); | ||
parser.RDF_NIL = namedNode(namespaces.rdf.nil); | ||
parser.N3_FORALL = namedNode(namespaces.r.forAll); | ||
parser.N3_FORSOME = namedNode(namespaces.r.forSome); | ||
parser.RDF_FIRST = factory.namedNode(namespaces.rdf.first); | ||
parser.RDF_REST = factory.namedNode(namespaces.rdf.rest); | ||
parser.RDF_NIL = factory.namedNode(namespaces.rdf.nil); | ||
parser.N3_FORALL = factory.namedNode(namespaces.r.forAll); | ||
parser.N3_FORSOME = factory.namedNode(namespaces.r.forSome); | ||
parser.ABBREVIATIONS = { | ||
'a': namedNode(namespaces.rdf.type), | ||
'=': namedNode(namespaces.owl.sameAs), | ||
'>': namedNode(namespaces.log.implies), | ||
'a': factory.namedNode(namespaces.rdf.type), | ||
'=': factory.namedNode(namespaces.owl.sameAs), | ||
'>': factory.namedNode(namespaces.log.implies), | ||
}; | ||
parser.QUANTIFIERS_GRAPH = namedNode('urn:n3:quantifiers'); | ||
parser.QUANTIFIERS_GRAPH = factory.namedNode('urn:n3:quantifiers'); | ||
} | ||
initDataFactory(N3Parser.prototype, N3DataFactory); |
Sorry, the diff of this file is too big to display
599123
8682