rdflib 2.2.35 → 2.2.36

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