n3 1.12.2 → 1.15.0

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.
@@ -48,12 +48,6 @@ class Term {
48
48
 
49
49
  get value() {
50
50
  return this.id;
51
- } // ### Implement hashCode for Immutable.js, since we implement `equals`
52
- // https://immutable-js.com/docs/v4.0.0/ValueObject/#hashCode()
53
-
54
-
55
- get hashCode() {
56
- return 0;
57
51
  } // ### Returns whether this object represents the same term as the other
58
52
 
59
53
 
@@ -63,6 +57,12 @@ class Term {
63
57
  if (other instanceof Term) return this.id === other.id; // Otherwise, compare term type and value
64
58
 
65
59
  return !!other && this.termType === other.termType && this.value === other.value;
60
+ } // ### Implement hashCode for Immutable.js, since we implement `equals`
61
+ // https://immutable-js.com/docs/v4.0.0/ValueObject/#hashCode()
62
+
63
+
64
+ hashCode() {
65
+ return 0;
66
66
  } // ### Returns a plain object representation of this term
67
67
 
68
68
 
package/lib/N3Lexer.js CHANGED
@@ -109,7 +109,7 @@ class N3Lexer {
109
109
  _tokenizeToEnd(callback, inputFinished) {
110
110
  // Continue parsing as far as possible; the loop will return eventually
111
111
  let input = this._input;
112
- const outputComments = this._comments;
112
+ let currentLineLength = input.length;
113
113
 
114
114
  while (true) {
115
115
  // Count and skip whitespace lines
@@ -117,14 +117,10 @@ class N3Lexer {
117
117
 
118
118
  while (whiteSpaceMatch = this._newline.exec(input)) {
119
119
  // Try to find a comment
120
- if (outputComments && (comment = this._comment.exec(whiteSpaceMatch[0]))) callback(null, {
121
- line: this._line,
122
- type: 'comment',
123
- value: comment[1],
124
- prefix: ''
125
- }); // Advance the input
120
+ if (this._comments && (comment = this._comment.exec(whiteSpaceMatch[0]))) emitToken('comment', comment[1], '', this._line, whiteSpaceMatch[0].length); // Advance the input
126
121
 
127
122
  input = input.substr(whiteSpaceMatch[0].length, input.length);
123
+ currentLineLength = input.length;
128
124
  this._line++;
129
125
  } // Skip whitespace on current line
130
126
 
@@ -135,18 +131,9 @@ class N3Lexer {
135
131
  // If the input is finished, emit EOF
136
132
  if (inputFinished) {
137
133
  // Try to find a final comment
138
- if (outputComments && (comment = this._comment.exec(input))) callback(null, {
139
- line: this._line,
140
- type: 'comment',
141
- value: comment[1],
142
- prefix: ''
143
- });
144
- callback(input = null, {
145
- line: this._line,
146
- type: 'eof',
147
- value: '',
148
- prefix: ''
149
- });
134
+ if (this._comments && (comment = this._comment.exec(input))) emitToken('comment', comment[1], '', this._line, input.length);
135
+ input = null;
136
+ emitToken('eof', '', '', this._line, 0);
150
137
  }
151
138
 
152
139
  return this._input = input;
@@ -376,17 +363,28 @@ class N3Lexer {
376
363
  } // Emit the parsed token
377
364
 
378
365
 
379
- const token = {
380
- line: line,
381
- type: type,
382
- value: value,
383
- prefix: prefix
384
- };
385
- callback(null, token);
366
+ const length = matchLength || match[0].length;
367
+ const token = emitToken(type, value, prefix, line, length);
386
368
  this.previousToken = token;
387
369
  this._previousMarker = type; // Advance to next part to tokenize
388
370
 
389
- input = input.substr(matchLength || match[0].length, input.length);
371
+ input = input.substr(length, input.length);
372
+ } // Emits the token through the callback
373
+
374
+
375
+ function emitToken(type, value, prefix, line, length) {
376
+ const start = input ? currentLineLength - input.length : currentLineLength;
377
+ const end = start + length;
378
+ const token = {
379
+ type,
380
+ value,
381
+ prefix,
382
+ line,
383
+ start,
384
+ end
385
+ };
386
+ callback(null, token);
387
+ return token;
390
388
  } // Signals the syntax error through the callback
391
389
 
392
390
 
package/lib/index.js CHANGED
@@ -94,6 +94,7 @@ Object.defineProperty(exports, "Writer", {
94
94
  return _N3Writer.default;
95
95
  }
96
96
  });
97
+ exports.default = void 0;
97
98
  Object.defineProperty(exports, "termFromId", {
98
99
  enumerable: true,
99
100
  get: function () {
@@ -129,4 +130,28 @@ function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "functio
129
130
 
130
131
  function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
131
132
 
132
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
133
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
134
+
135
+ // Named exports
136
+ // Export all named exports as a default object for backward compatibility
137
+ var _default = {
138
+ Lexer: _N3Lexer.default,
139
+ Parser: _N3Parser.default,
140
+ Writer: _N3Writer.default,
141
+ Store: _N3Store.default,
142
+ StreamParser: _N3StreamParser.default,
143
+ StreamWriter: _N3StreamWriter.default,
144
+ Util,
145
+ DataFactory: _N3DataFactory.default,
146
+ Term: _N3DataFactory.Term,
147
+ NamedNode: _N3DataFactory.NamedNode,
148
+ Literal: _N3DataFactory.Literal,
149
+ BlankNode: _N3DataFactory.BlankNode,
150
+ Variable: _N3DataFactory.Variable,
151
+ DefaultGraph: _N3DataFactory.DefaultGraph,
152
+ Quad: _N3DataFactory.Quad,
153
+ Triple: _N3DataFactory.Triple,
154
+ termFromId: _N3DataFactory.termFromId,
155
+ termToId: _N3DataFactory.termToId
156
+ };
157
+ exports.default = _default;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "n3",
3
- "version": "1.12.2",
3
+ "version": "1.15.0",
4
4
  "description": "Lightning fast, asynchronous, streaming Turtle / N3 / RDF library.",
5
5
  "author": "Ruben Verborgh <ruben.verborgh@gmail.com>",
6
6
  "keywords": [
@@ -39,7 +39,7 @@
39
39
  "colors": "^1.1.2",
40
40
  "docco": "^0.8.0",
41
41
  "eslint": "^5.14.1",
42
- "mocha": "^7.1.2",
42
+ "mocha": "^8.0.0",
43
43
  "nyc": "^14.1.1",
44
44
  "pre-commit": "^1.2.2",
45
45
  "rdf-test-suite": "^1.2.0",
@@ -35,12 +35,6 @@ export class Term {
35
35
  return this.id;
36
36
  }
37
37
 
38
- // ### Implement hashCode for Immutable.js, since we implement `equals`
39
- // https://immutable-js.com/docs/v4.0.0/ValueObject/#hashCode()
40
- get hashCode() {
41
- return 0;
42
- }
43
-
44
38
  // ### Returns whether this object represents the same term as the other
45
39
  equals(other) {
46
40
  // If both terms were created by this library,
@@ -52,6 +46,12 @@ export class Term {
52
46
  this.value === other.value;
53
47
  }
54
48
 
49
+ // ### Implement hashCode for Immutable.js, since we implement `equals`
50
+ // https://immutable-js.com/docs/v4.0.0/ValueObject/#hashCode()
51
+ hashCode() {
52
+ return 0;
53
+ }
54
+
55
55
  // ### Returns a plain object representation of this term
56
56
  toJSON() {
57
57
  return {
package/src/N3Lexer.js CHANGED
@@ -78,16 +78,17 @@ export default class N3Lexer {
78
78
  _tokenizeToEnd(callback, inputFinished) {
79
79
  // Continue parsing as far as possible; the loop will return eventually
80
80
  let input = this._input;
81
- const outputComments = this._comments;
81
+ let currentLineLength = input.length;
82
82
  while (true) {
83
83
  // Count and skip whitespace lines
84
84
  let whiteSpaceMatch, comment;
85
85
  while (whiteSpaceMatch = this._newline.exec(input)) {
86
86
  // Try to find a comment
87
- if (outputComments && (comment = this._comment.exec(whiteSpaceMatch[0])))
88
- callback(null, { line: this._line, type: 'comment', value: comment[1], prefix: '' });
87
+ if (this._comments && (comment = this._comment.exec(whiteSpaceMatch[0])))
88
+ emitToken('comment', comment[1], '', this._line, whiteSpaceMatch[0].length);
89
89
  // Advance the input
90
90
  input = input.substr(whiteSpaceMatch[0].length, input.length);
91
+ currentLineLength = input.length;
91
92
  this._line++;
92
93
  }
93
94
  // Skip whitespace on current line
@@ -99,9 +100,10 @@ export default class N3Lexer {
99
100
  // If the input is finished, emit EOF
100
101
  if (inputFinished) {
101
102
  // Try to find a final comment
102
- if (outputComments && (comment = this._comment.exec(input)))
103
- callback(null, { line: this._line, type: 'comment', value: comment[1], prefix: '' });
104
- callback(input = null, { line: this._line, type: 'eof', value: '', prefix: '' });
103
+ if (this._comments && (comment = this._comment.exec(input)))
104
+ emitToken('comment', comment[1], '', this._line, input.length);
105
+ input = null;
106
+ emitToken('eof', '', '', this._line, 0);
105
107
  }
106
108
  return this._input = input;
107
109
  }
@@ -345,14 +347,23 @@ export default class N3Lexer {
345
347
  }
346
348
 
347
349
  // Emit the parsed token
348
- const token = { line: line, type: type, value: value, prefix: prefix };
349
- callback(null, token);
350
+ const length = matchLength || match[0].length;
351
+ const token = emitToken(type, value, prefix, line, length);
350
352
  this.previousToken = token;
351
353
  this._previousMarker = type;
354
+
352
355
  // Advance to next part to tokenize
353
- input = input.substr(matchLength || match[0].length, input.length);
356
+ input = input.substr(length, input.length);
354
357
  }
355
358
 
359
+ // Emits the token through the callback
360
+ function emitToken(type, value, prefix, line, length) {
361
+ const start = input ? currentLineLength - input.length : currentLineLength;
362
+ const end = start + length;
363
+ const token = { type, value, prefix, line, start, end };
364
+ callback(null, token);
365
+ return token;
366
+ }
356
367
  // Signals the syntax error through the callback
357
368
  function reportSyntaxError(self) { callback(self._syntaxError(/^\S*/.exec(input)[0])); }
358
369
  }
package/src/index.js CHANGED
@@ -22,6 +22,7 @@ import {
22
22
  termToId,
23
23
  } from './N3DataFactory';
24
24
 
25
+ // Named exports
25
26
  export {
26
27
  Lexer,
27
28
  Parser,
@@ -45,3 +46,28 @@ export {
45
46
  termFromId,
46
47
  termToId,
47
48
  };
49
+
50
+ // Export all named exports as a default object for backward compatibility
51
+ export default {
52
+ Lexer,
53
+ Parser,
54
+ Writer,
55
+ Store,
56
+ StreamParser,
57
+ StreamWriter,
58
+ Util,
59
+
60
+ DataFactory,
61
+
62
+ Term,
63
+ NamedNode,
64
+ Literal,
65
+ BlankNode,
66
+ Variable,
67
+ DefaultGraph,
68
+ Quad,
69
+ Triple,
70
+
71
+ termFromId,
72
+ termToId,
73
+ };