Comparing version 0.2.3 to 0.2.4
@@ -59,6 +59,4 @@ // **N3Lexer** tokenizes N3 documents. | ||
_tokenizeToEnd: function (callback, inputFinished) { | ||
// Only emit tokens if there's still input left. | ||
// Continue parsing as far as possible; the loop will return eventually. | ||
var input = this._input; | ||
// Continue parsing as far as possible; the loop will return eventually. | ||
while (true) { | ||
@@ -80,3 +78,3 @@ // Count and skip whitespace lines. | ||
if (inputFinished) { | ||
delete this._input; | ||
input = null; | ||
token.type = 'eof'; | ||
@@ -271,4 +269,4 @@ callback(null, token); | ||
match = self._nonwhitespace.exec(input); | ||
delete self._input; | ||
callback('Syntax error: unexpected "' + match[0] + '" on line ' + self._line + '.'); | ||
self._input = null; | ||
callback(new Error('Syntax error: unexpected "' + match[0] + '" on line ' + self._line + '.')); | ||
} | ||
@@ -341,4 +339,6 @@ }, | ||
function addChunk(data) { | ||
self._input += data; | ||
self._tokenizeToEnd(callback, false); | ||
if (self._input !== null) { | ||
self._input += data; | ||
self._tokenizeToEnd(callback, false); | ||
} | ||
} | ||
@@ -348,5 +348,5 @@ | ||
function end() { | ||
delete self.addChunk; | ||
delete self.end; | ||
self._tokenizeToEnd(callback, true); | ||
if (self._input !== null) { | ||
self._tokenizeToEnd(callback, true); | ||
} | ||
} | ||
@@ -353,0 +353,0 @@ }, |
@@ -448,3 +448,3 @@ // **N3Parser** parses N3 documents. | ||
_error: function (message, token) { | ||
this._callback(message + ' at line ' + token.line + '.'); | ||
this._callback(new Error(message + ' at line ' + token.line + '.')); | ||
}, | ||
@@ -451,0 +451,0 @@ |
@@ -21,3 +21,3 @@ // **N3StreamParser** parses an N3 stream into a triple stream | ||
triple && self.push(triple) || | ||
error && self.emit('error', new Error(error)); | ||
error && self.emit('error', error); | ||
}, | ||
@@ -24,0 +24,0 @@ // Emit prefixes through the `prefix` event |
{ | ||
"name": "n3", | ||
"version": "0.2.3", | ||
"version": "0.2.4", | ||
"description": "Lightning fast, asynchronous, streaming Turtle / N3 / RDF library.", | ||
@@ -5,0 +5,0 @@ "author": "Ruben Verborgh <ruben.verborgh@gmail.com>", |
@@ -237,3 +237,3 @@ # Lightning fast, asynchronous, streaming Turtle for JavaScript | ||
``` | ||
Literals are represented as double quoted strings: | ||
**Literals** are represented as double quoted strings: | ||
``` js | ||
@@ -263,2 +263,17 @@ N3Util.isLiteral('"Mickey Mouse"'); // true | ||
**Blank nodes** start with `_:`, and can be tested for as follows: | ||
``` js | ||
N3Util.isBlank('_:b1'); // true | ||
N3Util.isUri('_:b1'); // false | ||
N3Util.isLiteral('_:b1'); // false | ||
``` | ||
**QNames** can be tested and expanded: | ||
``` js | ||
var prefixes = { 'rdfs': 'http://www.w3.org/2000/01/rdf-schema#' }; | ||
N3Util.isQName('rdfs:label'); // true; | ||
N3Util.expandQName('rdfs:label', prefixes); // http://www.w3.org/2000/01/rdf-schema#label | ||
``` | ||
### Loading the utility globally | ||
For convenience, `N3Util` can also be loaded globally: | ||
@@ -265,0 +280,0 @@ ``` js |
@@ -69,3 +69,4 @@ var N3Lexer = require('../N3').Lexer; | ||
lexer.tokenize(function (error, token) { | ||
error.should.equal('Syntax error: unexpected "<\\u1234>" on line 1.'); | ||
error.should.be.an.instanceof(Error); | ||
error.message.should.equal('Syntax error: unexpected "<\\u1234>" on line 1.'); | ||
done(token); | ||
@@ -85,3 +86,4 @@ }); | ||
lexer.tokenize(function (error, token) { | ||
error.should.equal('Syntax error: unexpected "<\\U12345678>" on line 1.'); | ||
error.should.be.an.instanceof(Error); | ||
error.message.should.equal('Syntax error: unexpected "<\\U12345678>" on line 1.'); | ||
done(token); | ||
@@ -454,3 +456,3 @@ }); | ||
var tokens = [], lexer = new N3Lexer(); | ||
lexer.tokenize(function (error, token) { tokens.push(token); }); | ||
lexer.tokenize(function (error, token) { !error && tokens.push(token); }); | ||
lexer.addChunk('<a> '); | ||
@@ -465,2 +467,27 @@ lexer.addChunk('<b> '); | ||
}); | ||
describe('passing data after the stream has been finished', function () { | ||
var tokens = [], lexer = new N3Lexer(); | ||
lexer.tokenize(function (error, token) { !error && tokens.push(token); }); | ||
lexer.addChunk('<a> '); | ||
lexer.end(); | ||
lexer.addChunk('<b> '); | ||
it('parses only the first chunk (plus EOF)', function () { | ||
tokens.should.have.length(2); | ||
}); | ||
}); | ||
describe('passing data after an error has occured', function () { | ||
var tokens = [], lexer = new N3Lexer(); | ||
lexer.tokenize(function (error, token) { !error && tokens.push(token); }); | ||
lexer.addChunk('<a> '); | ||
lexer.addChunk('error '); | ||
lexer.end(); | ||
lexer.addChunk('<b> '); | ||
it('parses only the first chunk', function () { | ||
tokens.should.have.length(1); | ||
}); | ||
}); | ||
}); | ||
@@ -498,3 +525,5 @@ }); | ||
expect(token).not.to.exist; | ||
error.should.eql(expectedError); | ||
error.should.be.an.instanceof(Error); | ||
error.message.should.eql(expectedError); | ||
error.should.be.an.instanceof(Error); | ||
done(); | ||
@@ -501,0 +530,0 @@ } |
@@ -527,3 +527,4 @@ var N3Parser = require('../N3').Parser; | ||
expect(triple).not.to.exist; | ||
error.should.eql(expectedError); | ||
error.should.be.an.instanceof(Error); | ||
error.message.should.eql(expectedError); | ||
done(); | ||
@@ -530,0 +531,0 @@ } |
@@ -65,2 +65,3 @@ var N3StreamParser = require('../N3').StreamParser; | ||
transform.on('error', function (error) { | ||
error.should.be.an.instanceof(Error); | ||
error.message.should.equal(expectedMessage); | ||
@@ -67,0 +68,0 @@ done(); |
@@ -94,2 +94,3 @@ var N3StreamWriter = require('../N3').StreamWriter; | ||
transform.on('error', function (error) { | ||
error.should.be.an.instanceof(Error); | ||
error.message.should.equal(expectedMessage); | ||
@@ -96,0 +97,0 @@ done(); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
172791
3499
301