rdflib 2.2.34 → 2.2.35-2bb9ed0b

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.
Files changed (100) hide show
  1. package/dist/515.rdflib.min.js +3 -0
  2. package/dist/515.rdflib.min.js.map +1 -0
  3. package/dist/789.rdflib.min.js +1 -0
  4. package/dist/rdflib.min.js +1 -1
  5. package/dist/rdflib.min.js.LICENSE.txt +0 -2
  6. package/dist/rdflib.min.js.map +1 -1
  7. package/esm/blank-node.js +57 -85
  8. package/esm/class-order.js +1 -1
  9. package/esm/collection.js +70 -106
  10. package/esm/default-graph.js +13 -33
  11. package/esm/empty.js +8 -26
  12. package/esm/factories/canonical-data-factory.js +33 -30
  13. package/esm/factories/extended-term-factory.js +18 -14
  14. package/esm/factories/factory-types.js +1 -1
  15. package/esm/factories/rdflib-data-factory.js +9 -11
  16. package/esm/fetcher.js +1364 -1668
  17. package/esm/formula.js +631 -739
  18. package/esm/index.js +31 -51
  19. package/esm/jsonldparser.js +19 -26
  20. package/esm/jsonparser.js +1 -1
  21. package/esm/lists.js +41 -86
  22. package/esm/literal.js +120 -157
  23. package/esm/log.js +7 -7
  24. package/esm/n3parser.js +1008 -1090
  25. package/esm/named-node.js +69 -99
  26. package/esm/namespace.js +2 -4
  27. package/esm/node-internal.js +73 -97
  28. package/esm/node.js +1 -2
  29. package/esm/parse.js +3 -3
  30. package/esm/patch-parser.js +1 -2
  31. package/esm/query.js +15 -30
  32. package/esm/rdfaparser.js +775 -846
  33. package/esm/rdfxmlparser.js +348 -365
  34. package/esm/serialize.js +2 -3
  35. package/esm/serializer.js +834 -889
  36. package/esm/sparql-to-query.js +0 -2
  37. package/esm/statement.js +52 -72
  38. package/esm/store.js +852 -963
  39. package/esm/types.js +26 -21
  40. package/esm/update-manager.js +963 -1104
  41. package/esm/updates-via.js +104 -134
  42. package/esm/uri.js +3 -3
  43. package/esm/utils/default-graph-uri.js +2 -2
  44. package/esm/utils/terms.js +4 -5
  45. package/esm/utils-js.js +5 -6
  46. package/esm/utils.js +7 -6
  47. package/esm/variable.js +32 -58
  48. package/esm/xsd.js +2 -2
  49. package/lib/blank-node.js +56 -83
  50. package/lib/class-order.js +2 -3
  51. package/lib/collection.js +69 -104
  52. package/lib/default-graph.js +13 -32
  53. package/lib/empty.js +8 -25
  54. package/lib/factories/canonical-data-factory.js +36 -34
  55. package/lib/factories/extended-term-factory.js +19 -16
  56. package/lib/factories/factory-types.js +2 -3
  57. package/lib/factories/rdflib-data-factory.js +10 -13
  58. package/lib/fetcher.js +1394 -1693
  59. package/lib/formula.js +631 -738
  60. package/lib/index.js +66 -89
  61. package/lib/jsonldparser.js +21 -32
  62. package/lib/jsonparser.js +3 -4
  63. package/lib/lists.js +47 -87
  64. package/lib/literal.js +120 -156
  65. package/lib/log.js +8 -9
  66. package/lib/n3parser.js +1011 -1096
  67. package/lib/named-node.js +69 -98
  68. package/lib/namespace.js +2 -4
  69. package/lib/node-internal.js +72 -95
  70. package/lib/node.js +2 -4
  71. package/lib/parse.js +5 -6
  72. package/lib/patch-parser.js +1 -2
  73. package/lib/query.js +19 -32
  74. package/lib/rdfaparser.js +777 -849
  75. package/lib/rdfxmlparser.js +350 -366
  76. package/lib/serialize.js +2 -3
  77. package/lib/serializer.js +838 -892
  78. package/lib/sparql-to-query.js +0 -2
  79. package/lib/statement.js +54 -74
  80. package/lib/store.js +873 -978
  81. package/lib/types.js +22 -43
  82. package/lib/update-manager.js +972 -1111
  83. package/lib/updates-via.js +105 -134
  84. package/lib/uri.js +3 -3
  85. package/lib/utils/default-graph-uri.js +2 -4
  86. package/lib/utils/terms.js +4 -6
  87. package/lib/utils-js.js +11 -13
  88. package/lib/utils.js +6 -7
  89. package/lib/variable.js +34 -60
  90. package/lib/xsd-internal.js +2 -3
  91. package/lib/xsd.js +3 -4
  92. package/package.json +31 -31
  93. package/src/n3parser.js +1 -1
  94. package/src/rdfxmlparser.js +2 -1
  95. package/src/serializer.js +1 -1
  96. package/.babelrc +0 -20
  97. package/dist/670.rdflib.min.js +0 -1
  98. package/dist/730.rdflib.min.js +0 -3
  99. package/dist/730.rdflib.min.js.map +0 -1
  100. /package/dist/{730.rdflib.min.js.LICENSE.txt → 515.rdflib.min.js.LICENSE.txt} +0 -0
package/esm/n3parser.js CHANGED
@@ -1,6 +1,3 @@
1
- import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
2
- import _createClass from "@babel/runtime/helpers/createClass";
3
- import _typeof from "@babel/runtime/helpers/typeof";
4
1
  /**
5
2
  *
6
3
  * UTF-8 data encode / decode
@@ -16,7 +13,7 @@ function hexify(str) {
16
13
  }
17
14
  var Utf8 = {
18
15
  // public method for url encoding
19
- encode: function encode(string) {
16
+ encode: function (string) {
20
17
  string = string.replace(/\r\n/g, "\n");
21
18
  var utftext = "";
22
19
  for (var n = 0; n < string.length; n++) {
@@ -35,7 +32,7 @@ var Utf8 = {
35
32
  return utftext;
36
33
  },
37
34
  // public method for url decoding
38
- decode: function decode(utftext) {
35
+ decode: function (utftext) {
39
36
  var string = "";
40
37
  var i = 0;
41
38
  while (i < utftext.length) {
@@ -62,27 +59,26 @@ var Logic_NS = "http://www.w3.org/2000/10/swap/log#";
62
59
 
63
60
  // pyjs seems to reference runtime library which I didn't find
64
61
 
65
- var pyjslib_Tuple = function pyjslib_Tuple(theList) {
62
+ var pyjslib_Tuple = function (theList) {
66
63
  return theList;
67
64
  };
68
- var pyjslib_List = function pyjslib_List(theList) {
65
+ var pyjslib_List = function (theList) {
69
66
  return theList;
70
67
  };
71
- var pyjslib_Dict = function pyjslib_Dict(listOfPairs) {
68
+ var pyjslib_Dict = function (listOfPairs) {
72
69
  if (listOfPairs.length > 0) throw "missing.js: oops nnonempty dict not imp";
73
70
  return [];
74
71
  };
75
- var pyjslib_len = function pyjslib_len(s) {
72
+ var pyjslib_len = function (s) {
76
73
  return s.length;
77
74
  };
78
- var pyjslib_slice = function pyjslib_slice(str, i, j) {
79
- if (typeof str.slice == 'undefined') throw '@@ mising.js: No .slice function for ' + str + ' of type ' + _typeof(str);
75
+ var pyjslib_slice = function (str, i, j) {
76
+ if (typeof str.slice == 'undefined') throw '@@ mising.js: No .slice function for ' + str + ' of type ' + typeof str;
80
77
  if (typeof j == 'undefined' || j == null) return str.slice(i);
81
78
  return str.slice(i, j); // @ exactly the same spec?
82
79
  };
83
-
84
80
  var StopIteration = Error('dummy error stop iteration');
85
- var pyjslib_Iterator = function pyjslib_Iterator(theList) {
81
+ var pyjslib_Iterator = function (theList) {
86
82
  this.last = 0;
87
83
  this.li = theList;
88
84
  this.next = function () {
@@ -91,18 +87,18 @@ var pyjslib_Iterator = function pyjslib_Iterator(theList) {
91
87
  };
92
88
  return this;
93
89
  };
94
- var ord = function ord(str) {
90
+ var ord = function (str) {
95
91
  return str.charCodeAt(0);
96
92
  };
97
- var string_find = function string_find(str, s) {
93
+ var string_find = function (str, s) {
98
94
  return str.indexOf(s);
99
95
  };
100
- var assertFudge = function assertFudge(condition, desc) {
96
+ var assertFudge = function (condition, desc) {
101
97
  if (condition) return;
102
98
  if (desc) throw "python Assertion failed: " + desc;
103
99
  throw "(python) Assertion failed.";
104
100
  };
105
- var stringFromCharCode = function stringFromCharCode(uesc) {
101
+ var stringFromCharCode = function (uesc) {
106
102
  return String.fromCharCode(uesc);
107
103
  };
108
104
  String.prototype.encode = function (encoding) {
@@ -114,14 +110,13 @@ String.prototype.decode = function (encoding) {
114
110
  //return Utf8.decode(this);
115
111
  return this;
116
112
  };
117
- var uripath_join = function uripath_join(base, given) {
113
+ var uripath_join = function (base, given) {
118
114
  return Uri.join(given, base); // sad but true
119
115
  };
120
-
121
116
  var becauseSubexpression = null; // No reason needed
122
117
  var diag_tracking = 0;
123
118
  var diag_chatty_flag = 0;
124
- var diag_progress = function diag_progress(str) {/*$rdf.log.debug(str);*/};
119
+ var diag_progress = function (str) {/*$rdf.log.debug(str);*/};
125
120
 
126
121
  // why_BecauseOfData = function(doc, reason) { return doc };
127
122
 
@@ -186,7 +181,7 @@ var eol = new RegExp("^[ \\t]*(#[^\\n]*)?\\r?\\n", 'g');
186
181
  var eof = new RegExp("^[ \\t]*(#[^\\n]*)?$", 'g');
187
182
  var ws = new RegExp("^[ \\t]*", 'g');
188
183
  var signed_integer = new RegExp("^[-+]?[0-9]+", 'g');
189
- var number_syntax = new RegExp("^([-+]?[0-9]+)(\\.[0-9]+)?(e[-+]?[0-9]+)?", 'g');
184
+ var number_syntax = new RegExp("^([-+]?[0-9]+)(\\.[0-9]+)?([eE][-+]?[0-9]+)?", 'g');
190
185
  var datetime_syntax = new RegExp('^[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9](T[0-9][0-9]:[0-9][0-9](:[0-9][0-9](\\.[0-9]*)?)?)?Z?');
191
186
  var digitstring = new RegExp("^[0-9]+", 'g');
192
187
  var interesting = new RegExp("[\\\\\\r\\n\\\"]", 'g');
@@ -195,9 +190,8 @@ function createSinkParser(store, openFormula, thisDoc, baseURI, genPrefix, metaU
195
190
  return new SinkParser(store, openFormula, thisDoc, baseURI, genPrefix, metaURI, flags, why);
196
191
  }
197
192
  export default createSinkParser;
198
- export var SinkParser = /*#__PURE__*/function () {
199
- function SinkParser(store, openFormula, thisDoc, baseURI, genPrefix, metaURI, flags, why) {
200
- _classCallCheck(this, SinkParser);
193
+ export class SinkParser {
194
+ constructor(store, openFormula, thisDoc, baseURI, genPrefix, metaURI, flags, why) {
201
195
  if (typeof openFormula == 'undefined') openFormula = null;
202
196
  if (typeof thisDoc == 'undefined') thisDoc = "";
203
197
  if (typeof baseURI == 'undefined') baseURI = null;
@@ -266,1224 +260,1148 @@ export var SinkParser = /*#__PURE__*/function () {
266
260
  this._context = this._formula;
267
261
  this._parentContext = null;
268
262
  }
269
- _createClass(SinkParser, [{
270
- key: "here",
271
- value: function here(i) {
272
- return this._genPrefix + "_L" + this.lines + "C" + (i - this.startOfLine + 1);
273
- }
274
- }, {
275
- key: "formula",
276
- value: function formula() {
277
- return this._formula;
278
- }
279
- }, {
280
- key: "loadStream",
281
- value: function loadStream(stream) {
282
- return this.loadBuf(stream.read());
283
- }
284
- }, {
285
- key: "loadBuf",
286
- value: function loadBuf(buf) {
287
- /*
288
- Parses a buffer and returns its top level formula*/
263
+ here(i) {
264
+ return this._genPrefix + "_L" + this.lines + "C" + (i - this.startOfLine + 1);
265
+ }
266
+ formula() {
267
+ return this._formula;
268
+ }
269
+ loadStream(stream) {
270
+ return this.loadBuf(stream.read());
271
+ }
272
+ loadBuf(buf) {
273
+ /*
274
+ Parses a buffer and returns its top level formula*/
289
275
 
290
- this.startDoc();
291
- this.feed(buf);
292
- return this.endDoc();
293
- }
294
- }, {
295
- key: "feed",
296
- value: function feed(octets) {
297
- /*
298
- Feed an octet stream tothe parser
299
- if BadSyntax is raised, the string
300
- passed in the exception object is the
301
- remainder after any statements have been parsed.
302
- So if there is more data to feed to the
303
- parser, it should be straightforward to recover.*/
276
+ this.startDoc();
277
+ this.feed(buf);
278
+ return this.endDoc();
279
+ }
280
+ feed(octets) {
281
+ /*
282
+ Feed an octet stream tothe parser
283
+ if BadSyntax is raised, the string
284
+ passed in the exception object is the
285
+ remainder after any statements have been parsed.
286
+ So if there is more data to feed to the
287
+ parser, it should be straightforward to recover.*/
304
288
 
305
- var str = octets.decode("utf-8");
306
- var i = 0;
307
- while (i >= 0) {
308
- var j = this.skipSpace(str, i);
309
- if (j < 0) {
310
- return;
311
- }
312
- var i = this.directiveOrStatement(str, j);
313
- if (i < 0) {
314
- throw BadSyntax(this._thisDoc, this.lines, str, j, "expected directive or statement");
315
- }
289
+ var str = octets.decode("utf-8");
290
+ var i = 0;
291
+ while (i >= 0) {
292
+ var j = this.skipSpace(str, i);
293
+ if (j < 0) {
294
+ return;
316
295
  }
317
- }
318
- }, {
319
- key: "directiveOrStatement",
320
- value: function directiveOrStatement(str, h) {
321
- var i = this.skipSpace(str, h);
296
+ var i = this.directiveOrStatement(str, j);
322
297
  if (i < 0) {
323
- return i;
324
- }
325
- var j = this.directive(str, i);
326
- if (j >= 0) {
327
- return this.checkDot(str, j);
328
- }
329
- var j = this.statement(str, i);
330
- if (j >= 0) {
331
- return this.checkDot(str, j);
298
+ throw BadSyntax(this._thisDoc, this.lines, str, j, "expected directive or statement");
332
299
  }
333
- return j;
334
300
  }
335
- }, {
336
- key: "tok",
337
- value: function tok(_tok, str, i) {
338
- /*
339
- Check for keyword. Space must have been stripped on entry and
340
- we must not be at end of file.*/
341
- var whitespace = "\t\n\v\f\r ";
342
- if (str.slice(i, i + 1) == "@") {
343
- var i = i + 1;
344
- } else {
345
- if (ArrayIndexOf(this.keywords, _tok) < 0) {
346
- return -1;
347
- }
348
- }
349
- var k = i + pyjslib_len(_tok);
350
- if (str.slice(i, k) == _tok && _notQNameChars.indexOf(str.charAt(k)) >= 0) {
351
- return k;
352
- } else {
301
+ }
302
+ directiveOrStatement(str, h) {
303
+ var i = this.skipSpace(str, h);
304
+ if (i < 0) {
305
+ return i;
306
+ }
307
+ var j = this.directive(str, i);
308
+ if (j >= 0) {
309
+ return this.checkDot(str, j);
310
+ }
311
+ var j = this.statement(str, i);
312
+ if (j >= 0) {
313
+ return this.checkDot(str, j);
314
+ }
315
+ return j;
316
+ }
317
+ tok(tok, str, i) {
318
+ /*
319
+ Check for keyword. Space must have been stripped on entry and
320
+ we must not be at end of file.*/
321
+ var whitespace = "\t\n\v\f\r ";
322
+ if (str.slice(i, i + 1) == "@") {
323
+ var i = i + 1;
324
+ } else {
325
+ if (ArrayIndexOf(this.keywords, tok) < 0) {
353
326
  return -1;
354
327
  }
355
328
  }
356
- }, {
357
- key: "directive",
358
- value: function directive(str, i) {
359
- var j = this.skipSpace(str, i);
360
- if (j < 0) {
361
- return j;
362
- }
363
- var res = new pyjslib_List([]);
364
- var j = this.tok("bind", str, i);
365
- if (j > 0) {
366
- throw BadSyntax(this._thisDoc, this.lines, str, i, "keyword bind is obsolete: use @prefix");
329
+ var k = i + pyjslib_len(tok);
330
+ if (str.slice(i, k) == tok && _notQNameChars.indexOf(str.charAt(k)) >= 0) {
331
+ return k;
332
+ } else {
333
+ return -1;
334
+ }
335
+ }
336
+ directive(str, i) {
337
+ var j = this.skipSpace(str, i);
338
+ if (j < 0) {
339
+ return j;
340
+ }
341
+ var res = new pyjslib_List([]);
342
+ var j = this.tok("bind", str, i);
343
+ if (j > 0) {
344
+ throw BadSyntax(this._thisDoc, this.lines, str, i, "keyword bind is obsolete: use @prefix");
345
+ }
346
+ var j = this.tok("keywords", str, i);
347
+ if (j > 0) {
348
+ var i = this.commaSeparatedList(str, j, res, false);
349
+ if (i < 0) {
350
+ throw BadSyntax(this._thisDoc, this.lines, str, i, "'@keywords' needs comma separated list of words");
367
351
  }
368
- var j = this.tok("keywords", str, i);
369
- if (j > 0) {
370
- var i = this.commaSeparatedList(str, j, res, false);
371
- if (i < 0) {
372
- throw BadSyntax(this._thisDoc, this.lines, str, i, "'@keywords' needs comma separated list of words");
373
- }
374
- this.setKeywords(pyjslib_slice(res, null, null));
375
- if (diag_chatty_flag > 80) {
376
- diag_progress("Keywords ", this.keywords);
377
- }
378
- return i;
352
+ this.setKeywords(pyjslib_slice(res, null, null));
353
+ if (diag_chatty_flag > 80) {
354
+ diag_progress("Keywords ", this.keywords);
379
355
  }
380
- var j = this.tok("forAll", str, i);
381
- if (j > 0) {
382
- var i = this.commaSeparatedList(str, j, res, true);
383
- if (i < 0) {
384
- throw BadSyntax(this._thisDoc, this.lines, str, i, "Bad variable list after @forAll");
385
- }
386
- var __x = new pyjslib_Iterator(res);
387
- try {
388
- while (true) {
389
- var x = __x.next();
390
- if (ArrayIndexOf(this._variables, x) < 0 || ArrayIndexOf(this._parentVariables, x) >= 0) {
391
- this._variables[x] = this._context.newUniversal(x);
392
- }
393
- }
394
- } catch (e) {
395
- if (e != StopIteration) {
396
- throw e;
356
+ return i;
357
+ }
358
+ var j = this.tok("forAll", str, i);
359
+ if (j > 0) {
360
+ var i = this.commaSeparatedList(str, j, res, true);
361
+ if (i < 0) {
362
+ throw BadSyntax(this._thisDoc, this.lines, str, i, "Bad variable list after @forAll");
363
+ }
364
+ var __x = new pyjslib_Iterator(res);
365
+ try {
366
+ while (true) {
367
+ var x = __x.next();
368
+ if (ArrayIndexOf(this._variables, x) < 0 || ArrayIndexOf(this._parentVariables, x) >= 0) {
369
+ this._variables[x] = this._context.newUniversal(x);
397
370
  }
398
371
  }
399
- return i;
400
- }
401
- var j = this.tok("forSome", str, i);
402
- if (j > 0) {
403
- var i = this.commaSeparatedList(str, j, res, this.uri_ref2);
404
- if (i < 0) {
405
- throw BadSyntax(this._thisDoc, this.lines, str, i, "Bad variable list after @forSome");
406
- }
407
- var __x = new pyjslib_Iterator(res);
408
- try {
409
- while (true) {
410
- var x = __x.next();
411
- this._context.declareExistential(x);
412
- }
413
- } catch (e) {
414
- if (e != StopIteration) {
415
- throw e;
416
- }
372
+ } catch (e) {
373
+ if (e != StopIteration) {
374
+ throw e;
417
375
  }
418
- return i;
419
376
  }
420
- var j = this.tok("prefix", str, i);
421
- if (j >= 0) {
422
- var t = new pyjslib_List([]);
423
- var i = this.qname(str, j, t);
424
- if (i < 0) {
425
- throw BadSyntax(this._thisDoc, this.lines, str, j, "expected qname after @prefix");
426
- }
427
- var j = this.uri_ref2(str, i, t);
428
- if (j < 0) {
429
- throw BadSyntax(this._thisDoc, this.lines, str, i, "expected <uriref> after @prefix _qname_");
430
- }
431
- var ns = t[1].uri;
432
- if (this._baseURI) {
433
- var ns = uripath_join(this._baseURI, ns);
434
- } else {
435
- assertFudge(ns.indexOf(":") >= 0, "With no base URI, cannot handle relative URI for NS");
436
- }
437
- assertFudge(ns.indexOf(":") >= 0);
438
- this._bindings[t[0][0]] = ns;
439
- this.bind(t[0][0], hexify(ns));
440
- return j;
377
+ return i;
378
+ }
379
+ var j = this.tok("forSome", str, i);
380
+ if (j > 0) {
381
+ var i = this.commaSeparatedList(str, j, res, this.uri_ref2);
382
+ if (i < 0) {
383
+ throw BadSyntax(this._thisDoc, this.lines, str, i, "Bad variable list after @forSome");
441
384
  }
442
- var j = this.tok("base", str, i);
443
- if (j >= 0) {
444
- var t = new pyjslib_List([]);
445
- var i = this.uri_ref2(str, j, t);
446
- if (i < 0) {
447
- throw BadSyntax(this._thisDoc, this.lines, str, j, "expected <uri> after @base ");
385
+ var __x = new pyjslib_Iterator(res);
386
+ try {
387
+ while (true) {
388
+ var x = __x.next();
389
+ this._context.declareExistential(x);
448
390
  }
449
- var ns = t[0].uri;
450
- if (this._baseURI) {
451
- var ns = uripath_join(this._baseURI, ns);
452
- } else {
453
- throw BadSyntax(this._thisDoc, this.lines, str, j, "With no previous base URI, cannot use relative URI in @base <" + ns + ">");
391
+ } catch (e) {
392
+ if (e != StopIteration) {
393
+ throw e;
454
394
  }
455
- assertFudge(ns.indexOf(":") >= 0);
456
- this._baseURI = ns;
457
- return i;
458
- }
459
- return -1;
460
- }
461
- }, {
462
- key: "bind",
463
- value: function bind(qn, uri) {
464
- if (qn == "") {} else {
465
- this._store.setPrefixForURI(qn, uri);
466
395
  }
396
+ return i;
467
397
  }
468
- }, {
469
- key: "setKeywords",
470
- value: function setKeywords(k) {
471
- /*
472
- Takes a list of strings*/
473
-
474
- if (k == null) {
475
- this.keywordsSet = 0;
476
- } else {
477
- this.keywords = k;
478
- this.keywordsSet = 1;
479
- }
480
- }
481
- }, {
482
- key: "startDoc",
483
- value: function startDoc() {}
484
- }, {
485
- key: "endDoc",
486
- value: /* Signal end of document and stop parsing. returns formula */
487
- function endDoc() {
488
- if (this.hasNil && this._store.rdfFactory.supports["COLLECTIONS"]) {
489
- convertFirstRestNil(this._store, this.source);
490
- }
491
- return this._formula;
492
- }
493
- }, {
494
- key: "makeStatement",
495
- value: function makeStatement(quad) {
496
- quad[0].add(quad[2], quad[1], quad[3], this.source);
497
- if (quad[2].uri && quad[2].uri === RDF_nil_URI || quad[3].uri && quad[3].uri === RDF_nil_URI) {
498
- this.hasNil = true;
499
- }
500
- this.statementCount += 1;
501
- }
502
- }, {
503
- key: "statement",
504
- value: function statement(str, i) {
505
- var r = new pyjslib_List([]);
506
- var i = this.object(str, i, r);
398
+ var j = this.tok("prefix", str, i);
399
+ if (j >= 0) {
400
+ var t = new pyjslib_List([]);
401
+ var i = this.qname(str, j, t);
507
402
  if (i < 0) {
508
- return i;
403
+ throw BadSyntax(this._thisDoc, this.lines, str, j, "expected qname after @prefix");
509
404
  }
510
- var j = this.property_list(str, i, r[0]);
405
+ var j = this.uri_ref2(str, i, t);
511
406
  if (j < 0) {
512
- throw BadSyntax(this._thisDoc, this.lines, str, i, "expected propertylist");
407
+ throw BadSyntax(this._thisDoc, this.lines, str, i, "expected <uriref> after @prefix _qname_");
513
408
  }
409
+ var ns = t[1].uri;
410
+ if (this._baseURI) {
411
+ var ns = uripath_join(this._baseURI, ns);
412
+ } else {
413
+ assertFudge(ns.indexOf(":") >= 0, "With no base URI, cannot handle relative URI for NS");
414
+ }
415
+ assertFudge(ns.indexOf(":") >= 0);
416
+ this._bindings[t[0][0]] = ns;
417
+ this.bind(t[0][0], hexify(ns));
514
418
  return j;
515
419
  }
516
- }, {
517
- key: "subject",
518
- value: function subject(str, i, res) {
519
- return this.item(str, i, res);
520
- }
521
- }, {
522
- key: "verb",
523
- value: function verb(str, i, res) {
524
- /*
525
- has _prop_
526
- is _prop_ of
527
- a
528
- =
529
- _prop_
530
- >- prop ->
531
- <- prop -<
532
- _operator_*/
533
-
534
- var j = this.skipSpace(str, i);
535
- if (j < 0) {
536
- return j;
420
+ var j = this.tok("base", str, i);
421
+ if (j >= 0) {
422
+ var t = new pyjslib_List([]);
423
+ var i = this.uri_ref2(str, j, t);
424
+ if (i < 0) {
425
+ throw BadSyntax(this._thisDoc, this.lines, str, j, "expected <uri> after @base ");
537
426
  }
538
- var r = new pyjslib_List([]);
539
- var j = this.tok("has", str, i);
540
- if (j >= 0) {
541
- var i = this.prop(str, j, r);
542
- if (i < 0) {
543
- throw BadSyntax(this._thisDoc, this.lines, str, j, "expected property after 'has'");
544
- }
545
- res.push(new pyjslib_Tuple(["->", r[0]]));
546
- return i;
427
+ var ns = t[0].uri;
428
+ if (this._baseURI) {
429
+ var ns = uripath_join(this._baseURI, ns);
430
+ } else {
431
+ throw BadSyntax(this._thisDoc, this.lines, str, j, "With no previous base URI, cannot use relative URI in @base <" + ns + ">");
547
432
  }
548
- var j = this.tok("is", str, i);
549
- if (j >= 0) {
550
- var i = this.prop(str, j, r);
551
- if (i < 0) {
552
- throw BadSyntax(this._thisDoc, this.lines, str, j, "expected <property> after 'is'");
553
- }
554
- var j = this.skipSpace(str, i);
555
- if (j < 0) {
556
- throw BadSyntax(this._thisDoc, this.lines, str, i, "End of file found, expected property after 'is'");
557
- return j;
558
- }
559
- var i = j;
560
- var j = this.tok("of", str, i);
561
- if (j < 0) {
562
- throw BadSyntax(this._thisDoc, this.lines, str, i, "expected 'of' after 'is' <prop>");
563
- }
564
- res.push(new pyjslib_Tuple(["<-", r[0]]));
565
- return j;
433
+ assertFudge(ns.indexOf(":") >= 0);
434
+ this._baseURI = ns;
435
+ return i;
436
+ }
437
+ return -1;
438
+ }
439
+ bind(qn, uri) {
440
+ if (qn == "") {} else {
441
+ this._store.setPrefixForURI(qn, uri);
442
+ }
443
+ }
444
+ setKeywords(k) {
445
+ /*
446
+ Takes a list of strings*/
447
+
448
+ if (k == null) {
449
+ this.keywordsSet = 0;
450
+ } else {
451
+ this.keywords = k;
452
+ this.keywordsSet = 1;
453
+ }
454
+ }
455
+ startDoc() {}
456
+ /* Signal end of document and stop parsing. returns formula */
457
+ endDoc() {
458
+ if (this.hasNil && this._store.rdfFactory.supports["COLLECTIONS"]) {
459
+ convertFirstRestNil(this._store, this.source);
460
+ }
461
+ return this._formula;
462
+ }
463
+ makeStatement(quad) {
464
+ quad[0].add(quad[2], quad[1], quad[3], this.source);
465
+ if (quad[2].uri && quad[2].uri === RDF_nil_URI || quad[3].uri && quad[3].uri === RDF_nil_URI) {
466
+ this.hasNil = true;
467
+ }
468
+ this.statementCount += 1;
469
+ }
470
+ statement(str, i) {
471
+ var r = new pyjslib_List([]);
472
+ var i = this.object(str, i, r);
473
+ if (i < 0) {
474
+ return i;
475
+ }
476
+ var j = this.property_list(str, i, r[0]);
477
+ if (j < 0) {
478
+ throw BadSyntax(this._thisDoc, this.lines, str, i, "expected propertylist");
479
+ }
480
+ return j;
481
+ }
482
+ subject(str, i, res) {
483
+ return this.item(str, i, res);
484
+ }
485
+ verb(str, i, res) {
486
+ /*
487
+ has _prop_
488
+ is _prop_ of
489
+ a
490
+ =
491
+ _prop_
492
+ >- prop ->
493
+ <- prop -<
494
+ _operator_*/
495
+
496
+ var j = this.skipSpace(str, i);
497
+ if (j < 0) {
498
+ return j;
499
+ }
500
+ var r = new pyjslib_List([]);
501
+ var j = this.tok("has", str, i);
502
+ if (j >= 0) {
503
+ var i = this.prop(str, j, r);
504
+ if (i < 0) {
505
+ throw BadSyntax(this._thisDoc, this.lines, str, j, "expected property after 'has'");
566
506
  }
567
- var j = this.tok("a", str, i);
568
- if (j >= 0) {
569
- res.push(new pyjslib_Tuple(["->", this._store.sym(RDF_type_URI)]));
570
- return j;
507
+ res.push(new pyjslib_Tuple(["->", r[0]]));
508
+ return i;
509
+ }
510
+ var j = this.tok("is", str, i);
511
+ if (j >= 0) {
512
+ var i = this.prop(str, j, r);
513
+ if (i < 0) {
514
+ throw BadSyntax(this._thisDoc, this.lines, str, j, "expected <property> after 'is'");
571
515
  }
572
- if (str.slice(i, i + 2) == "<=") {
573
- res.push(new pyjslib_Tuple(["<-", this._store.sym(Logic_NS + "implies")]));
574
- return i + 2;
516
+ var j = this.skipSpace(str, i);
517
+ if (j < 0) {
518
+ throw BadSyntax(this._thisDoc, this.lines, str, i, "End of file found, expected property after 'is'");
519
+ return j;
575
520
  }
576
- if (str.slice(i, i + 1) == "=") {
577
- if (str.slice(i + 1, i + 2) == ">") {
578
- res.push(new pyjslib_Tuple(["->", this._store.sym(Logic_NS + "implies")]));
579
- return i + 2;
580
- }
581
- res.push(new pyjslib_Tuple(["->", this._store.sym(DAML_sameAs_URI)]));
582
- return i + 1;
521
+ var i = j;
522
+ var j = this.tok("of", str, i);
523
+ if (j < 0) {
524
+ throw BadSyntax(this._thisDoc, this.lines, str, i, "expected 'of' after 'is' <prop>");
583
525
  }
584
- if (str.slice(i, i + 2) == ":=") {
585
- res.push(new pyjslib_Tuple(["->", Logic_NS + "becomes"]));
526
+ res.push(new pyjslib_Tuple(["<-", r[0]]));
527
+ return j;
528
+ }
529
+ var j = this.tok("a", str, i);
530
+ if (j >= 0) {
531
+ res.push(new pyjslib_Tuple(["->", this._store.sym(RDF_type_URI)]));
532
+ return j;
533
+ }
534
+ if (str.slice(i, i + 2) == "<=") {
535
+ res.push(new pyjslib_Tuple(["<-", this._store.sym(Logic_NS + "implies")]));
536
+ return i + 2;
537
+ }
538
+ if (str.slice(i, i + 1) == "=") {
539
+ if (str.slice(i + 1, i + 2) == ">") {
540
+ res.push(new pyjslib_Tuple(["->", this._store.sym(Logic_NS + "implies")]));
586
541
  return i + 2;
587
542
  }
588
- var j = this.prop(str, i, r);
589
- if (j >= 0) {
590
- res.push(new pyjslib_Tuple(["->", r[0]]));
591
- return j;
592
- }
593
- if (str.slice(i, i + 2) == ">-" || str.slice(i, i + 2) == "<-") {
594
- throw BadSyntax(this._thisDoc, this.lines, str, j, ">- ... -> syntax is obsolete.");
595
- }
596
- return -1;
543
+ res.push(new pyjslib_Tuple(["->", this._store.sym(DAML_sameAs_URI)]));
544
+ return i + 1;
597
545
  }
598
- }, {
599
- key: "prop",
600
- value: function prop(str, i, res) {
601
- return this.item(str, i, res);
602
- }
603
- }, {
604
- key: "item",
605
- value: function item(str, i, res) {
606
- return this.path(str, i, res);
607
- }
608
- }, {
609
- key: "blankNode",
610
- value: function blankNode(uri) {
611
- return this._context.bnode(uri, this._reason2);
612
- }
613
- }, {
614
- key: "path",
615
- value: function path(str, i, res) {
616
- /*
617
- Parse the path production.
618
- */
546
+ if (str.slice(i, i + 2) == ":=") {
547
+ res.push(new pyjslib_Tuple(["->", Logic_NS + "becomes"]));
548
+ return i + 2;
549
+ }
550
+ var j = this.prop(str, i, r);
551
+ if (j >= 0) {
552
+ res.push(new pyjslib_Tuple(["->", r[0]]));
553
+ return j;
554
+ }
555
+ if (str.slice(i, i + 2) == ">-" || str.slice(i, i + 2) == "<-") {
556
+ throw BadSyntax(this._thisDoc, this.lines, str, j, ">- ... -> syntax is obsolete.");
557
+ }
558
+ return -1;
559
+ }
560
+ prop(str, i, res) {
561
+ return this.item(str, i, res);
562
+ }
563
+ item(str, i, res) {
564
+ return this.path(str, i, res);
565
+ }
566
+ blankNode(uri) {
567
+ return this._context.bnode(uri, this._reason2);
568
+ }
569
+ path(str, i, res) {
570
+ /*
571
+ Parse the path production.
572
+ */
619
573
 
620
- var j = this.nodeOrLiteral(str, i, res);
574
+ var j = this.nodeOrLiteral(str, i, res);
575
+ if (j < 0) {
576
+ return j;
577
+ }
578
+ while ("!^.".indexOf(str.slice(j, j + 1)) >= 0) {
579
+ var ch = str.slice(j, j + 1);
580
+ if (ch == ".") {
581
+ var ahead = str.slice(j + 1, j + 2);
582
+ if (!ahead || _notNameChars.indexOf(ahead) >= 0 && ":?<[{(".indexOf(ahead) < 0) {
583
+ break;
584
+ }
585
+ }
586
+ var subj = res.pop();
587
+ var obj = this.blankNode(this.here(j));
588
+ var j = this.node(str, j + 1, res);
621
589
  if (j < 0) {
622
- return j;
590
+ throw BadSyntax(this._thisDoc, this.lines, str, j, "EOF found in middle of path syntax");
623
591
  }
624
- while ("!^.".indexOf(str.slice(j, j + 1)) >= 0) {
625
- var ch = str.slice(j, j + 1);
626
- if (ch == ".") {
627
- var ahead = str.slice(j + 1, j + 2);
628
- if (!ahead || _notNameChars.indexOf(ahead) >= 0 && ":?<[{(".indexOf(ahead) < 0) {
629
- break;
630
- }
631
- }
632
- var subj = res.pop();
633
- var obj = this.blankNode(this.here(j));
634
- var j = this.node(str, j + 1, res);
635
- if (j < 0) {
636
- throw BadSyntax(this._thisDoc, this.lines, str, j, "EOF found in middle of path syntax");
637
- }
638
- var pred = res.pop();
639
- if (ch == "^") {
640
- this.makeStatement(new pyjslib_Tuple([this._context, pred, obj, subj]));
641
- } else {
642
- this.makeStatement(new pyjslib_Tuple([this._context, pred, subj, obj]));
643
- }
644
- res.push(obj);
592
+ var pred = res.pop();
593
+ if (ch == "^") {
594
+ this.makeStatement(new pyjslib_Tuple([this._context, pred, obj, subj]));
595
+ } else {
596
+ this.makeStatement(new pyjslib_Tuple([this._context, pred, subj, obj]));
645
597
  }
646
- return j;
598
+ res.push(obj);
647
599
  }
648
- }, {
649
- key: "anonymousNode",
650
- value: function anonymousNode(ln) {
651
- /*
652
- Remember or generate a term for one of these _: anonymous nodes*/
600
+ return j;
601
+ }
602
+ anonymousNode(ln) {
603
+ /*
604
+ Remember or generate a term for one of these _: anonymous nodes*/
653
605
 
654
- var term = this._anonymousNodes[ln];
655
- if (term) {
656
- return term;
657
- }
658
- var term = this._store.bnode(ln);
659
- // var term = this._store.bnode(this._context, this._reason2); eh?
660
- this._anonymousNodes[ln] = term;
606
+ var term = this._anonymousNodes[ln];
607
+ if (term) {
661
608
  return term;
662
609
  }
663
- }, {
664
- key: "node",
665
- value: function node(str, i, res, subjectAlready) {
666
- if (typeof subjectAlready == 'undefined') subjectAlready = null;
667
- /*
668
- Parse the <node> production.
669
- Space is now skipped once at the beginning
670
- instead of in multipe calls to self.skipSpace().
671
- */
610
+ var term = this._store.bnode(ln);
611
+ // var term = this._store.bnode(this._context, this._reason2); eh?
612
+ this._anonymousNodes[ln] = term;
613
+ return term;
614
+ }
615
+ node(str, i, res, subjectAlready) {
616
+ if (typeof subjectAlready == 'undefined') subjectAlready = null;
617
+ /*
618
+ Parse the <node> production.
619
+ Space is now skipped once at the beginning
620
+ instead of in multipe calls to self.skipSpace().
621
+ */
672
622
 
673
- var subj = subjectAlready;
674
- var j = this.skipSpace(str, i);
623
+ var subj = subjectAlready;
624
+ var j = this.skipSpace(str, i);
625
+ if (j < 0) {
626
+ return j;
627
+ }
628
+ var i = j;
629
+ var ch = str.slice(i, i + 1);
630
+ if (ch == "[") {
631
+ var bnodeID = this.here(i);
632
+ var j = this.skipSpace(str, i + 1);
675
633
  if (j < 0) {
676
- return j;
634
+ throw BadSyntax(this._thisDoc, this.lines, str, i, "EOF after '['");
677
635
  }
678
- var i = j;
679
- var ch = str.slice(i, i + 1);
680
- if (ch == "[") {
681
- var bnodeID = this.here(i);
682
- var j = this.skipSpace(str, i + 1);
683
- if (j < 0) {
684
- throw BadSyntax(this._thisDoc, this.lines, str, i, "EOF after '['");
685
- }
686
- if (str.slice(j, j + 1) == "=") {
687
- var i = j + 1;
688
- var objs = new pyjslib_List([]);
689
- var j = this.objectList(str, i, objs);
690
- if (j >= 0) {
691
- var subj = objs[0];
692
- if (pyjslib_len(objs) > 1) {
693
- var __obj = new pyjslib_Iterator(objs);
694
- try {
695
- while (true) {
696
- var obj = __obj.next();
697
- this.makeStatement(new pyjslib_Tuple([this._context, this._store.sym(DAML_sameAs_URI), subj, obj]));
698
- }
699
- } catch (e) {
700
- if (e != StopIteration) {
701
- throw e;
702
- }
636
+ if (str.slice(j, j + 1) == "=") {
637
+ var i = j + 1;
638
+ var objs = new pyjslib_List([]);
639
+ var j = this.objectList(str, i, objs);
640
+ if (j >= 0) {
641
+ var subj = objs[0];
642
+ if (pyjslib_len(objs) > 1) {
643
+ var __obj = new pyjslib_Iterator(objs);
644
+ try {
645
+ while (true) {
646
+ var obj = __obj.next();
647
+ this.makeStatement(new pyjslib_Tuple([this._context, this._store.sym(DAML_sameAs_URI), subj, obj]));
703
648
  }
704
- }
705
- var j = this.skipSpace(str, j);
706
- if (j < 0) {
707
- throw BadSyntax(this._thisDoc, this.lines, str, i, "EOF when objectList expected after [ = ");
708
- }
709
- if (str.slice(j, j + 1) == ";") {
710
- var j = j + 1;
711
- }
712
- } else {
713
- throw BadSyntax(this._thisDoc, this.lines, str, i, "objectList expected after [= ");
714
- }
715
- }
716
- if (subj == null) {
717
- var subj = this.blankNode(bnodeID);
718
- }
719
- var i = this.property_list(str, j, subj);
720
- if (i < 0) {
721
- throw BadSyntax(this._thisDoc, this.lines, str, j, "property_list expected");
722
- }
723
- var j = this.skipSpace(str, i);
724
- if (j < 0) {
725
- throw BadSyntax(this._thisDoc, this.lines, str, i, "EOF when ']' expected after [ <propertyList>");
726
- }
727
- if (str.slice(j, j + 1) != "]") {
728
- throw BadSyntax(this._thisDoc, this.lines, str, j, "']' expected");
729
- }
730
- res.push(subj);
731
- return j + 1;
732
- }
733
- if (ch == "{") {
734
- var ch2 = str.slice(i + 1, i + 2);
735
- if (ch2 == "$") {
736
- i += 1;
737
- var j = i + 1;
738
- var mylist = new pyjslib_List([]);
739
- var first_run = true;
740
- while (1) {
741
- var i = this.skipSpace(str, j);
742
- if (i < 0) {
743
- throw BadSyntax(this._thisDoc, this.lines, str, i, "needed '$}', found end.");
744
- }
745
- if (str.slice(i, i + 2) == "$}") {
746
- var j = i + 2;
747
- break;
748
- }
749
- if (!first_run) {
750
- if (str.slice(i, i + 1) == ",") {
751
- i += 1;
752
- } else {
753
- throw BadSyntax(this._thisDoc, this.lines, str, i, "expected: ','");
649
+ } catch (e) {
650
+ if (e != StopIteration) {
651
+ throw e;
754
652
  }
755
- } else {
756
- var first_run = false;
757
- }
758
- var item = new pyjslib_List([]);
759
- var j = this.item(str, i, item);
760
- if (j < 0) {
761
- throw BadSyntax(this._thisDoc, this.lines, str, i, "expected item in set or '$}'");
762
653
  }
763
- mylist.push(item[0]);
764
654
  }
765
- res.push(this._store.newSet(mylist, this._context));
766
- return j;
767
- } else {
768
- var j = i + 1;
769
- var oldParentContext = this._parentContext;
770
- this._parentContext = this._context;
771
- var parentAnonymousNodes = this._anonymousNodes;
772
- var grandParentVariables = this._parentVariables;
773
- this._parentVariables = this._variables;
774
- this._anonymousNodes = new pyjslib_Dict([]);
775
- this._variables = this._variables.slice();
776
- var reason2 = this._reason2;
777
- this._reason2 = becauseSubexpression;
778
- if (subj == null) {
779
- var subj = this._store.formula();
655
+ var j = this.skipSpace(str, j);
656
+ if (j < 0) {
657
+ throw BadSyntax(this._thisDoc, this.lines, str, i, "EOF when objectList expected after [ = ");
780
658
  }
781
- this._context = subj;
782
- while (1) {
783
- var i = this.skipSpace(str, j);
784
- if (i < 0) {
785
- throw BadSyntax(this._thisDoc, this.lines, str, i, "needed '}', found end.");
786
- }
787
- if (str.slice(i, i + 1) == "}") {
788
- var j = i + 1;
789
- break;
790
- }
791
- var j = this.directiveOrStatement(str, i);
792
- if (j < 0) {
793
- throw BadSyntax(this._thisDoc, this.lines, str, i, "expected statement or '}'");
794
- }
659
+ if (str.slice(j, j + 1) == ";") {
660
+ var j = j + 1;
795
661
  }
796
- this._anonymousNodes = parentAnonymousNodes;
797
- this._variables = this._parentVariables;
798
- this._parentVariables = grandParentVariables;
799
- this._context = this._parentContext;
800
- this._reason2 = reason2;
801
- this._parentContext = oldParentContext;
802
- res.push(subj.close());
803
- return j;
662
+ } else {
663
+ throw BadSyntax(this._thisDoc, this.lines, str, i, "objectList expected after [= ");
804
664
  }
805
665
  }
806
- if (ch == "(") {
807
- var thing_type = this._store.list;
808
- var ch2 = str.slice(i + 1, i + 2);
809
- if (ch2 == "$") {
810
- var thing_type = this._store.newSet;
811
- i += 1;
812
- }
666
+ if (subj == null) {
667
+ var subj = this.blankNode(bnodeID);
668
+ }
669
+ var i = this.property_list(str, j, subj);
670
+ if (i < 0) {
671
+ throw BadSyntax(this._thisDoc, this.lines, str, j, "property_list expected");
672
+ }
673
+ var j = this.skipSpace(str, i);
674
+ if (j < 0) {
675
+ throw BadSyntax(this._thisDoc, this.lines, str, i, "EOF when ']' expected after [ <propertyList>");
676
+ }
677
+ if (str.slice(j, j + 1) != "]") {
678
+ throw BadSyntax(this._thisDoc, this.lines, str, j, "']' expected");
679
+ }
680
+ res.push(subj);
681
+ return j + 1;
682
+ }
683
+ if (ch == "{") {
684
+ var ch2 = str.slice(i + 1, i + 2);
685
+ if (ch2 == "$") {
686
+ i += 1;
813
687
  var j = i + 1;
814
688
  var mylist = new pyjslib_List([]);
689
+ var first_run = true;
815
690
  while (1) {
816
691
  var i = this.skipSpace(str, j);
817
692
  if (i < 0) {
818
- throw BadSyntax(this._thisDoc, this.lines, str, i, "needed ')', found end.");
693
+ throw BadSyntax(this._thisDoc, this.lines, str, i, "needed '$}', found end.");
819
694
  }
820
- if (str.slice(i, i + 1) == ")") {
821
- var j = i + 1;
695
+ if (str.slice(i, i + 2) == "$}") {
696
+ var j = i + 2;
822
697
  break;
823
698
  }
699
+ if (!first_run) {
700
+ if (str.slice(i, i + 1) == ",") {
701
+ i += 1;
702
+ } else {
703
+ throw BadSyntax(this._thisDoc, this.lines, str, i, "expected: ','");
704
+ }
705
+ } else {
706
+ var first_run = false;
707
+ }
824
708
  var item = new pyjslib_List([]);
825
709
  var j = this.item(str, i, item);
826
710
  if (j < 0) {
827
- throw BadSyntax(this._thisDoc, this.lines, str, i, "expected item in list or ')'");
711
+ throw BadSyntax(this._thisDoc, this.lines, str, i, "expected item in set or '$}'");
828
712
  }
829
713
  mylist.push(item[0]);
830
714
  }
831
- res.push(thing_type(mylist, this._context));
832
- return j;
833
- }
834
- var j = this.tok("this", str, i);
835
- if (j >= 0) {
836
- throw BadSyntax(this._thisDoc, this.lines, str, i, "Keyword 'this' was ancient N3. Now use @forSome and @forAll keywords.");
837
- res.push(this._context);
838
- return j;
839
- }
840
- var j = this.tok("true", str, i);
841
- if (j >= 0) {
842
- res.push(true);
843
- return j;
844
- }
845
- var j = this.tok("false", str, i);
846
- if (j >= 0) {
847
- res.push(false);
715
+ res.push(this._store.newSet(mylist, this._context));
848
716
  return j;
849
- }
850
- if (subj == null) {
851
- var j = this.uri_ref2(str, i, res);
852
- if (j >= 0) {
853
- return j;
854
- }
855
- }
856
- return -1;
857
- }
858
- }, {
859
- key: "property_list",
860
- value: function property_list(str, i, subj) {
861
- /*
862
- Parse property list
863
- Leaves the terminating punctuation in the buffer
864
- */
865
-
866
- while (1) {
867
- var j = this.skipSpace(str, i);
868
- if (j < 0) {
869
- throw BadSyntax(this._thisDoc, this.lines, str, i, "EOF found when expected verb in property list");
870
- return j;
717
+ } else {
718
+ var j = i + 1;
719
+ var oldParentContext = this._parentContext;
720
+ this._parentContext = this._context;
721
+ var parentAnonymousNodes = this._anonymousNodes;
722
+ var grandParentVariables = this._parentVariables;
723
+ this._parentVariables = this._variables;
724
+ this._anonymousNodes = new pyjslib_Dict([]);
725
+ this._variables = this._variables.slice();
726
+ var reason2 = this._reason2;
727
+ this._reason2 = becauseSubexpression;
728
+ if (subj == null) {
729
+ var subj = this._store.formula();
871
730
  }
872
- if (str.slice(j, j + 2) == ":-") {
873
- var i = j + 2;
874
- var res = new pyjslib_List([]);
875
- var j = this.node(str, i, res, subj);
731
+ this._context = subj;
732
+ while (1) {
733
+ var i = this.skipSpace(str, j);
734
+ if (i < 0) {
735
+ throw BadSyntax(this._thisDoc, this.lines, str, i, "needed '}', found end.");
736
+ }
737
+ if (str.slice(i, i + 1) == "}") {
738
+ var j = i + 1;
739
+ break;
740
+ }
741
+ var j = this.directiveOrStatement(str, i);
876
742
  if (j < 0) {
877
- throw BadSyntax(this._thisDoc, this.lines, str, i, "bad {} or () or [] node after :- ");
743
+ throw BadSyntax(this._thisDoc, this.lines, str, i, "expected statement or '}'");
878
744
  }
879
- var i = j;
880
- continue;
881
- }
882
- var i = j;
883
- var v = new pyjslib_List([]);
884
- var j = this.verb(str, i, v);
885
- if (j <= 0) {
886
- return i;
887
745
  }
888
- var objs = new pyjslib_List([]);
889
- var i = this.objectList(str, j, objs);
746
+ this._anonymousNodes = parentAnonymousNodes;
747
+ this._variables = this._parentVariables;
748
+ this._parentVariables = grandParentVariables;
749
+ this._context = this._parentContext;
750
+ this._reason2 = reason2;
751
+ this._parentContext = oldParentContext;
752
+ res.push(subj.close());
753
+ return j;
754
+ }
755
+ }
756
+ if (ch == "(") {
757
+ var thing_type = this._store.list;
758
+ var ch2 = str.slice(i + 1, i + 2);
759
+ if (ch2 == "$") {
760
+ var thing_type = this._store.newSet;
761
+ i += 1;
762
+ }
763
+ var j = i + 1;
764
+ var mylist = new pyjslib_List([]);
765
+ while (1) {
766
+ var i = this.skipSpace(str, j);
890
767
  if (i < 0) {
891
- throw BadSyntax(this._thisDoc, this.lines, str, j, "objectList expected");
768
+ throw BadSyntax(this._thisDoc, this.lines, str, i, "needed ')', found end.");
892
769
  }
893
- var __obj = new pyjslib_Iterator(objs);
894
- try {
895
- while (true) {
896
- var obj = __obj.next();
897
- var pairFudge = v[0];
898
- var dir = pairFudge[0];
899
- var sym = pairFudge[1];
900
- if (dir == "->") {
901
- this.makeStatement(new pyjslib_Tuple([this._context, sym, subj, obj]));
902
- } else {
903
- this.makeStatement(new pyjslib_Tuple([this._context, sym, obj, subj]));
904
- }
905
- }
906
- } catch (e) {
907
- if (e != StopIteration) {
908
- throw e;
909
- }
770
+ if (str.slice(i, i + 1) == ")") {
771
+ var j = i + 1;
772
+ break;
910
773
  }
911
- var j = this.skipSpace(str, i);
774
+ var item = new pyjslib_List([]);
775
+ var j = this.item(str, i, item);
912
776
  if (j < 0) {
913
- throw BadSyntax(this._thisDoc, this.lines, str, j, "EOF found in list of objects");
914
- return j;
777
+ throw BadSyntax(this._thisDoc, this.lines, str, i, "expected item in list or ')'");
915
778
  }
916
- if (str.slice(i, i + 1) != ";") {
917
- return i;
918
- }
919
- var i = i + 1;
779
+ mylist.push(item[0]);
920
780
  }
781
+ res.push(thing_type(mylist, this._context));
782
+ return j;
921
783
  }
922
- }, {
923
- key: "commaSeparatedList",
924
- value: function commaSeparatedList(str, j, res, ofUris) {
925
- /*
926
- return value: -1 bad syntax; >1 new position in str
927
- res has things found appended
928
- Used to use a final value of the function to be called, e.g. this.bareWord
929
- but passing the function didn't work fo js converion pyjs
930
- */
931
-
932
- var i = this.skipSpace(str, j);
933
- if (i < 0) {
934
- throw BadSyntax(this._thisDoc, this.lines, str, i, "EOF found expecting comma sep list");
935
- return i;
936
- }
937
- if (str.charAt(i) == ".") {
784
+ var j = this.tok("this", str, i);
785
+ if (j >= 0) {
786
+ throw BadSyntax(this._thisDoc, this.lines, str, i, "Keyword 'this' was ancient N3. Now use @forSome and @forAll keywords.");
787
+ res.push(this._context);
788
+ return j;
789
+ }
790
+ var j = this.tok("true", str, i);
791
+ if (j >= 0) {
792
+ res.push(true);
793
+ return j;
794
+ }
795
+ var j = this.tok("false", str, i);
796
+ if (j >= 0) {
797
+ res.push(false);
798
+ return j;
799
+ }
800
+ if (subj == null) {
801
+ var j = this.uri_ref2(str, i, res);
802
+ if (j >= 0) {
938
803
  return j;
939
804
  }
940
- if (ofUris) {
941
- var i = this.uri_ref2(str, i, res);
942
- } else {
943
- var i = this.bareWord(str, i, res);
944
- }
945
- if (i < 0) {
946
- return -1;
805
+ }
806
+ return -1;
807
+ }
808
+ property_list(str, i, subj) {
809
+ /*
810
+ Parse property list
811
+ Leaves the terminating punctuation in the buffer
812
+ */
813
+
814
+ while (1) {
815
+ var j = this.skipSpace(str, i);
816
+ if (j < 0) {
817
+ throw BadSyntax(this._thisDoc, this.lines, str, i, "EOF found when expected verb in property list");
818
+ return j;
947
819
  }
948
- while (1) {
949
- var j = this.skipSpace(str, i);
820
+ if (str.slice(j, j + 2) == ":-") {
821
+ var i = j + 2;
822
+ var res = new pyjslib_List([]);
823
+ var j = this.node(str, i, res, subj);
950
824
  if (j < 0) {
951
- return j;
825
+ throw BadSyntax(this._thisDoc, this.lines, str, i, "bad {} or () or [] node after :- ");
952
826
  }
953
- var ch = str.slice(j, j + 1);
954
- if (ch != ",") {
955
- if (ch != ".") {
956
- return -1;
827
+ var i = j;
828
+ continue;
829
+ }
830
+ var i = j;
831
+ var v = new pyjslib_List([]);
832
+ var j = this.verb(str, i, v);
833
+ if (j <= 0) {
834
+ return i;
835
+ }
836
+ var objs = new pyjslib_List([]);
837
+ var i = this.objectList(str, j, objs);
838
+ if (i < 0) {
839
+ throw BadSyntax(this._thisDoc, this.lines, str, j, "objectList expected");
840
+ }
841
+ var __obj = new pyjslib_Iterator(objs);
842
+ try {
843
+ while (true) {
844
+ var obj = __obj.next();
845
+ var pairFudge = v[0];
846
+ var dir = pairFudge[0];
847
+ var sym = pairFudge[1];
848
+ if (dir == "->") {
849
+ this.makeStatement(new pyjslib_Tuple([this._context, sym, subj, obj]));
850
+ } else {
851
+ this.makeStatement(new pyjslib_Tuple([this._context, sym, obj, subj]));
957
852
  }
958
- return j;
959
- }
960
- if (ofUris) {
961
- var i = this.uri_ref2(str, j + 1, res);
962
- } else {
963
- var i = this.bareWord(str, j + 1, res);
964
853
  }
965
- if (i < 0) {
966
- throw BadSyntax(this._thisDoc, this.lines, str, i, "bad list content");
967
- return i;
854
+ } catch (e) {
855
+ if (e != StopIteration) {
856
+ throw e;
968
857
  }
969
858
  }
970
- }
971
- }, {
972
- key: "objectList",
973
- value: function objectList(str, i, res) {
974
- var i = this.object(str, i, res);
975
- if (i < 0) {
976
- return -1;
859
+ var j = this.skipSpace(str, i);
860
+ if (j < 0) {
861
+ throw BadSyntax(this._thisDoc, this.lines, str, j, "EOF found in list of objects");
862
+ return j;
977
863
  }
978
- while (1) {
979
- var j = this.skipSpace(str, i);
980
- if (j < 0) {
981
- throw BadSyntax(this._thisDoc, this.lines, str, j, "EOF found after object");
982
- return j;
983
- }
984
- if (str.slice(j, j + 1) != ",") {
985
- return j;
986
- }
987
- var i = this.object(str, j + 1, res);
988
- if (i < 0) {
989
- return i;
990
- }
864
+ if (str.slice(i, i + 1) != ";") {
865
+ return i;
991
866
  }
867
+ var i = i + 1;
992
868
  }
993
- }, {
994
- key: "checkDot",
995
- value: function checkDot(str, i) {
869
+ }
870
+ commaSeparatedList(str, j, res, ofUris) {
871
+ /*
872
+ return value: -1 bad syntax; >1 new position in str
873
+ res has things found appended
874
+ Used to use a final value of the function to be called, e.g. this.bareWord
875
+ but passing the function didn't work fo js converion pyjs
876
+ */
877
+
878
+ var i = this.skipSpace(str, j);
879
+ if (i < 0) {
880
+ throw BadSyntax(this._thisDoc, this.lines, str, i, "EOF found expecting comma sep list");
881
+ return i;
882
+ }
883
+ if (str.charAt(i) == ".") {
884
+ return j;
885
+ }
886
+ if (ofUris) {
887
+ var i = this.uri_ref2(str, i, res);
888
+ } else {
889
+ var i = this.bareWord(str, i, res);
890
+ }
891
+ if (i < 0) {
892
+ return -1;
893
+ }
894
+ while (1) {
996
895
  var j = this.skipSpace(str, i);
997
896
  if (j < 0) {
998
897
  return j;
999
898
  }
1000
- if (str.slice(j, j + 1) == ".") {
1001
- return j + 1;
899
+ var ch = str.slice(j, j + 1);
900
+ if (ch != ",") {
901
+ if (ch != ".") {
902
+ return -1;
903
+ }
904
+ return j;
1002
905
  }
1003
- if (str.slice(j, j + 1) == "}") {
906
+ if (ofUris) {
907
+ var i = this.uri_ref2(str, j + 1, res);
908
+ } else {
909
+ var i = this.bareWord(str, j + 1, res);
910
+ }
911
+ if (i < 0) {
912
+ throw BadSyntax(this._thisDoc, this.lines, str, i, "bad list content");
913
+ return i;
914
+ }
915
+ }
916
+ }
917
+ objectList(str, i, res) {
918
+ var i = this.object(str, i, res);
919
+ if (i < 0) {
920
+ return -1;
921
+ }
922
+ while (1) {
923
+ var j = this.skipSpace(str, i);
924
+ if (j < 0) {
925
+ throw BadSyntax(this._thisDoc, this.lines, str, j, "EOF found after object");
1004
926
  return j;
1005
927
  }
1006
- if (str.slice(j, j + 1) == "]") {
928
+ if (str.slice(j, j + 1) != ",") {
1007
929
  return j;
1008
930
  }
1009
- throw BadSyntax(this._thisDoc, this.lines, str, j, "expected '.' or '}' or ']' at end of statement");
1010
- return i;
931
+ var i = this.object(str, j + 1, res);
932
+ if (i < 0) {
933
+ return i;
934
+ }
935
+ }
936
+ }
937
+ checkDot(str, i) {
938
+ var j = this.skipSpace(str, i);
939
+ if (j < 0) {
940
+ return j;
941
+ }
942
+ if (str.slice(j, j + 1) == ".") {
943
+ return j + 1;
944
+ }
945
+ if (str.slice(j, j + 1) == "}") {
946
+ return j;
947
+ }
948
+ if (str.slice(j, j + 1) == "]") {
949
+ return j;
1011
950
  }
1012
- }, {
1013
- key: "uri_ref2",
1014
- value: function uri_ref2(str, i, res) {
1015
- /*
1016
- Generate uri from n3 representation.
1017
- Note that the RDF convention of directly concatenating
1018
- NS and local name is now used though I prefer inserting a '#'
1019
- to make the namesapces look more like what XML folks expect.
1020
- */
951
+ throw BadSyntax(this._thisDoc, this.lines, str, j, "expected '.' or '}' or ']' at end of statement");
952
+ return i;
953
+ }
954
+ uri_ref2(str, i, res) {
955
+ /*
956
+ Generate uri from n3 representation.
957
+ Note that the RDF convention of directly concatenating
958
+ NS and local name is now used though I prefer inserting a '#'
959
+ to make the namesapces look more like what XML folks expect.
960
+ */
1021
961
 
1022
- var qn = new pyjslib_List([]);
1023
- var j = this.qname(str, i, qn);
1024
- if (j >= 0) {
1025
- var pairFudge = qn[0];
1026
- var pfx = pairFudge[0];
1027
- var ln = pairFudge[1];
1028
- if (pfx == null) {
1029
- assertFudge(0, "not used?");
1030
- var ns = this._baseURI + ADDED_HASH;
1031
- } else {
1032
- var ns = this._bindings[pfx];
1033
- if (!ns) {
1034
- if (pfx == "_") {
1035
- res.push(this.anonymousNode(ln));
1036
- return j;
1037
- }
1038
- throw BadSyntax(this._thisDoc, this.lines, str, i, "Prefix " + pfx + " not bound.");
962
+ var qn = new pyjslib_List([]);
963
+ var j = this.qname(str, i, qn);
964
+ if (j >= 0) {
965
+ var pairFudge = qn[0];
966
+ var pfx = pairFudge[0];
967
+ var ln = pairFudge[1];
968
+ if (pfx == null) {
969
+ assertFudge(0, "not used?");
970
+ var ns = this._baseURI + ADDED_HASH;
971
+ } else {
972
+ var ns = this._bindings[pfx];
973
+ if (!ns) {
974
+ if (pfx == "_") {
975
+ res.push(this.anonymousNode(ln));
976
+ return j;
1039
977
  }
978
+ throw BadSyntax(this._thisDoc, this.lines, str, i, "Prefix " + pfx + " not bound.");
1040
979
  }
1041
- var symb = this._store.sym(ns + ln);
1042
- if (ArrayIndexOf(this._variables, symb) >= 0) {
1043
- res.push(this._variables[symb]);
1044
- } else {
1045
- res.push(symb);
1046
- }
1047
- return j;
1048
980
  }
1049
- var i = this.skipSpace(str, i);
1050
- if (i < 0) {
1051
- return -1;
981
+ var symb = this._store.sym(ns + ln);
982
+ if (ArrayIndexOf(this._variables, symb) >= 0) {
983
+ res.push(this._variables[symb]);
984
+ } else {
985
+ res.push(symb);
1052
986
  }
1053
- if (str.charAt(i) == "?") {
1054
- var v = new pyjslib_List([]);
1055
- var j = this.variable(str, i, v);
1056
- if (j > 0) {
1057
- res.push(v[0]);
1058
- return j;
987
+ return j;
988
+ }
989
+ var i = this.skipSpace(str, i);
990
+ if (i < 0) {
991
+ return -1;
992
+ }
993
+ if (str.charAt(i) == "?") {
994
+ var v = new pyjslib_List([]);
995
+ var j = this.variable(str, i, v);
996
+ if (j > 0) {
997
+ res.push(v[0]);
998
+ return j;
999
+ }
1000
+ return -1;
1001
+ } else if (str.charAt(i) == "<") {
1002
+ var i = i + 1;
1003
+ var st = i;
1004
+ while (i < pyjslib_len(str)) {
1005
+ if (str.charAt(i) == ">") {
1006
+ var uref = str.slice(st, i);
1007
+ if (this._baseURI) {
1008
+ var uref = uripath_join(this._baseURI, uref);
1009
+ } else {
1010
+ assertFudge(uref.indexOf(":") >= 0, "With no base URI, cannot deal with relative URIs");
1011
+ }
1012
+ if (str.slice(i - 1, i) == "#" && !(pyjslib_slice(uref, -1, null) == "#")) {
1013
+ var uref = uref + "#";
1014
+ }
1015
+ var symb = this._store.sym(uref);
1016
+ if (ArrayIndexOf(this._variables, symb) >= 0) {
1017
+ res.push(this._variables[symb]);
1018
+ } else {
1019
+ res.push(symb);
1020
+ }
1021
+ return i + 1;
1059
1022
  }
1060
- return -1;
1061
- } else if (str.charAt(i) == "<") {
1062
1023
  var i = i + 1;
1063
- var st = i;
1064
- while (i < pyjslib_len(str)) {
1065
- if (str.charAt(i) == ">") {
1066
- var uref = str.slice(st, i);
1067
- if (this._baseURI) {
1068
- var uref = uripath_join(this._baseURI, uref);
1069
- } else {
1070
- assertFudge(uref.indexOf(":") >= 0, "With no base URI, cannot deal with relative URIs");
1071
- }
1072
- if (str.slice(i - 1, i) == "#" && !(pyjslib_slice(uref, -1, null) == "#")) {
1073
- var uref = uref + "#";
1024
+ }
1025
+ throw BadSyntax(this._thisDoc, this.lines, str, j, "unterminated URI reference");
1026
+ } else if (this.keywordsSet) {
1027
+ var v = new pyjslib_List([]);
1028
+ var j = this.bareWord(str, i, v);
1029
+ if (j < 0) {
1030
+ return -1;
1031
+ }
1032
+ if (ArrayIndexOf(this.keywords, v[0]) >= 0) {
1033
+ throw BadSyntax(this._thisDoc, this.lines, str, i, "Keyword \"" + v[0] + "\" not allowed here.");
1034
+ }
1035
+ res.push(this._store.sym(this._bindings[""] + v[0]));
1036
+ return j;
1037
+ } else {
1038
+ return -1;
1039
+ }
1040
+ }
1041
+ skipSpace(str, i) {
1042
+ /*
1043
+ Skip white space, newlines and comments.
1044
+ return -1 if EOF, else position of first non-ws character*/
1045
+
1046
+ var whitespace = ' \n\r\t\f\x0b\xa0\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200a\u200b\u2028\u2029\u3000';
1047
+ for (var j = i ? i : 0; j < str.length; j++) {
1048
+ var ch = str.charAt(j);
1049
+ // console.log(" skipspace j= "+j + " i= " + i + " n= " + str.length);
1050
+ // console.log(" skipspace ch <" + ch + ">");
1051
+ if (whitespace.indexOf(ch) < 0) {
1052
+ //not ws
1053
+ // console.log(" skipspace 2 ch <" + ch + ">");
1054
+ if (str.charAt(j) === '#') {
1055
+ for (;; j++) {
1056
+ // console.log(" skipspace2 j= "+j + " i= " + i + " n= " + str.length);
1057
+ if (j === str.length) {
1058
+ return -1; // EOF
1074
1059
  }
1075
- var symb = this._store.sym(uref);
1076
- if (ArrayIndexOf(this._variables, symb) >= 0) {
1077
- res.push(this._variables[symb]);
1078
- } else {
1079
- res.push(symb);
1060
+ if (str.charAt(j) === '\n') {
1061
+ this.lines = this.lines + 1;
1062
+ break;
1080
1063
  }
1081
- return i + 1;
1082
1064
  }
1083
- var i = i + 1;
1084
- }
1085
- throw BadSyntax(this._thisDoc, this.lines, str, j, "unterminated URI reference");
1086
- } else if (this.keywordsSet) {
1087
- var v = new pyjslib_List([]);
1088
- var j = this.bareWord(str, i, v);
1089
- if (j < 0) {
1090
- return -1;
1091
- }
1092
- if (ArrayIndexOf(this.keywords, v[0]) >= 0) {
1093
- throw BadSyntax(this._thisDoc, this.lines, str, i, "Keyword \"" + v[0] + "\" not allowed here.");
1065
+ ;
1066
+ } else {
1067
+ // Not hash - something interesting
1068
+ // console.log(" skipspace 3 ch <" + ch + ">");
1069
+ return j;
1094
1070
  }
1095
- res.push(this._store.sym(this._bindings[""] + v[0]));
1096
- return j;
1097
1071
  } else {
1098
- return -1;
1072
+ // Whitespace
1073
+ // console.log(" skipspace 5 ch <" + ch + ">");
1074
+ if (str.charAt(j) === '\n') {
1075
+ this.lines = this.lines + 1;
1076
+ }
1099
1077
  }
1078
+ } // next j
1079
+ return -1; // EOF
1080
+ }
1081
+ variable(str, i, res) {
1082
+ /*
1083
+ ?abc -> variable(:abc)
1084
+ */
1085
+
1086
+ var j = this.skipSpace(str, i);
1087
+ if (j < 0) {
1088
+ return -1;
1089
+ }
1090
+ if (str.slice(j, j + 1) != "?") {
1091
+ return -1;
1092
+ }
1093
+ var j = j + 1;
1094
+ var i = j;
1095
+ if ("0123456789-".indexOf(str.charAt(j)) >= 0) {
1096
+ throw BadSyntax(this._thisDoc, this.lines, str, j, "Varible name can't start with '" + str.charAt(j) + "s'");
1097
+ return -1;
1098
+ }
1099
+ while (i < pyjslib_len(str) && _notNameChars.indexOf(str.charAt(i)) < 0) {
1100
+ var i = i + 1;
1100
1101
  }
1101
- }, {
1102
- key: "skipSpace",
1103
- value: function skipSpace(str, i) {
1104
- /*
1105
- Skip white space, newlines and comments.
1106
- return -1 if EOF, else position of first non-ws character*/
1102
+ if (this._parentContext == null) {
1103
+ throw BadSyntax(this._thisDoc, this.lines, str, j, "Can't use ?xxx syntax for variable in outermost level: " + str.slice(j - 1, i));
1104
+ }
1105
+ res.push(this._store.variable(str.slice(j, i)));
1106
+ return i;
1107
+ }
1108
+ bareWord(str, i, res) {
1109
+ /*
1110
+ abc -> :abc
1111
+ */
1107
1112
 
1108
- var whitespace = " \n\r\t\f\x0B\xA0\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200A\u200B\u2028\u2029\u3000";
1109
- for (var j = i ? i : 0; j < str.length; j++) {
1110
- var ch = str.charAt(j);
1111
- // console.log(" skipspace j= "+j + " i= " + i + " n= " + str.length);
1112
- // console.log(" skipspace ch <" + ch + ">");
1113
- if (whitespace.indexOf(ch) < 0) {
1114
- //not ws
1115
- // console.log(" skipspace 2 ch <" + ch + ">");
1116
- if (str.charAt(j) === '#') {
1117
- for (;; j++) {
1118
- // console.log(" skipspace2 j= "+j + " i= " + i + " n= " + str.length);
1119
- if (j === str.length) {
1120
- return -1; // EOF
1121
- }
1113
+ var j = this.skipSpace(str, i);
1114
+ if (j < 0) {
1115
+ return -1;
1116
+ }
1117
+ var ch = str.charAt(j);
1118
+ if ("0123456789-".indexOf(ch) >= 0) {
1119
+ return -1;
1120
+ }
1121
+ if (_notNameChars.indexOf(ch) >= 0) {
1122
+ return -1;
1123
+ }
1124
+ var i = j;
1125
+ while (i < pyjslib_len(str) && _notNameChars.indexOf(str.charAt(i)) < 0) {
1126
+ var i = i + 1;
1127
+ }
1128
+ res.push(str.slice(j, i));
1129
+ return i;
1130
+ }
1131
+ qname(str, i, res) {
1132
+ /*
1133
+ xyz:def -> ('xyz', 'def')
1134
+ If not in keywords and keywordsSet: def -> ('', 'def')
1135
+ :def -> ('', 'def')
1136
+ */
1122
1137
 
1123
- if (str.charAt(j) === '\n') {
1124
- this.lines = this.lines + 1;
1125
- break;
1126
- }
1127
- }
1128
- ;
1129
- } else {
1130
- // Not hash - something interesting
1131
- // console.log(" skipspace 3 ch <" + ch + ">");
1132
- return j;
1133
- }
1138
+ var i = this.skipSpace(str, i);
1139
+ if (i < 0) {
1140
+ return -1;
1141
+ }
1142
+ var c = str.charAt(i);
1143
+ if ("0123456789-+".indexOf(c) >= 0) {
1144
+ return -1;
1145
+ }
1146
+ if (_notNameChars.indexOf(c) < 0) {
1147
+ var ln = c;
1148
+ var i = i + 1;
1149
+ while (i < pyjslib_len(str)) {
1150
+ var c = str.charAt(i);
1151
+ if (_notNameChars.indexOf(c) < 0) {
1152
+ var ln = ln + c;
1153
+ var i = i + 1;
1134
1154
  } else {
1135
- // Whitespace
1136
- // console.log(" skipspace 5 ch <" + ch + ">");
1137
- if (str.charAt(j) === '\n') {
1138
- this.lines = this.lines + 1;
1139
- }
1155
+ break;
1140
1156
  }
1141
- } // next j
1142
- return -1; // EOF
1143
- }
1144
- }, {
1145
- key: "variable",
1146
- value: function variable(str, i, res) {
1147
- /*
1148
- ?abc -> variable(:abc)
1149
- */
1150
-
1151
- var j = this.skipSpace(str, i);
1152
- if (j < 0) {
1153
- return -1;
1154
1157
  }
1155
- if (str.slice(j, j + 1) != "?") {
1156
- return -1;
1157
- }
1158
- var j = j + 1;
1159
- var i = j;
1160
- if ("0123456789-".indexOf(str.charAt(j)) >= 0) {
1161
- throw BadSyntax(this._thisDoc, this.lines, str, j, "Varible name can't start with '" + str.charAt(j) + "s'");
1162
- return -1;
1163
- }
1164
- while (i < pyjslib_len(str) && _notNameChars.indexOf(str.charAt(i)) < 0) {
1165
- var i = i + 1;
1166
- }
1167
- if (this._parentContext == null) {
1168
- throw BadSyntax(this._thisDoc, this.lines, str, j, "Can't use ?xxx syntax for variable in outermost level: " + str.slice(j - 1, i));
1158
+ } else {
1159
+ var ln = "";
1160
+ }
1161
+ if (i < pyjslib_len(str) && str.charAt(i) == ":") {
1162
+ var pfx = ln;
1163
+ var i = i + 1;
1164
+ var ln = "";
1165
+ while (i < pyjslib_len(str)) {
1166
+ var c = str.charAt(i);
1167
+ if (_notNameChars.indexOf(c) < 0) {
1168
+ var ln = ln + c;
1169
+ var i = i + 1;
1170
+ } else {
1171
+ break;
1172
+ }
1169
1173
  }
1170
- res.push(this._store.variable(str.slice(j, i)));
1174
+ res.push(new pyjslib_Tuple([pfx, ln]));
1171
1175
  return i;
1176
+ } else {
1177
+ if (ln && this.keywordsSet && ArrayIndexOf(this.keywords, ln) < 0) {
1178
+ res.push(new pyjslib_Tuple(["", ln]));
1179
+ return i;
1180
+ }
1181
+ return -1;
1172
1182
  }
1173
- }, {
1174
- key: "bareWord",
1175
- value: function bareWord(str, i, res) {
1176
- /*
1177
- abc -> :abc
1178
- */
1179
-
1183
+ }
1184
+ object(str, i, res) {
1185
+ var j = this.subject(str, i, res);
1186
+ if (j >= 0) {
1187
+ return j;
1188
+ } else {
1180
1189
  var j = this.skipSpace(str, i);
1181
1190
  if (j < 0) {
1182
1191
  return -1;
1192
+ } else {
1193
+ var i = j;
1183
1194
  }
1184
- var ch = str.charAt(j);
1185
- if ("0123456789-".indexOf(ch) >= 0) {
1186
- return -1;
1187
- }
1188
- if (_notNameChars.indexOf(ch) >= 0) {
1195
+ var delim = null;
1196
+ let ch = str.charAt(i);
1197
+ if (ch == "\"" || ch == "'") {
1198
+ if (str.slice(i, i + 3 == ch + ch)) {
1199
+ delim = ch + ch + ch;
1200
+ } else {
1201
+ delim = ch;
1202
+ }
1203
+ var i = i + pyjslib_len(delim);
1204
+ var pairFudge = this.strconst(str, i, delim);
1205
+ var j = pairFudge[0];
1206
+ var s = pairFudge[1];
1207
+ res.push(this._store.literal(s));
1208
+ diag_progress("New string const ", s, j);
1209
+ return j;
1210
+ } else {
1189
1211
  return -1;
1190
1212
  }
1191
- var i = j;
1192
- while (i < pyjslib_len(str) && _notNameChars.indexOf(str.charAt(i)) < 0) {
1193
- var i = i + 1;
1194
- }
1195
- res.push(str.slice(j, i));
1196
- return i;
1197
1213
  }
1198
- }, {
1199
- key: "qname",
1200
- value: function qname(str, i, res) {
1201
- /*
1202
- xyz:def -> ('xyz', 'def')
1203
- If not in keywords and keywordsSet: def -> ('', 'def')
1204
- :def -> ('', 'def')
1205
- */
1206
-
1207
- var i = this.skipSpace(str, i);
1208
- if (i < 0) {
1209
- return -1;
1210
- }
1211
- var c = str.charAt(i);
1212
- if ("0123456789-+".indexOf(c) >= 0) {
1214
+ }
1215
+ nodeOrLiteral(str, i, res) {
1216
+ var j = this.node(str, i, res);
1217
+ if (j >= 0) {
1218
+ return j;
1219
+ } else {
1220
+ var j = this.skipSpace(str, i);
1221
+ if (j < 0) {
1213
1222
  return -1;
1214
- }
1215
- if (_notNameChars.indexOf(c) < 0) {
1216
- var ln = c;
1217
- var i = i + 1;
1218
- while (i < pyjslib_len(str)) {
1219
- var c = str.charAt(i);
1220
- if (_notNameChars.indexOf(c) < 0) {
1221
- var ln = ln + c;
1222
- var i = i + 1;
1223
- } else {
1224
- break;
1225
- }
1226
- }
1227
1223
  } else {
1228
- var ln = "";
1224
+ var i = j;
1229
1225
  }
1230
- if (i < pyjslib_len(str) && str.charAt(i) == ":") {
1231
- var pfx = ln;
1232
- var i = i + 1;
1233
- var ln = "";
1234
- while (i < pyjslib_len(str)) {
1235
- var c = str.charAt(i);
1236
- if (_notNameChars.indexOf(c) < 0) {
1237
- var ln = ln + c;
1238
- var i = i + 1;
1226
+ var ch = str.charAt(i);
1227
+ if ("-+0987654321".indexOf(ch) >= 0) {
1228
+ datetime_syntax.lastIndex = 0;
1229
+ var m = datetime_syntax.exec(str.slice(i));
1230
+ if (m != null) {
1231
+ // j = ( i + datetime_syntax.lastIndex ) ;
1232
+ var val = m[0];
1233
+ j = i + val.length;
1234
+ if (val.indexOf("T") >= 0) {
1235
+ res.push(this._store.literal(val, this._store.sym(DATETIME_DATATYPE)));
1239
1236
  } else {
1240
- break;
1237
+ res.push(this._store.literal(val, this._store.sym(DATE_DATATYPE)));
1241
1238
  }
1242
- }
1243
- res.push(new pyjslib_Tuple([pfx, ln]));
1244
- return i;
1245
- } else {
1246
- if (ln && this.keywordsSet && ArrayIndexOf(this.keywords, ln) < 0) {
1247
- res.push(new pyjslib_Tuple(["", ln]));
1248
- return i;
1249
- }
1250
- return -1;
1251
- }
1252
- }
1253
- }, {
1254
- key: "object",
1255
- value: function object(str, i, res) {
1256
- var j = this.subject(str, i, res);
1257
- if (j >= 0) {
1258
- return j;
1259
- } else {
1260
- var j = this.skipSpace(str, i);
1261
- if (j < 0) {
1262
- return -1;
1263
1239
  } else {
1264
- var i = j;
1265
- }
1266
- var delim = null;
1267
- var ch = str.charAt(i);
1268
- if (ch == "\"" || ch == "'") {
1269
- if (str.slice(i, i + 3 == ch + ch)) {
1270
- delim = ch + ch + ch;
1240
+ number_syntax.lastIndex = 0;
1241
+ var m = number_syntax.exec(str.slice(i));
1242
+ if (m == null) {
1243
+ throw BadSyntax(this._thisDoc, this.lines, str, i, "Bad number or date syntax");
1244
+ }
1245
+ j = i + number_syntax.lastIndex;
1246
+ var val = str.slice(i, j);
1247
+ if (val.indexOf("e") >= 0) {
1248
+ res.push(this._store.literal(parseFloat(val), this._store.sym(FLOAT_DATATYPE)));
1249
+ } else if (str.slice(i, j).indexOf(".") >= 0) {
1250
+ res.push(this._store.literal(parseFloat(val), this._store.sym(DECIMAL_DATATYPE)));
1271
1251
  } else {
1272
- delim = ch;
1252
+ res.push(this._store.literal(parseInt(val), this._store.sym(INTEGER_DATATYPE)));
1273
1253
  }
1274
- var i = i + pyjslib_len(delim);
1275
- var pairFudge = this.strconst(str, i, delim);
1276
- var j = pairFudge[0];
1277
- var s = pairFudge[1];
1278
- res.push(this._store.literal(s));
1279
- diag_progress("New string const ", s, j);
1280
- return j;
1281
- } else {
1282
- return -1;
1283
1254
  }
1255
+ ;
1256
+ return j; // Where we have got up to
1284
1257
  }
1285
- }
1286
- }, {
1287
- key: "nodeOrLiteral",
1288
- value: function nodeOrLiteral(str, i, res) {
1289
- var j = this.node(str, i, res);
1290
- if (j >= 0) {
1291
- return j;
1292
- } else {
1293
- var j = this.skipSpace(str, i);
1294
- if (j < 0) {
1295
- return -1;
1258
+ if (str.charAt(i) == "\"") {
1259
+ if (str.slice(i, i + 3) == "\"\"\"") {
1260
+ var delim = "\"\"\"";
1296
1261
  } else {
1297
- var i = j;
1298
- }
1299
- var ch = str.charAt(i);
1300
- if ("-+0987654321".indexOf(ch) >= 0) {
1301
- datetime_syntax.lastIndex = 0;
1302
- var m = datetime_syntax.exec(str.slice(i));
1303
- if (m != null) {
1304
- // j = ( i + datetime_syntax.lastIndex ) ;
1305
- var val = m[0];
1306
- j = i + val.length;
1307
- if (val.indexOf("T") >= 0) {
1308
- res.push(this._store.literal(val, this._store.sym(DATETIME_DATATYPE)));
1309
- } else {
1310
- res.push(this._store.literal(val, this._store.sym(DATE_DATATYPE)));
1311
- }
1312
- } else {
1313
- number_syntax.lastIndex = 0;
1314
- var m = number_syntax.exec(str.slice(i));
1315
- if (m == null) {
1316
- throw BadSyntax(this._thisDoc, this.lines, str, i, "Bad number or date syntax");
1317
- }
1318
- j = i + number_syntax.lastIndex;
1319
- var val = str.slice(i, j);
1320
- if (val.indexOf("e") >= 0) {
1321
- res.push(this._store.literal(parseFloat(val), this._store.sym(FLOAT_DATATYPE)));
1322
- } else if (str.slice(i, j).indexOf(".") >= 0) {
1323
- res.push(this._store.literal(parseFloat(val), this._store.sym(DECIMAL_DATATYPE)));
1324
- } else {
1325
- res.push(this._store.literal(parseInt(val), this._store.sym(INTEGER_DATATYPE)));
1326
- }
1262
+ var delim = "\"";
1263
+ }
1264
+ var i = i + pyjslib_len(delim);
1265
+ var dt = null;
1266
+ var pairFudge = this.strconst(str, i, delim);
1267
+ var j = pairFudge[0];
1268
+ var s = pairFudge[1];
1269
+ var lang = null;
1270
+ if (str.slice(j, j + 1) == "@") {
1271
+ langcode.lastIndex = 0;
1272
+ var m = langcode.exec(str.slice(j + 1));
1273
+ if (m == null) {
1274
+ throw BadSyntax(this._thisDoc, startline, str, i, "Bad language code syntax on string literal, after @");
1327
1275
  }
1328
- ;
1329
- return j; // Where we have got up to
1276
+ var i = langcode.lastIndex + j + 1;
1277
+ var lang = str.slice(j + 1, i);
1278
+ var j = i;
1330
1279
  }
1331
-
1332
- if (str.charAt(i) == "\"") {
1333
- if (str.slice(i, i + 3) == "\"\"\"") {
1334
- var delim = "\"\"\"";
1335
- } else {
1336
- var delim = "\"";
1337
- }
1338
- var i = i + pyjslib_len(delim);
1339
- var dt = null;
1340
- var pairFudge = this.strconst(str, i, delim);
1341
- var j = pairFudge[0];
1342
- var s = pairFudge[1];
1343
- var lang = null;
1344
- if (str.slice(j, j + 1) == "@") {
1345
- langcode.lastIndex = 0;
1346
- var m = langcode.exec(str.slice(j + 1));
1347
- if (m == null) {
1348
- throw BadSyntax(this._thisDoc, startline, str, i, "Bad language code syntax on string literal, after @");
1349
- }
1350
- var i = langcode.lastIndex + j + 1;
1351
- var lang = str.slice(j + 1, i);
1352
- var j = i;
1353
- }
1354
- if (str.slice(j, j + 2) == "^^") {
1355
- var res2 = new pyjslib_List([]);
1356
- var j = this.uri_ref2(str, j + 2, res2);
1357
- var dt = res2[0];
1358
- }
1359
- res.push(this._store.literal(s, lang || dt));
1360
- return j;
1361
- } else {
1362
- return -1;
1280
+ if (str.slice(j, j + 2) == "^^") {
1281
+ var res2 = new pyjslib_List([]);
1282
+ var j = this.uri_ref2(str, j + 2, res2);
1283
+ var dt = res2[0];
1363
1284
  }
1285
+ res.push(this._store.literal(s, lang || dt));
1286
+ return j;
1287
+ } else {
1288
+ return -1;
1364
1289
  }
1365
1290
  }
1366
- }, {
1367
- key: "strconst",
1368
- value: function strconst(str, i, delim) {
1369
- /*
1370
- parse an N3 string constant delimited by delim.
1371
- return index, val
1372
- */
1291
+ }
1292
+ strconst(str, i, delim) {
1293
+ /*
1294
+ parse an N3 string constant delimited by delim.
1295
+ return index, val
1296
+ */
1373
1297
 
1374
- var j = i;
1375
- var ustr = "";
1376
- var startline = this.lines;
1377
- while (j < pyjslib_len(str)) {
1378
- var i = j + pyjslib_len(delim);
1379
- if (str.slice(j, i) == delim) {
1380
- return new pyjslib_Tuple([i, ustr]);
1381
- }
1382
- if (str.charAt(j) == "\"") {
1383
- var ustr = ustr + "\"";
1384
- var j = j + 1;
1385
- continue;
1298
+ var j = i;
1299
+ var ustr = "";
1300
+ var startline = this.lines;
1301
+ while (j < pyjslib_len(str)) {
1302
+ var i = j + pyjslib_len(delim);
1303
+ if (str.slice(j, i) == delim) {
1304
+ return new pyjslib_Tuple([i, ustr]);
1305
+ }
1306
+ if (str.charAt(j) == "\"") {
1307
+ var ustr = ustr + "\"";
1308
+ var j = j + 1;
1309
+ continue;
1310
+ }
1311
+ interesting.lastIndex = 0;
1312
+ var m = interesting.exec(str.slice(j));
1313
+ if (!m) {
1314
+ throw BadSyntax(this._thisDoc, startline, str, j, "Closing quote missing in string at ^ in " + str.slice(j - 20, j) + "^" + str.slice(j, j + 20));
1315
+ }
1316
+ var i = j + interesting.lastIndex - 1;
1317
+ var ustr = ustr + str.slice(j, i);
1318
+ var ch = str.charAt(i);
1319
+ if (ch == "\"") {
1320
+ var j = i;
1321
+ continue;
1322
+ } else if (ch == "\r") {
1323
+ var j = i + 1;
1324
+ continue;
1325
+ } else if (ch == "\n") {
1326
+ if (delim == "\"") {
1327
+ throw BadSyntax(this._thisDoc, startline, str, i, "newline found in string literal");
1386
1328
  }
1387
- interesting.lastIndex = 0;
1388
- var m = interesting.exec(str.slice(j));
1389
- if (!m) {
1390
- throw BadSyntax(this._thisDoc, startline, str, j, "Closing quote missing in string at ^ in " + str.slice(j - 20, j) + "^" + str.slice(j, j + 20));
1329
+ this.lines = this.lines + 1;
1330
+ var ustr = ustr + ch;
1331
+ var j = i + 1;
1332
+ this.previousLine = this.startOfLine;
1333
+ this.startOfLine = j;
1334
+ } else if (ch == "\\") {
1335
+ var j = i + 1;
1336
+ var ch = str.slice(j, j + 1);
1337
+ if (!ch) {
1338
+ throw BadSyntax(this._thisDoc, startline, str, i, "unterminated string literal (2)");
1391
1339
  }
1392
- var i = j + interesting.lastIndex - 1;
1393
- var ustr = ustr + str.slice(j, i);
1394
- var ch = str.charAt(i);
1395
- if (ch == "\"") {
1396
- var j = i;
1397
- continue;
1398
- } else if (ch == "\r") {
1399
- var j = i + 1;
1400
- continue;
1401
- } else if (ch == "\n") {
1402
- if (delim == "\"") {
1403
- throw BadSyntax(this._thisDoc, startline, str, i, "newline found in string literal");
1404
- }
1405
- this.lines = this.lines + 1;
1340
+ var k = string_find("abfrtvn\\\"", ch);
1341
+ if (k >= 0) {
1342
+ var uch = "\a\b\f\r\t\v\n\\\"".charAt(k);
1343
+ var ustr = ustr + uch;
1344
+ var j = j + 1;
1345
+ } else if (ch == "u") {
1346
+ var pairFudge = this.uEscape(str, j + 1, startline);
1347
+ var j = pairFudge[0];
1348
+ var ch = pairFudge[1];
1406
1349
  var ustr = ustr + ch;
1407
- var j = i + 1;
1408
- this.previousLine = this.startOfLine;
1409
- this.startOfLine = j;
1410
- } else if (ch == "\\") {
1411
- var j = i + 1;
1412
- var ch = str.slice(j, j + 1);
1413
- if (!ch) {
1414
- throw BadSyntax(this._thisDoc, startline, str, i, "unterminated string literal (2)");
1415
- }
1416
- var k = string_find("abfrtvn\\\"", ch);
1417
- if (k >= 0) {
1418
- var uch = "\a\b\f\r\t\v\n\\\"".charAt(k);
1419
- var ustr = ustr + uch;
1420
- var j = j + 1;
1421
- } else if (ch == "u") {
1422
- var pairFudge = this.uEscape(str, j + 1, startline);
1423
- var j = pairFudge[0];
1424
- var ch = pairFudge[1];
1425
- var ustr = ustr + ch;
1426
- } else if (ch == "U") {
1427
- var pairFudge = this.UEscape(str, j + 1, startline);
1428
- var j = pairFudge[0];
1429
- var ch = pairFudge[1];
1430
- var ustr = ustr + ch;
1431
- } else {
1432
- throw BadSyntax(this._thisDoc, this.lines, str, i, "bad escape");
1433
- }
1350
+ } else if (ch == "U") {
1351
+ var pairFudge = this.UEscape(str, j + 1, startline);
1352
+ var j = pairFudge[0];
1353
+ var ch = pairFudge[1];
1354
+ var ustr = ustr + ch;
1355
+ } else {
1356
+ throw BadSyntax(this._thisDoc, this.lines, str, i, "bad escape");
1434
1357
  }
1435
1358
  }
1436
- throw BadSyntax(this._thisDoc, this.lines, str, i, "unterminated string literal");
1437
- }
1438
- }, {
1439
- key: "uEscape",
1440
- value: function uEscape(str, i, startline) {
1441
- var j = i;
1442
- var count = 0;
1443
- var value = 0;
1444
- while (count < 4) {
1445
- var chFudge = str.slice(j, j + 1);
1446
- var ch = chFudge.toLowerCase();
1447
- var j = j + 1;
1448
- if (ch == "") {
1449
- throw BadSyntax(this._thisDoc, startline, str, i, "unterminated string literal(3)");
1450
- }
1451
- var k = string_find("0123456789abcdef", ch);
1452
- if (k < 0) {
1453
- throw BadSyntax(this._thisDoc, startline, str, i, "bad string literal hex escape");
1454
- }
1455
- var value = value * 16 + k;
1456
- var count = count + 1;
1457
- }
1458
- var uch = String.fromCharCode(value);
1459
- return new pyjslib_Tuple([j, uch]);
1460
- }
1461
- }, {
1462
- key: "UEscape",
1463
- value: function UEscape(str, i, startline) {
1464
- var j = i;
1465
- var count = 0;
1466
- var value = "\\U";
1467
- while (count < 8) {
1468
- var chFudge = str.slice(j, j + 1);
1469
- var ch = chFudge.toLowerCase();
1470
- var j = j + 1;
1471
- if (ch == "") {
1472
- throw BadSyntax(this._thisDoc, startline, str, i, "unterminated string literal(3)");
1473
- }
1474
- var k = string_find("0123456789abcdef", ch);
1475
- if (k < 0) {
1476
- throw BadSyntax(this._thisDoc, startline, str, i, "bad string literal hex escape");
1477
- }
1478
- var value = value + ch;
1479
- var count = count + 1;
1359
+ }
1360
+ throw BadSyntax(this._thisDoc, this.lines, str, i, "unterminated string literal");
1361
+ }
1362
+ uEscape(str, i, startline) {
1363
+ var j = i;
1364
+ var count = 0;
1365
+ var value = 0;
1366
+ while (count < 4) {
1367
+ var chFudge = str.slice(j, j + 1);
1368
+ var ch = chFudge.toLowerCase();
1369
+ var j = j + 1;
1370
+ if (ch == "") {
1371
+ throw BadSyntax(this._thisDoc, startline, str, i, "unterminated string literal(3)");
1480
1372
  }
1481
- var uch = stringFromCharCode("0x" + pyjslib_slice(value, 2, 10) - 0);
1482
- return new pyjslib_Tuple([j, uch]);
1373
+ var k = string_find("0123456789abcdef", ch);
1374
+ if (k < 0) {
1375
+ throw BadSyntax(this._thisDoc, startline, str, i, "bad string literal hex escape");
1376
+ }
1377
+ var value = value * 16 + k;
1378
+ var count = count + 1;
1483
1379
  }
1484
- }]);
1485
- return SinkParser;
1486
- }();
1380
+ var uch = String.fromCharCode(value);
1381
+ return new pyjslib_Tuple([j, uch]);
1382
+ }
1383
+ UEscape(str, i, startline) {
1384
+ var j = i;
1385
+ var count = 0;
1386
+ var value = "\\U";
1387
+ while (count < 8) {
1388
+ var chFudge = str.slice(j, j + 1);
1389
+ var ch = chFudge.toLowerCase();
1390
+ var j = j + 1;
1391
+ if (ch == "") {
1392
+ throw BadSyntax(this._thisDoc, startline, str, i, "unterminated string literal(3)");
1393
+ }
1394
+ var k = string_find("0123456789abcdef", ch);
1395
+ if (k < 0) {
1396
+ throw BadSyntax(this._thisDoc, startline, str, i, "bad string literal hex escape");
1397
+ }
1398
+ var value = value + ch;
1399
+ var count = count + 1;
1400
+ }
1401
+ var uch = stringFromCharCode("0x" + pyjslib_slice(value, 2, 10) - 0);
1402
+ return new pyjslib_Tuple([j, uch]);
1403
+ }
1404
+ }
1487
1405
  function OLD_BadSyntax(uri, lines, str, i, why) {
1488
1406
  return new __OLD_BadSyntax(uri, lines, str, i, why);
1489
1407
  }
@@ -1513,9 +1431,9 @@ __OLD_BadSyntax.prototype.toString = function () {
1513
1431
  return "Line %i of <%s>: Bad syntax (%s) at ^ in:\n\"%s%s^%s%s\"" % new pyjslib_Tuple([this.lines + 1, this._uri, this._why, pre, str.slice(st, i), str.slice(i, i + 60), post]);
1514
1432
  };
1515
1433
  function BadSyntax(uri, lines, str, i, why) {
1516
- var lineNo = lines + 1;
1517
- var msg = "Line " + lineNo + " of <" + uri + ">: Bad syntax: " + why + "\nat: \"" + str.slice(i, i + 30) + "\"";
1518
- var e = new SyntaxError(msg, uri, lineNo);
1434
+ let lineNo = lines + 1;
1435
+ let msg = "Line " + lineNo + " of <" + uri + ">: Bad syntax: " + why + "\nat: \"" + str.slice(i, i + 30) + "\"";
1436
+ let e = new SyntaxError(msg, uri, lineNo);
1519
1437
  e.lineNo = lineNo;
1520
1438
  e.characterInFile = i;
1521
1439
  e.syntaxProblem = why;