Skip to content

Commit 3c1c629

Browse files
committed
Fix synchronous parsing in presence of prefixes.
Fixes #78.
1 parent 1f04190 commit 3c1c629

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

lib/N3Parser.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -841,11 +841,12 @@ N3Parser.prototype = {
841841
this._sparqlStyle = false;
842842
this._prefixes = Object.create(null);
843843
this._prefixes._ = this._blankNodePrefix || '_:b' + blankNodePrefix++ + '_';
844+
this._prefixCallback = prefixCallback || noop;
844845
this._inversePredicate = false;
845846
this._quantified = Object.create(null);
846847

847-
// Parse synchronously if no callbacks are given.
848-
if (!tripleCallback && !prefixCallback) {
848+
// Parse synchronously if no triple callback is given.
849+
if (!tripleCallback) {
849850
var triples = [], error;
850851
this._callback = function (e, t) { e ? (error = e) : t && triples.push(t); };
851852
this._lexer.tokenize(input).every(function (token) {
@@ -856,8 +857,7 @@ N3Parser.prototype = {
856857
}
857858

858859
// Parse asynchronously otherwise, executing the read callback when a token arrives.
859-
this._callback = tripleCallback || noop;
860-
this._prefixCallback = prefixCallback || noop;
860+
this._callback = tripleCallback;
861861
this._lexer.tokenize(input, function (error, token) {
862862
if (error !== null)
863863
self._callback(error), self._callback = noop;

test/N3Parser-test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -751,8 +751,8 @@ describe('N3Parser', function () {
751751
});
752752

753753
it('should parse a string synchronously if no callback is given', function () {
754-
var triples = new N3Parser().parse('<a> <b> <c>.');
755-
triples.should.deep.equal([{ subject: 'a', predicate: 'b', object: 'c', graph: '' }]);
754+
var triples = new N3Parser().parse('@prefix a: <urn:a:>. a:a a:b a:c.');
755+
triples.should.deep.equal([{ subject: 'urn:a:a', predicate: 'urn:a:b', object: 'urn:a:c', graph: '' }]);
756756
});
757757

758758
it('should throw on syntax errors if no callback is given', function () {

0 commit comments

Comments
 (0)