n3 1.26.0 → 2.0.0-beta.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/index.js CHANGED
@@ -3,12 +3,6 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- Object.defineProperty(exports, "BaseIRI", {
7
- enumerable: true,
8
- get: function () {
9
- return _BaseIRI.default;
10
- }
11
- });
12
6
  Object.defineProperty(exports, "BlankNode", {
13
7
  enumerable: true,
14
8
  get: function () {
@@ -147,9 +141,9 @@ var _N3StreamParser = _interopRequireDefault(require("./N3StreamParser"));
147
141
  var _N3StreamWriter = _interopRequireDefault(require("./N3StreamWriter"));
148
142
  var Util = _interopRequireWildcard(require("./N3Util"));
149
143
  exports.Util = Util;
150
- var _BaseIRI = _interopRequireDefault(require("./BaseIRI"));
151
144
  var _N3DataFactory = _interopRequireWildcard(require("./N3DataFactory"));
152
- function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); }
145
+ function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
146
+ function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
153
147
  function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
154
148
  // Named exports
155
149
  // Export all named exports as a default object for backward compatibility
@@ -164,7 +158,6 @@ var _default = exports.default = {
164
158
  StreamWriter: _N3StreamWriter.default,
165
159
  Util,
166
160
  Reasoner: _N3Reasoner.default,
167
- BaseIRI: _BaseIRI.default,
168
161
  DataFactory: _N3DataFactory.default,
169
162
  Term: _N3DataFactory.Term,
170
163
  NamedNode: _N3DataFactory.NamedNode,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "n3",
3
- "version": "1.26.0",
3
+ "version": "2.0.0-beta.2",
4
4
  "description": "Lightning fast, asynchronous, streaming Turtle / N3 / RDF library.",
5
5
  "author": "Ruben Verborgh <ruben.verborgh@gmail.com>",
6
6
  "keywords": [
@@ -25,6 +25,7 @@
25
25
  ],
26
26
  "dependencies": {
27
27
  "buffer": "^6.0.3",
28
+ "queue-microtask": "^1.1.2",
28
29
  "readable-stream": "^4.0.0"
29
30
  },
30
31
  "devDependencies": {
@@ -42,7 +43,7 @@
42
43
  "eslint-plugin-jest": "^28.8.3",
43
44
  "jest": "^29.7.0",
44
45
  "pre-commit": "^1.2.2",
45
- "rdf-isomorphic": "^2.0.0",
46
+ "rdf-isomorphic": "^1.3.1",
46
47
  "rdf-test-suite": "^1.25.0",
47
48
  "streamify-string": "^1.0.1",
48
49
  "uglify-js": "^3.14.3"
@@ -54,16 +55,27 @@
54
55
  "test": "jest",
55
56
  "lint": "eslint src perf test spec",
56
57
  "prepare": "npm run build",
57
- "spec": "npm run spec-turtle && npm run spec-ntriples && npm run spec-nquads && npm run spec-trig",
58
- "spec-earl": "npm run spec-earl-turtle && npm run spec-earl-ntriples && npm run spec-earl-nquads && npm run spec-earl-trig",
59
- "spec-ntriples": "rdf-test-suite spec/parser.js https://w3c.github.io/rdf-tests/rdf/rdf11/rdf-n-triples/manifest.ttl -i '{ \"format\": \"n-triples\" }' -c .rdf-test-suite-cache/",
60
- "spec-nquads": "rdf-test-suite spec/parser.js https://w3c.github.io/rdf-tests/rdf/rdf11/rdf-n-quads/manifest.ttl -i '{ \"format\": \"n-quads\" }' -c .rdf-test-suite-cache/",
61
- "spec-turtle": "rdf-test-suite spec/parser.js https://w3c.github.io/rdf-tests/rdf/rdf11/rdf-turtle/manifest.ttl -i '{ \"format\": \"turtle\" }' -c .rdf-test-suite-cache/",
62
- "spec-trig": "rdf-test-suite spec/parser.js https://w3c.github.io/rdf-tests/rdf/rdf11/rdf-trig/manifest.ttl -i '{ \"format\": \"trig\" }' -c .rdf-test-suite-cache/",
63
- "spec-earl-ntriples": "rdf-test-suite spec/parser.js https://w3c.github.io/rdf-tests/rdf/rdf11/rdf-n-triples/manifest.ttl -i '{ \"format\": \"n-triples\" }' -c .rdf-test-suite-cache/ -o earl -p spec/earl-meta.json > spec/earl-ntriples.ttl",
64
- "spec-earl-nquads": "rdf-test-suite spec/parser.js https://w3c.github.io/rdf-tests/rdf/rdf11/rdf-n-quads/manifest.ttl -i '{ \"format\": \"n-quads\" }' -c .rdf-test-suite-cache/ -o earl -p spec/earl-meta.json > spec/earl-nquads.ttl",
65
- "spec-earl-turtle": "rdf-test-suite spec/parser.js https://w3c.github.io/rdf-tests/rdf/rdf11/rdf-turtle/manifest.ttl -i '{ \"format\": \"turtle\" }' -c .rdf-test-suite-cache/ -o earl -p spec/earl-meta.json > spec/earl-turtle.ttl",
66
- "spec-earl-trig": "rdf-test-suite spec/parser.js https://w3c.github.io/rdf-tests/rdf/rdf11/rdf-trig/manifest.ttl -i '{ \"format\": \"trig\" }' -c .rdf-test-suite-cache/ -o earl -p spec/earl-meta.json > spec/earl-trig.ttl",
58
+ "spec": "npm run spec-1-1 && npm run spec-1-2",
59
+ "spec-1-1": "npm run spec-1-1-turtle && npm run spec-1-1-ntriples && npm run spec-1-1-nquads && npm run spec-1-1-trig",
60
+ "spec-1-1-earl": "npm run spec-1-1-earl-turtle && npm run spec-1-1-earl-ntriples && npm run spec-1-1-earl-nquads && npm run spec-1-1-earl-trig",
61
+ "spec-1-1-ntriples": "rdf-test-suite spec/parser.js https://w3c.github.io/rdf-tests/rdf/rdf11/rdf-n-triples/manifest.ttl -i '{ \"format\": \"n-triples\" }' -c .rdf-test-suite-cache/",
62
+ "spec-1-1-nquads": "rdf-test-suite spec/parser.js https://w3c.github.io/rdf-tests/rdf/rdf11/rdf-n-quads/manifest.ttl -i '{ \"format\": \"n-quads\" }' -c .rdf-test-suite-cache/",
63
+ "spec-1-1-turtle": "rdf-test-suite spec/parser.js https://w3c.github.io/rdf-tests/rdf/rdf11/rdf-turtle/manifest.ttl -i '{ \"format\": \"turtle\" }' -c .rdf-test-suite-cache/",
64
+ "spec-1-1-trig": "rdf-test-suite spec/parser.js https://w3c.github.io/rdf-tests/rdf/rdf11/rdf-trig/manifest.ttl -i '{ \"format\": \"trig\" }' -c .rdf-test-suite-cache/",
65
+ "spec-1-1-earl-ntriples": "rdf-test-suite spec/parser.js https://w3c.github.io/rdf-tests/rdf/rdf11/rdf-n-triples/manifest.ttl -i '{ \"format\": \"n-triples\" }' -c .rdf-test-suite-cache/ -o earl -p spec/earl-meta.json > spec/earl-ntriples.ttl",
66
+ "spec-1-1-earl-nquads": "rdf-test-suite spec/parser.js https://w3c.github.io/rdf-tests/rdf/rdf11/rdf-n-quads/manifest.ttl -i '{ \"format\": \"n-quads\" }' -c .rdf-test-suite-cache/ -o earl -p spec/earl-meta.json > spec/earl-nquads.ttl",
67
+ "spec-1-1-earl-turtle": "rdf-test-suite spec/parser.js https://w3c.github.io/rdf-tests/rdf/rdf11/rdf-turtle/manifest.ttl -i '{ \"format\": \"turtle\" }' -c .rdf-test-suite-cache/ -o earl -p spec/earl-meta.json > spec/earl-turtle.ttl",
68
+ "spec-1-1-earl-trig": "rdf-test-suite spec/parser.js https://w3c.github.io/rdf-tests/rdf/rdf11/rdf-trig/manifest.ttl -i '{ \"format\": \"trig\" }' -c .rdf-test-suite-cache/ -o earl -p spec/earl-meta.json > spec/earl-trig.ttl",
69
+ "spec-1-2": "npm run spec-1-2-turtle && npm run spec-1-2-ntriples && npm run spec-1-2-nquads && npm run spec-1-2-trig",
70
+ "spec-1-2-earl": "npm run spec-1-2-earl-turtle && npm run spec-1-2-earl-ntriples && npm run spec-1-2-earl-nquads && npm run spec-1-2-earl-trig",
71
+ "spec-1-2-ntriples": "rdf-test-suite spec/parser.js https://w3c.github.io/rdf-tests/rdf/rdf12/rdf-n-triples/syntax/manifest.ttl -i '{ \"format\": \"n-triples\" }' -c .rdf-test-suite-cache/",
72
+ "spec-1-2-nquads": "rdf-test-suite spec/parser.js https://w3c.github.io/rdf-tests/rdf/rdf12/rdf-n-quads/syntax/manifest.ttl -i '{ \"format\": \"n-quads\" }' -c .rdf-test-suite-cache/",
73
+ "spec-1-2-turtle": "rdf-test-suite spec/parser.js https://w3c.github.io/rdf-tests/rdf/rdf12/rdf-turtle/syntax/manifest.ttl -i '{ \"format\": \"turtle\" }' -c .rdf-test-suite-cache/",
74
+ "spec-1-2-trig": "rdf-test-suite spec/parser.js https://w3c.github.io/rdf-tests/rdf/rdf12/rdf-trig/syntax/manifest.ttl -i '{ \"format\": \"trig\" }' -c .rdf-test-suite-cache/",
75
+ "spec-1-2-earl-ntriples": "rdf-test-suite spec/parser.js https://w3c.github.io/rdf-tests/rdf/rdf12/rdf-n-triples/syntax/manifest.ttl -i '{ \"format\": \"n-triples\" }' -c .rdf-test-suite-cache/ -o earl -p spec/earl-meta.json > spec/earl-ntriples.ttl",
76
+ "spec-1-2-earl-nquads": "rdf-test-suite spec/parser.js https://w3c.github.io/rdf-tests/rdf/rdf12/rdf-n-quads/syntax/manifest.ttl -i '{ \"format\": \"n-quads\" }' -c .rdf-test-suite-cache/ -o earl -p spec/earl-meta.json > spec/earl-nquads.ttl",
77
+ "spec-1-2-earl-turtle": "rdf-test-suite spec/parser.js https://w3c.github.io/rdf-tests/rdf/rdf12/rdf-turtle/syntax/manifest.ttl -i '{ \"format\": \"turtle\" }' -c .rdf-test-suite-cache/ -o earl -p spec/earl-meta.json > spec/earl-turtle.ttl",
78
+ "spec-1-2-earl-trig": "rdf-test-suite spec/parser.js https://w3c.github.io/rdf-tests/rdf/rdf12/rdf-trig/syntax/manifest.ttl -i '{ \"format\": \"trig\" }' -c .rdf-test-suite-cache/ -o earl -p spec/earl-meta.json > spec/earl-trig.ttl",
67
79
  "spec-clean": "rm -r .rdf-test-suite-cache/",
68
80
  "docs": "cd src && docco *.js -o ../docs && cd .."
69
81
  },
package/src/IRIs.js CHANGED
@@ -11,11 +11,13 @@ export default {
11
11
  string: `${XSD}string`,
12
12
  },
13
13
  rdf: {
14
- type: `${RDF}type`,
15
- nil: `${RDF}nil`,
16
- first: `${RDF}first`,
17
- rest: `${RDF}rest`,
18
- langString: `${RDF}langString`,
14
+ type: `${RDF}type`,
15
+ nil: `${RDF}nil`,
16
+ first: `${RDF}first`,
17
+ rest: `${RDF}rest`,
18
+ langString: `${RDF}langString`,
19
+ dirLangString: `${RDF}dirLangString`,
20
+ reifies: `${RDF}reifies`,
19
21
  },
20
22
  owl: {
21
23
  sameAs: 'http://www.w3.org/2002/07/owl#sameAs',
@@ -26,6 +28,5 @@ export default {
26
28
  },
27
29
  log: {
28
30
  implies: `${SWAP}log#implies`,
29
- isImpliedBy: `${SWAP}log#isImpliedBy`,
30
31
  },
31
32
  };
@@ -88,8 +88,17 @@ export class Literal extends Term {
88
88
  // Find the last quotation mark (e.g., '"abc"@en-us')
89
89
  const id = this.id;
90
90
  let atPos = id.lastIndexOf('"') + 1;
91
+ const dirPos = id.lastIndexOf('--');
91
92
  // If "@" it follows, return the remaining substring; empty otherwise
92
- return atPos < id.length && id[atPos++] === '@' ? id.substr(atPos).toLowerCase() : '';
93
+ return atPos < id.length && id[atPos++] === '@' ? (dirPos > atPos ? id.substr(0, dirPos) : id).substr(atPos).toLowerCase() : '';
94
+ }
95
+
96
+ // ### The direction of this literal
97
+ get direction() {
98
+ // Find the last double dash (e.g., '"abc"@en-us--ltr')
99
+ const id = this.id;
100
+ const atPos = id.lastIndexOf('--') + 2;
101
+ return atPos > 1 && atPos < id.length ? id.substr(atPos).toLowerCase() : '';
93
102
  }
94
103
 
95
104
  // ### The datatype IRI of this literal
@@ -104,8 +113,8 @@ export class Literal extends Term {
104
113
  const char = dtPos < id.length ? id[dtPos] : '';
105
114
  // If "^" it follows, return the remaining substring
106
115
  return char === '^' ? id.substr(dtPos + 2) :
107
- // If "@" follows, return rdf:langString; xsd:string otherwise
108
- (char !== '@' ? xsd.string : rdf.langString);
116
+ // If "@" follows, return rdf:langString or rdf:dirLangString; xsd:string otherwise
117
+ (char !== '@' ? xsd.string : (id.indexOf('--', dtPos) > 0 ? rdf.dirLangString : rdf.langString));
109
118
  }
110
119
 
111
120
  // ### Returns whether this object represents the same term as the other
@@ -119,14 +128,16 @@ export class Literal extends Term {
119
128
  this.termType === other.termType &&
120
129
  this.value === other.value &&
121
130
  this.language === other.language &&
131
+ ((this.direction === other.direction) || (this.direction === '' && !other.direction)) &&
122
132
  this.datatype.value === other.datatype.value;
123
133
  }
124
134
 
125
135
  toJSON() {
126
136
  return {
127
- termType: this.termType,
128
- value: this.value,
129
- language: this.language,
137
+ termType: this.termType,
138
+ value: this.value,
139
+ language: this.language,
140
+ direction: this.direction,
130
141
  datatype: { termType: 'NamedNode', value: this.datatypeString },
131
142
  };
132
143
  }
@@ -216,9 +227,22 @@ export function termFromId(id, factory, nested) {
216
227
  return factory.literal(id.substr(1, id.length - 2));
217
228
  // Literal with datatype or language
218
229
  const endPos = id.lastIndexOf('"', id.length - 1);
230
+ let languageOrDatatype;
231
+ if (id[endPos + 1] === '@') {
232
+ languageOrDatatype = id.substr(endPos + 2);
233
+ const dashDashIndex = languageOrDatatype.lastIndexOf('--');
234
+ if (dashDashIndex > 0 && dashDashIndex < languageOrDatatype.length) {
235
+ languageOrDatatype = {
236
+ language: languageOrDatatype.substr(0, dashDashIndex),
237
+ direction: languageOrDatatype.substr(dashDashIndex + 2),
238
+ };
239
+ }
240
+ }
241
+ else {
242
+ languageOrDatatype = factory.namedNode(id.substr(endPos + 3));
243
+ }
219
244
  return factory.literal(id.substr(1, endPos - 1),
220
- id[endPos + 1] === '@' ? id.substr(endPos + 2)
221
- : factory.namedNode(id.substr(endPos + 3)));
245
+ languageOrDatatype);
222
246
  case '[':
223
247
  id = JSON.parse(id);
224
248
  break;
@@ -255,7 +279,7 @@ export function termToId(term, nested) {
255
279
  case 'Variable': return `?${term.value}`;
256
280
  case 'DefaultGraph': return '';
257
281
  case 'Literal': return `"${term.value}"${
258
- term.language ? `@${term.language}` :
282
+ term.language ? `@${term.language}${term.direction ? `--${term.direction}` : ''}` :
259
283
  (term.datatype && term.datatype.value !== xsd.string ? `^^${term.datatype.value}` : '')}`;
260
284
  case 'Quad':
261
285
  const res = [
@@ -350,6 +374,11 @@ function literal(value, languageOrDataType) {
350
374
  if (typeof languageOrDataType === 'string')
351
375
  return new Literal(`"${value}"@${languageOrDataType.toLowerCase()}`);
352
376
 
377
+ // Create a language-tagged string with base direction
378
+ if (languageOrDataType !== undefined && !('termType' in languageOrDataType)) {
379
+ return new Literal(`"${value}"@${languageOrDataType.language.toLowerCase()}--${languageOrDataType.direction.toLowerCase()}`);
380
+ }
381
+
353
382
  // Automatically determine datatype for booleans and numbers
354
383
  let datatype = languageOrDataType ? languageOrDataType.value : '';
355
384
  if (datatype === '') {
package/src/N3Lexer.js CHANGED
@@ -1,5 +1,6 @@
1
1
  // **N3Lexer** tokenizes N3 documents.
2
2
  import { Buffer } from 'buffer';
3
+ import queueMicrotask from 'queue-microtask';
3
4
  import namespaces from './IRIs';
4
5
 
5
6
  const { xsd } = namespaces;
@@ -20,6 +21,7 @@ const lineModeRegExps = {
20
21
  _unescapedIri: true,
21
22
  _simpleQuotedString: true,
22
23
  _langcode: true,
24
+ _dircode: true,
23
25
  _blank: true,
24
26
  _newline: true,
25
27
  _comment: true,
@@ -37,15 +39,16 @@ export default class N3Lexer {
37
39
  this._unescapedIri = /^<([^\x00-\x20<>\\"\{\}\|\^\`]*)>[ \t]*/; // IRI without escape sequences; no unescaping
38
40
  this._simpleQuotedString = /^"([^"\\\r\n]*)"(?=[^"])/; // string without escape sequences
39
41
  this._simpleApostropheString = /^'([^'\\\r\n]*)'(?=[^'])/;
40
- this._langcode = /^@([a-z]+(?:-[a-z0-9]+)*)(?=[^a-z0-9\-])/i;
42
+ this._langcode = /^@([a-z]+(?:-[a-z0-9]+)*)(?=[^a-z0-9])/i;
43
+ this._dircode = /^--(ltr)|(rtl)/;
41
44
  this._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<])/;
42
45
  this._prefixed = /^((?:[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])*)?:((?:(?:[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}|\\[!#-\/;=?\-@_~]))?)?)(?:[ \t]+|(?=\.?[,;!\^\s#()\[\]\{\}"'<>]))/;
43
46
  this._variable = /^\?(?:(?:[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-: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])*)(?=[.,;!\^\s#()\[\]\{\}"'<>])/;
44
47
  this._blank = /^_:((?:[0-9A-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])*)(?:[ \t]+|(?=\.?[,;:\s#()\[\]\{\}"'<>]))/;
45
48
  this._number = /^[\-+]?(?:(\d+\.\d*|\.?\d+)[eE][\-+]?|\d*(\.)?)\d+(?=\.?[,;:\s#()\[\]\{\}"'<>])/;
46
49
  this._boolean = /^(?:true|false)(?=[.,;\s#()\[\]\{\}"'<>])/;
47
- this._keyword = /^@[a-z]+(?=[\s#<:])/i;
48
- this._sparqlKeyword = /^(?:PREFIX|BASE|GRAPH)(?=[\s#<])/i;
50
+ this._atKeyword = /^@[a-z]+(?=[\s#<:])/i;
51
+ this._keyword = /^(?:PREFIX|BASE|VERSION|GRAPH)(?=[\s#<])/i;
49
52
  this._shortPredicates = /^a(?=[\s#()\[\]\{\}"'<>])/;
50
53
  this._newline = /^[ \t]*(?:#[^\n\r]*)?(?:\r\n|\n|\r)[ \t]*/;
51
54
  this._comment = /#([^\n\r]*)/;
@@ -53,9 +56,6 @@ export default class N3Lexer {
53
56
  this._endOfFile = /^(?:#[^\n\r]*)?$/;
54
57
  options = options || {};
55
58
 
56
- // Whether the log:isImpliedBy predicate is supported
57
- this._isImpliedBy = options.isImpliedBy;
58
-
59
59
  // In line mode (N-Triples or N-Quads), only simple features may be parsed
60
60
  if (this._lineMode = !!options.lineMode) {
61
61
  this._n3Mode = false;
@@ -150,18 +150,19 @@ export default class N3Lexer {
150
150
  return reportSyntaxError(this);
151
151
  type = 'IRI';
152
152
  }
153
- // Try to find a nested triple
154
- else if (input.length > 1 && input[1] === '<')
153
+ // Try to find a triple term
154
+ else if (input.length > 2 && input[1] === '<' && input[2] === '(')
155
+ type = '<<(', matchLength = 3;
156
+ // Try to find a reified triple
157
+ else if (!this._lineMode && input.length > (inputFinished ? 1 : 2) && input[1] === '<')
155
158
  type = '<<', matchLength = 2;
156
159
  // Try to find a backwards implication arrow
157
- else if (this._n3Mode && input.length > 1 && input[1] === '=') {
158
- matchLength = 2;
159
- if (this._isImpliedBy) type = 'abbreviation', value = '<';
160
- else type = 'inverse', value = '>';
161
- }
160
+ else if (this._n3Mode && input.length > 1 && input[1] === '=')
161
+ type = 'inverse', matchLength = 2, value = '>';
162
162
  break;
163
163
 
164
164
  case '>':
165
+ // Try to find a reified triple
165
166
  if (input.length > 1 && input[1] === '>')
166
167
  type = '>>', matchLength = 2;
167
168
  break;
@@ -217,10 +218,10 @@ export default class N3Lexer {
217
218
 
218
219
  case '@':
219
220
  // Try to find a language code
220
- if (this._previousMarker === 'literal' && (match = this._langcode.exec(input)))
221
+ if (this._previousMarker === 'literal' && (match = this._langcode.exec(input)) && match[1] !== 'version')
221
222
  type = 'langcode', value = match[1];
222
223
  // Try to find a keyword
223
- else if (match = this._keyword.exec(input))
224
+ else if (match = this._atKeyword.exec(input))
224
225
  type = match[0];
225
226
  break;
226
227
 
@@ -245,6 +246,13 @@ export default class N3Lexer {
245
246
  case '9':
246
247
  case '+':
247
248
  case '-':
249
+ if (input[1] === '-') {
250
+ // Try to find a direction code
251
+ if (this._previousMarker === 'langcode' && (match = this._dircode.exec(input)))
252
+ type = 'dircode', matchLength = 2, value = (match[1] || match[2]), matchLength = value.length + 2;
253
+ break;
254
+ }
255
+
248
256
  // Try to find a number. Since it can contain (but not end with) a dot,
249
257
  // we always need a non-dot character before deciding it is a number.
250
258
  // Therefore, try inserting a space if we're at the end of the input.
@@ -262,8 +270,10 @@ export default class N3Lexer {
262
270
  case 'P':
263
271
  case 'G':
264
272
  case 'g':
273
+ case 'V':
274
+ case 'v':
265
275
  // Try to find a SPARQL-style keyword
266
- if (match = this._sparqlKeyword.exec(input))
276
+ if (match = this._keyword.exec(input))
267
277
  type = match[0].toUpperCase();
268
278
  else
269
279
  inconclusive = true;
@@ -300,13 +310,23 @@ export default class N3Lexer {
300
310
  case '!':
301
311
  if (!this._n3Mode)
302
312
  break;
313
+ case ')':
314
+ if (!inputFinished && (input.length === 1 || (input.length === 2 && input[1] === '>'))) {
315
+ // Don't consume yet, as it *could* become a triple term end.
316
+ break;
317
+ }
318
+ // Try to find a triple term
319
+ if (input.length > 2 && input[1] === '>' && input[2] === '>') {
320
+ type = ')>>', matchLength = 3;
321
+ break;
322
+ }
303
323
  case ',':
304
324
  case ';':
305
325
  case '[':
306
326
  case ']':
307
327
  case '(':
308
- case ')':
309
328
  case '}':
329
+ case '~':
310
330
  if (!this._lineMode) {
311
331
  matchLength = 1;
312
332
  type = firstChar;