Comparing version 1.0.2 to 1.0.3
@@ -20,2 +20,16 @@ // **N3Lexer** tokenizes N3 documents. | ||
var lineModeRegExps = { | ||
_iri: true, | ||
_unescapedIri: true, | ||
_unescapedQuote: true, | ||
_singleQuote: true, | ||
_langcode: true, | ||
_blank: true, | ||
_newline: true, | ||
_comment: true, | ||
_whitespace: true, | ||
_endOfFile: true, | ||
}; | ||
var invalidRegExp = /$0^/; | ||
// ## Constructor | ||
@@ -28,20 +42,15 @@ function N3Lexer(options) { | ||
// In line mode (N-Triples or N-Quads), only simple features may be parsed | ||
if (options.lineMode) { | ||
if (this._lineMode = !!options.lineMode) { | ||
this._n3Mode = false; | ||
// Don't tokenize special literals | ||
this._tripleApos = this._tripleQuote = this._number = this._boolean = /$0^/; | ||
// Swap the tokenize method for a restricted version | ||
var self = this; | ||
this._tokenize = this.tokenize; | ||
this.tokenize = function (input, callback) { | ||
this._tokenize(input, function (error, token) { | ||
if (!error && /^(?:IRI|blank|literal|langcode|typeIRI|\.|eof)$/.test(token.type)) | ||
callback && callback(error, token); | ||
else | ||
callback && callback(error || self._syntaxError(token.type, callback = null)); | ||
}); | ||
}; | ||
for (var key in this) { | ||
if (!(key in lineModeRegExps) && this[key] instanceof RegExp) | ||
this[key] = invalidRegExp; | ||
} | ||
} | ||
// Enable N3 functionality by default | ||
this._n3Mode = options.n3 !== false; | ||
// Disable comment tokens by default | ||
// When not in line mode, enable N3 functionality by default | ||
else { | ||
this._n3Mode = options.n3 !== false; | ||
} | ||
// Don't output comment tokens by default | ||
this._comments = !!options.comments; | ||
@@ -307,5 +316,6 @@ } | ||
case '}': | ||
// The next token is punctuation | ||
matchLength = 1; | ||
type = firstChar; | ||
if (!this._lineMode) { | ||
matchLength = 1; | ||
type = firstChar; | ||
} | ||
break; | ||
@@ -312,0 +322,0 @@ |
@@ -112,3 +112,3 @@ // **N3Writer** writes N3 documents. | ||
this._encodeObject(object) + | ||
(graph && graph.value ? ' ' + this._encodeIriOrBlank(graph) + '.\n' : '.\n'); | ||
(graph && graph.value ? ' ' + this._encodeIriOrBlank(graph) + ' .\n' : ' .\n'); | ||
}, | ||
@@ -115,0 +115,0 @@ |
{ | ||
"name": "n3", | ||
"version": "1.0.2", | ||
"version": "1.0.3", | ||
"description": "Lightning fast, asynchronous, streaming Turtle / N3 / RDF library.", | ||
@@ -5,0 +5,0 @@ "author": "Ruben Verborgh <ruben.verborgh@gmail.com>", |
@@ -343,3 +343,3 @@ # Lightning fast, asynchronous, streaming RDF for JavaScript | ||
- `N3.Store` implements | ||
[`Sink`](http://rdf.js.org/#stream-interface) | ||
[`Sink`](http://rdf.js.org/#sink-interface) | ||
@@ -346,0 +346,0 @@ ## License and contributions |
2711
127928