Comparing version 0.3.4 to 0.3.5
@@ -9,5 +9,5 @@ // **N3Lexer** tokenizes N3 documents. | ||
_prefix: /^((?:[A-Za-z\xc0-\xd6\xd8-\xf6\xf8-\u02ff\u0370-\u037d\u037f-\u1fff\u200c\u200d\u2070-\u218f\u2c00-\u2fef\u3001-\ud7ff\uf900-\ufdcf\ufdf0-\ufffd]|[\ud800-\udb7f][\udc00-\udfff])(?:[\.\-0-9A-Z_a-z\xb7\xc0-\xd6\xd8-\xf6\xf8-\u037d\u037f-\u1fff\u200c\u200d\u203f\u2040\u2070-\u218f\u2c00-\u2fef\u3001-\ud7ff\uf900-\ufdcf\ufdf0-\ufffd]|[\ud800-\udb7f][\udc00-\udfff])*)?:(?=\s|<)/, | ||
_prefixedName: /^((?:[A-Z_a-z\xc0-\xd6\xd8-\xf6\xf8-\u02ff\u0370-\u037d\u037f-\u1fff\u200c\u200d\u2070-\u218f\u2c00-\u2fef\u3001-\ud7ff\uf900-\ufdcf\ufdf0-\ufffd]|[\ud800-\udb7f][\udc00-\udfff])(?:[\.\-0-9A-Z_a-z\xb7\xc0-\xd6\xd8-\xf6\xf8-\u037d\u037f-\u1fff\u200c\u200d\u203f\u2040\u2070-\u218f\u2c00-\u2fef\u3001-\ud7ff\uf900-\ufdcf\ufdf0-\ufffd]|[\ud800-\udb7f][\udc00-\udfff])*)?:((?:(?:[0-:A-Z_a-z\xc0-\xd6\xd8-\xf6\xf8-\u02ff\u0370-\u037d\u037f-\u1fff\u200c\u200d\u2070-\u218f\u2c00-\u2fef\u3001-\ud7ff\uf900-\ufdcf\ufdf0-\ufffd]|[\ud800-\udb7f][\udc00-\udfff]|%[0-9a-fA-F]{2}|\\[!#-\/;=?\-@_~])(?:(?:[\.\-0-:A-Z_a-z\xb7\xc0-\xd6\xd8-\xf6\xf8-\u037d\u037f-\u1fff\u200c\u200d\u203f\u2040\u2070-\u218f\u2c00-\u2fef\u3001-\ud7ff\uf900-\ufdcf\ufdf0-\ufffd]|[\ud800-\udb7f][\udc00-\udfff]|%[0-9a-fA-F]{2}|\\[!#-\/;=?\-@_~])*(?:[\-0-:A-Z_a-z\xb7\xc0-\xd6\xd8-\xf6\xf8-\u037d\u037f-\u1fff\u200c\u200d\u203f\u2040\u2070-\u218f\u2c00-\u2fef\u3001-\ud7ff\uf900-\ufdcf\ufdf0-\ufffd]|[\ud800-\udb7f][\udc00-\udfff]|%[0-9a-fA-F]{2}|\\[!#-\/;=?\-@_~]))?)?)(?=[\s#;,)\]]|\.[\s#\(\[<"'])/, | ||
_number: /^[\-+]?(?:\d+\.?\d*([eE](?:[\-\+])?\d+)|\d+\.\d+|\.\d+|\d+)(?=[\s#.;,)\]])/, | ||
_boolean: /^(?:true|false)(?=[\s#.;,)\]])/, | ||
_prefixedName: /^((?:[A-Z_a-z\xc0-\xd6\xd8-\xf6\xf8-\u02ff\u0370-\u037d\u037f-\u1fff\u200c\u200d\u2070-\u218f\u2c00-\u2fef\u3001-\ud7ff\uf900-\ufdcf\ufdf0-\ufffd]|[\ud800-\udb7f][\udc00-\udfff])(?:[\.\-0-9A-Z_a-z\xb7\xc0-\xd6\xd8-\xf6\xf8-\u037d\u037f-\u1fff\u200c\u200d\u203f\u2040\u2070-\u218f\u2c00-\u2fef\u3001-\ud7ff\uf900-\ufdcf\ufdf0-\ufffd]|[\ud800-\udb7f][\udc00-\udfff])*)?:((?:(?:[0-:A-Z_a-z\xc0-\xd6\xd8-\xf6\xf8-\u02ff\u0370-\u037d\u037f-\u1fff\u200c\u200d\u2070-\u218f\u2c00-\u2fef\u3001-\ud7ff\uf900-\ufdcf\ufdf0-\ufffd]|[\ud800-\udb7f][\udc00-\udfff]|%[0-9a-fA-F]{2}|\\[!#-\/;=?\-@_~])(?:(?:[\.\-0-:A-Z_a-z\xb7\xc0-\xd6\xd8-\xf6\xf8-\u037d\u037f-\u1fff\u200c\u200d\u203f\u2040\u2070-\u218f\u2c00-\u2fef\u3001-\ud7ff\uf900-\ufdcf\ufdf0-\ufffd]|[\ud800-\udb7f][\udc00-\udfff]|%[0-9a-fA-F]{2}|\\[!#-\/;=?\-@_~])*(?:[\-0-:A-Z_a-z\xb7\xc0-\xd6\xd8-\xf6\xf8-\u037d\u037f-\u1fff\u200c\u200d\u203f\u2040\u2070-\u218f\u2c00-\u2fef\u3001-\ud7ff\uf900-\ufdcf\ufdf0-\ufffd]|[\ud800-\udb7f][\udc00-\udfff]|%[0-9a-fA-F]{2}|\\[!#-\/;=?\-@_~]))?)?)(?=[,;\s#()\[\]]|\.[\s#()\[\]<"'])/, | ||
_number: /^[\-+]?(?:\d+\.?\d*([eE](?:[\-\+])?\d+)|\d+\.\d+|\.\d+|\d+)(?=[.,;\s#()\[\]])/, | ||
_boolean: /^(?:true|false)(?=[.,;\s#()\[\]])/, | ||
_dot: /^\.(?!\d)/, // If a digit follows a dot, it is a number, not punctuation. | ||
@@ -18,3 +18,2 @@ _punctuation: /^[;,\[\]\(\)]/, | ||
_sparqlKeyword: /^(?:PREFIX|BASE)(?=\s)/i, | ||
_type: /^\^\^(?:<([^>]*)>|([A-Z_a-z\u00c0-\u00d6\u00d8-\u00f6\u00f8-\u02ff\u0370-\u037d\u037f-\u1fff\u200c-\u200d\u2070-\u218f\u2c00-\u2fef\u3001-\ud7ff\uf900-\ufdcf\ufdf0-\ufffd][\-0-9A-Z_a-z\u00b7\u00c0-\u00d6\u00d8-\u00f6\u00f8-\u037d\u037f-\u1fff\u200c-\u200d\u203f-\u2040\u2070-\u218f\u2c00-\u2fef\u3001-\ud7ff\uf900-\ufdcf\ufdf0-\ufffd]*)?:([A-Z_a-z\u00c0-\u00d6\u00d8-\u00f6\u00f8-\u02ff\u0370-\u037d\u037f-\u1fff\u200c-\u200d\u2070-\u218f\u2c00-\u2fef\u3001-\ud7ff\uf900-\ufdcf\ufdf0-\ufffd][\-0-9A-Z_a-z\u00b7\u00c0-\u00d6\u00d8-\u00f6\u00f8-\u037d\u037f-\u1fff\u200c-\u200d\u203f-\u2040\u2070-\u218f\u2c00-\u2fef\u3001-\ud7ff\uf900-\ufdcf\ufdf0-\ufffd]*)(?=[\s\.;,)#]))/, | ||
_shortPredicates: /^a(?=\s+|<)/, | ||
@@ -90,4 +89,17 @@ _newline: /^[ \t]*(?:#[^\n\r]*)?(?:\r\n|\n|\r)[ \t]*/, | ||
switch (firstChar) { | ||
case '^': | ||
// Try to match a type. | ||
if (input.length === 1) break; | ||
else if (input[1] !== '^') return reportSyntaxError(this); | ||
this._prevTokenType = '^'; | ||
// Move to type IRI or prefixed name. | ||
input = input.substr(2); | ||
if (input[0] !== '<') { | ||
inconclusive = true; | ||
break; | ||
} | ||
// Fall through in case the type is an IRI. | ||
case '<': | ||
// Try to find a full URI. | ||
// Try to find a full IRI. | ||
if (match = this._iri.exec(input)) { | ||
@@ -143,16 +155,2 @@ unescaped = this._unescape(match[1]); | ||
case '^': | ||
// Try to find a type. | ||
if (match = this._type.exec(input)) { | ||
token.type = 'type'; | ||
if (!match[2]) { | ||
token.value = match[1]; | ||
} | ||
else { | ||
token.prefix = match[2]; | ||
token.value = match[3]; | ||
} | ||
} | ||
break; | ||
case '.': | ||
@@ -253,2 +251,14 @@ // Try to find a dot as punctuation. | ||
// A type token is special: it can only be emitted after an IRI or prefixed name is read. | ||
if (this._prevTokenType === '^') { | ||
switch (token.type) { | ||
case 'IRI': | ||
case 'prefixed': | ||
token.type = 'type'; | ||
break; | ||
default: | ||
match = null; | ||
} | ||
} | ||
// What if nothing of the above was found? | ||
@@ -255,0 +265,0 @@ if (match === null) { |
@@ -35,3 +35,3 @@ // **N3Util** provides N3 utility functions | ||
getLiteralType: function (literal) { | ||
var match = /^"[^]*"(?:\^\^([^"\^]+)|(@)[^@"]+)?$/.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 = /^"[^]*"(?:@([^@"]+)|\^\^[^"\^]+)?$/.exec(literal); | ||
var match = /^"[^]*"(?:@([^@"]+)|\^\^[^"]+)?$/.exec(literal); | ||
if (!match) | ||
@@ -47,0 +47,0 @@ throw new Error(literal + ' is not a literal'); |
{ | ||
"name": "n3", | ||
"version": "0.3.4", | ||
"version": "0.3.5", | ||
"description": "Lightning fast, asynchronous, streaming Turtle / N3 / RDF library.", | ||
@@ -5,0 +5,0 @@ "author": "Ruben Verborgh <ruben.verborgh@gmail.com>", |
@@ -193,2 +193,10 @@ var N3Lexer = require('../N3').Lexer; | ||
it('should not tokenize a single hat', | ||
shouldNotTokenize('^', | ||
'Syntax error: unexpected "^" on line 1.')); | ||
it('should not tokenize a double hat followed by a non-IRI', | ||
shouldNotTokenize('^^1', | ||
'Syntax error: unexpected "1" on line 1.')); | ||
it('should tokenize a single-quoted string literal', | ||
@@ -441,3 +449,3 @@ shouldTokenize("'string' ", | ||
it('should tokenize blank nodes', | ||
shouldTokenize('[] [<a> <b>]', | ||
shouldTokenize('[] [<a> <b>] [a:b "c"^^d:e][a:b[]]', | ||
{ type: 'bracketopen', line: 1 }, | ||
@@ -449,2 +457,12 @@ { type: 'bracketclose', line: 1 }, | ||
{ type: 'bracketclose', line: 1 }, | ||
{ type: 'bracketopen', line: 1 }, | ||
{ type: 'prefixed', prefix: 'a', value: 'b', line: 1 }, | ||
{ type: 'literal', value: '"c"', line: 1 }, | ||
{ type: 'type', prefix: 'd', value: 'e', line: 1 }, | ||
{ type: 'bracketclose', line: 1 }, | ||
{ type: 'bracketopen', line: 1 }, | ||
{ type: 'prefixed', prefix: 'a', value: 'b', line: 1 }, | ||
{ type: 'bracketopen', line: 1 }, | ||
{ type: 'bracketclose', line: 1 }, | ||
{ type: 'bracketclose', line: 1 }, | ||
{ type: 'eof', line: 1 })); | ||
@@ -466,3 +484,3 @@ | ||
it('should tokenize mixed lists', | ||
shouldTokenize('<a> <b> (1 "2" :o)', | ||
shouldTokenize('<a> <b> (1 "2" :o)(1()(1))', | ||
{ type: 'IRI', value: 'a', line: 1 }, | ||
@@ -475,2 +493,10 @@ { type: 'IRI', value: 'b', line: 1 }, | ||
{ type: 'listend', line: 1 }, | ||
{ type: 'liststart', line: 1 }, | ||
{ type: 'literal', value: '"1"^^http://www.w3.org/2001/XMLSchema#integer', line: 1 }, | ||
{ type: 'liststart', line: 1 }, | ||
{ type: 'listend', line: 1 }, | ||
{ type: 'liststart', line: 1 }, | ||
{ type: 'literal', value: '"1"^^http://www.w3.org/2001/XMLSchema#integer', line: 1 }, | ||
{ type: 'listend', line: 1 }, | ||
{ type: 'listend', line: 1 }, | ||
{ type: 'eof', line: 1 })); | ||
@@ -477,0 +503,0 @@ |
195911
3968