Comparing version 0.3.3 to 0.3.4
@@ -13,3 +13,4 @@ // **N3Parser** parses N3 documents. | ||
var _undefined, noop = function () {}; | ||
// The next ID for new blank nodes | ||
var blankNodeCount = 0; | ||
@@ -21,8 +22,9 @@ // ## Constructor | ||
// Initialize the parser settings | ||
config = config || {}; | ||
this._tripleStack = []; | ||
this._lexer = config.lexer || new N3Lexer(); | ||
this._blankNodes = Object.create(null); | ||
this._blankNodeCount = 0; | ||
this._tripleStack = []; | ||
// Set the document URI | ||
if (!config.documentURI) { | ||
@@ -41,2 +43,9 @@ this._baseURI = null; | ||
// ## Private class methods | ||
// ### `_resetBlankNodeIds` restarts blank node identification. | ||
N3Parser._resetBlankNodeIds = function () { | ||
blankNodeCount = 0; | ||
}; | ||
N3Parser.prototype = { | ||
@@ -83,7 +92,7 @@ // ## Private methods | ||
this._subject = this._blankNodes[token.value] || | ||
(this._blankNodes[token.value] = '_:b' + this._blankNodeCount++); | ||
(this._blankNodes[token.value] = '_:b' + blankNodeCount++); | ||
} | ||
else { | ||
var prefix = this._prefixes[token.prefix]; | ||
if (prefix === _undefined) | ||
if (prefix === undefined) | ||
return this._error('Undefined prefix "' + token.prefix + ':"', token); | ||
@@ -95,3 +104,3 @@ this._subject = prefix + token.value; | ||
// Start a new triple with a new blank node as subject. | ||
this._subject = '_:b' + this._blankNodeCount++; | ||
this._subject = '_:b' + blankNodeCount++; | ||
this._tripleStack.push({ subject: this._subject, predicate: null, object: null, type: 'blank' }); | ||
@@ -128,3 +137,3 @@ return this._readBlankNodeHead; | ||
var prefix = this._prefixes[token.prefix]; | ||
if (prefix === _undefined) | ||
if (prefix === undefined) | ||
return this._error('Undefined prefix "' + token.prefix + ':"', token); | ||
@@ -166,7 +175,7 @@ this._predicate = prefix + token.value; | ||
this._object = this._blankNodes[token.value] || | ||
(this._blankNodes[token.value] = '_:b' + this._blankNodeCount++); | ||
(this._blankNodes[token.value] = '_:b' + blankNodeCount++); | ||
} | ||
else { | ||
var prefix = this._prefixes[token.prefix]; | ||
if (prefix === _undefined) | ||
if (prefix === undefined) | ||
return this._error('Undefined prefix "' + token.prefix + ':"', token); | ||
@@ -181,3 +190,3 @@ this._object = prefix + token.value; | ||
// Start a new triple with a new blank node as subject. | ||
var blank = '_:b' + this._blankNodeCount++; | ||
var blank = '_:b' + blankNodeCount++; | ||
this._tripleStack.push({ subject: this._subject, predicate: this._predicate, object: blank, type: 'blank' }); | ||
@@ -241,3 +250,3 @@ this._subject = blank; | ||
var prefix = this._prefixes[token.prefix]; | ||
if (prefix === _undefined) | ||
if (prefix === undefined) | ||
return this._error('Undefined prefix "' + token.prefix + ':"', token); | ||
@@ -272,7 +281,7 @@ value = prefix + token.value; | ||
item = this._blankNodes[token.value] || | ||
(this._blankNodes[token.value] = '_:b' + this._blankNodeCount++); | ||
(this._blankNodes[token.value] = '_:b' + blankNodeCount++); | ||
} | ||
else { | ||
var prefix = this._prefixes[token.prefix]; | ||
if (prefix === _undefined) | ||
if (prefix === undefined) | ||
return this._error('Undefined prefix "' + token.prefix + ':"', token); | ||
@@ -288,4 +297,4 @@ item = prefix + token.value; | ||
// Stack the current list triple and start a new triple with a blank node as subject. | ||
itemHead = '_:b' + this._blankNodeCount++; | ||
item = '_:b' + this._blankNodeCount++; | ||
itemHead = '_:b' + blankNodeCount++; | ||
item = '_:b' + blankNodeCount++; | ||
stack.push({ subject: itemHead, predicate: RDF_FIRST, object: item, type: 'blank' }); | ||
@@ -297,3 +306,3 @@ this._subject = item; | ||
// Stack the current list triple and start a new list | ||
itemHead = '_:b' + this._blankNodeCount++; | ||
itemHead = '_:b' + blankNodeCount++; | ||
stack.push({ subject: itemHead, predicate: RDF_FIRST, object: RDF_NIL, type: 'list' }); | ||
@@ -342,3 +351,3 @@ this._subject = null; | ||
if (itemHead === null) | ||
this._subject = itemHead = '_:b' + this._blankNodeCount++; | ||
this._subject = itemHead = '_:b' + blankNodeCount++; | ||
@@ -505,3 +514,3 @@ // Is this the first element of the list? | ||
this._lexer.tokenize(input, function (error, token) { | ||
if (self._readCallback !== _undefined) { | ||
if (self._readCallback !== undefined) { | ||
if (error !== null) | ||
@@ -522,2 +531,5 @@ self._callback(error); | ||
// The empty function | ||
function noop() {} | ||
// ## Exports | ||
@@ -524,0 +536,0 @@ |
@@ -35,3 +35,3 @@ // **N3Util** provides N3 utility functions | ||
getLiteralType: function (literal) { | ||
var match = /^"[^]*"(?:\^\^(.+)|(@)[\-a-z]+)?$/i.exec(literal); | ||
var match = /^"[^]*"(?:\^\^([^"\^]+)|(@)[^@"]+)?$/.exec(literal); | ||
if (!match) | ||
@@ -44,3 +44,3 @@ throw new Error(literal + ' is not a literal'); | ||
getLiteralLanguage: function (literal) { | ||
var match = /^"[^]*"(?:@([\-a-z]+)|\^\^.+)?$/i.exec(literal); | ||
var match = /^"[^]*"(?:@([^@"]+)|\^\^[^"\^]+)?$/.exec(literal); | ||
if (!match) | ||
@@ -47,0 +47,0 @@ throw new Error(literal + ' is not a literal'); |
// **N3Writer** writes N3 documents. | ||
// Matches a literal as represented in memory by the N3 library | ||
var N3LiteralMatcher = /^"((?:.|\n|\r)*)"(?:\^\^(.+)|@([\-a-z]+))?$/i; | ||
var N3LiteralMatcher = /^"([^]*)"(?:\^\^(.+)|@([\-a-z]+))?$/i; | ||
@@ -6,0 +6,0 @@ // rdf:type predicate (for 'a' abbreviation) |
{ | ||
"name": "n3", | ||
"version": "0.3.3", | ||
"version": "0.3.4", | ||
"description": "Lightning fast, asynchronous, streaming Turtle / N3 / RDF library.", | ||
@@ -33,9 +33,9 @@ "author": "Ruben Verborgh <ruben.verborgh@gmail.com>", | ||
"scripts": { | ||
"test": "./node_modules/mocha/bin/mocha", | ||
"hint": "./node_modules/jshint/bin/jshint lib perf test", | ||
"browser": "./browser/build-browser-versions", | ||
"coverage": "./node_modules/istanbul/lib/cli.js cover node_modules/mocha/bin/_mocha -- -R spec --timeout 100", | ||
"spec": "./spec/turtle-spec.js", | ||
"test": "mocha", | ||
"hint": "jshint lib perf test", | ||
"browser": "node browser/build-browser-versions", | ||
"coverage": "istanbul cover node_modules/.bin/_mocha -- -R spec --timeout 100", | ||
"spec": "node spec/turtle-spec.js", | ||
"spec-clean": "rm -r spec/turtle", | ||
"docs": "./node_modules/.bin/docco lib/*.js" | ||
"docs": "docco lib/*.js" | ||
}, | ||
@@ -42,0 +42,0 @@ "repository": { |
#!/usr/bin/env node | ||
var n3 = require('../n3'); | ||
var n3 = require('../N3'); | ||
var fs = require('fs'), | ||
@@ -4,0 +4,0 @@ assert = require('assert'); |
#!/usr/bin/env node | ||
var n3 = require('../n3'); | ||
var n3 = require('../N3'); | ||
var fs = require('fs'), | ||
@@ -4,0 +4,0 @@ assert = require('assert'); |
#!/usr/bin/env node | ||
var n3 = require('../n3'); | ||
var n3 = require('../N3'); | ||
var assert = require('assert'); | ||
@@ -4,0 +4,0 @@ |
@@ -23,2 +23,4 @@ var N3Parser = require('../N3').Parser; | ||
describe('An N3Parser instance', function () { | ||
beforeEach(N3Parser._resetBlankNodeIds); | ||
it('should parse the empty string', | ||
@@ -25,0 +27,0 @@ shouldParse('' |
@@ -63,2 +63,6 @@ var N3Util = require('../N3').Util; | ||
it('matches a literal with a language that contains a number', function () { | ||
N3Util.isLiteral('"English"@es-419').should.be.true; | ||
}); | ||
it('matches a literal with a type', function () { | ||
@@ -124,2 +128,6 @@ N3Util.isLiteral('"3"^^http://www.w3.org/2001/XMLSchema#integer').should.be.true; | ||
it('gets the value of a literal with a language that contains a number', function () { | ||
N3Util.getLiteralValue('"English"@es-419').should.equal('English'); | ||
}); | ||
it('gets the value of a literal with a type', function () { | ||
@@ -159,2 +167,6 @@ N3Util.getLiteralValue('"3"^^http://www.w3.org/2001/XMLSchema#integer').should.equal('3'); | ||
it('gets the type of a literal with a language that contains a number', function () { | ||
N3Util.getLiteralType('"English"@es-419').should.equal('http://www.w3.org/1999/02/22-rdf-syntax-ns#langString'); | ||
}); | ||
it('gets the type of a literal with a type', function () { | ||
@@ -194,2 +206,6 @@ N3Util.getLiteralType('"3"^^http://www.w3.org/2001/XMLSchema#integer').should.equal('http://www.w3.org/2001/XMLSchema#integer'); | ||
it('gets the language of a literal with a language that contains a number', function () { | ||
N3Util.getLiteralLanguage('"English"@es-419').should.equal('es-419'); | ||
}); | ||
it('normalizes the language to lowercase', function () { | ||
@@ -196,0 +212,0 @@ N3Util.getLiteralLanguage('"English"@en-GB').should.equal('en-gb'); |
@@ -86,2 +86,10 @@ var N3Writer = require('../N3').Writer; | ||
it('should serialize a literal containing a line separator', | ||
shouldSerialize([['a', 'b', '"c\u2028de"']], | ||
'<a> <b> "c\u2028de".\n')); | ||
it('should serialize a literal containing a paragraph separator', | ||
shouldSerialize([['a', 'b', '"c\u2029de"']], | ||
'<a> <b> "c\u2029de".\n')); | ||
it('should serialize blank nodes', | ||
@@ -88,0 +96,0 @@ shouldSerialize([['_:a', 'b', '_:c']], |
Sorry, the diff of this file is not supported yet
194696
3937