n3 2.7.7 → 2.7.9

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/N3Lexer.js CHANGED
@@ -60,7 +60,6 @@ const lineModeRegExps = {
60
60
  _unescapedIri: true,
61
61
  _simpleQuotedString: true,
62
62
  _langcode: true,
63
- _dircode: true,
64
63
  _blank: true,
65
64
  _newline: true,
66
65
  _comment: true,
@@ -79,7 +78,6 @@ class N3Lexer {
79
78
  this._simpleQuotedString = /^"([^"\\\r\n]*)"(?=[^"])/; // string without escape sequences
80
79
  this._simpleApostropheString = /^'([^'\\\r\n]*)'(?=[^'])/;
81
80
  this._langcode = /^@([a-z]+(?:-[a-z0-9]+)*)(?=[^a-z0-9])/i;
82
- this._dircode = /^--(?:(ltr)|(rtl))/;
83
81
  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<])/;
84
82
  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#()\[\]\{\}"'<>]))/;
85
83
  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#()\[\]\{\}"'<>])/;
@@ -287,7 +285,9 @@ class N3Lexer {
287
285
  case '-':
288
286
  if (input[1] === '-') {
289
287
  // Try to find a direction code
290
- if (this._previousMarker === 'langcode' && (match = this._dircode.exec(input))) type = 'dircode', matchLength = 2, value = match[1] || match[2], matchLength = value.length + 2;
288
+ if (this._previousMarker === 'langcode') {
289
+ if (input.startsWith('--ltr')) type = 'dircode', value = 'ltr', matchLength = 5;else if (input.startsWith('--rtl')) type = 'dircode', value = 'rtl', matchLength = 5;
290
+ }
291
291
  break;
292
292
  }
293
293
 
@@ -498,9 +498,11 @@ class N3Lexer {
498
498
  _parseLiteral(input) {
499
499
  // Ensure we have enough lookahead to identify triple-quoted strings
500
500
  if (input.length >= 3) {
501
- // Identify the opening quote(s)
502
- const opening = input.match(/^(?:"""|"|'''|'|)/)[0];
503
- const openingLength = opening.length;
501
+ // The caller has already identified a single or double quote.
502
+ const quote = input[0];
503
+ const openingLength = input[1] === quote && input[2] === quote ? 3 : 1;
504
+ let opening = quote;
505
+ if (openingLength === 3) opening = quote === '"' ? '"""' : "'''";
504
506
 
505
507
  // Find the next candidate closing quotes
506
508
  let closingPos = Math.max(this._literalClosingPos, openingLength);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "n3",
3
- "version": "2.7.7",
3
+ "version": "2.7.9",
4
4
  "description": "Lightning fast, asynchronous, streaming Turtle / N3 / RDF library.",
5
5
  "author": "Ruben Verborgh <ruben.verborgh@gmail.com>",
6
6
  "keywords": [
package/src/N3Lexer.js CHANGED
@@ -29,7 +29,6 @@ const lineModeRegExps = {
29
29
  _unescapedIri: true,
30
30
  _simpleQuotedString: true,
31
31
  _langcode: true,
32
- _dircode: true,
33
32
  _blank: true,
34
33
  _newline: true,
35
34
  _comment: true,
@@ -48,7 +47,6 @@ export default class N3Lexer {
48
47
  this._simpleQuotedString = /^"([^"\\\r\n]*)"(?=[^"])/; // string without escape sequences
49
48
  this._simpleApostropheString = /^'([^'\\\r\n]*)'(?=[^'])/;
50
49
  this._langcode = /^@([a-z]+(?:-[a-z0-9]+)*)(?=[^a-z0-9])/i;
51
- this._dircode = /^--(?:(ltr)|(rtl))/;
52
50
  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<])/;
53
51
  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#()\[\]\{\}"'<>]))/;
54
52
  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#()\[\]\{\}"'<>])/;
@@ -275,8 +273,12 @@ export default class N3Lexer {
275
273
  case '-':
276
274
  if (input[1] === '-') {
277
275
  // Try to find a direction code
278
- if (this._previousMarker === 'langcode' && (match = this._dircode.exec(input)))
279
- type = 'dircode', matchLength = 2, value = (match[1] || match[2]), matchLength = value.length + 2;
276
+ if (this._previousMarker === 'langcode') {
277
+ if (input.startsWith('--ltr'))
278
+ type = 'dircode', value = 'ltr', matchLength = 5;
279
+ else if (input.startsWith('--rtl'))
280
+ type = 'dircode', value = 'rtl', matchLength = 5;
281
+ }
280
282
  break;
281
283
  }
282
284
 
@@ -522,9 +524,12 @@ export default class N3Lexer {
522
524
  _parseLiteral(input) {
523
525
  // Ensure we have enough lookahead to identify triple-quoted strings
524
526
  if (input.length >= 3) {
525
- // Identify the opening quote(s)
526
- const opening = input.match(/^(?:"""|"|'''|'|)/)[0];
527
- const openingLength = opening.length;
527
+ // The caller has already identified a single or double quote.
528
+ const quote = input[0];
529
+ const openingLength = input[1] === quote && input[2] === quote ? 3 : 1;
530
+ let opening = quote;
531
+ if (openingLength === 3)
532
+ opening = quote === '"' ? '"""' : "'''";
528
533
 
529
534
  // Find the next candidate closing quotes
530
535
  let closingPos = Math.max(this._literalClosingPos, openingLength);