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.
- package/dist/rdflib.min.js +1 -1
- package/dist/rdflib.min.js.LICENSE.txt +0 -2
- package/dist/rdflib.min.js.map +1 -1
- package/esm/blank-node.js +57 -82
- package/esm/class-order.js +1 -1
- package/esm/collection.js +70 -103
- package/esm/default-graph.js +13 -30
- package/esm/empty.js +8 -23
- package/esm/factories/canonical-data-factory.js +33 -29
- package/esm/factories/extended-term-factory.js +18 -13
- package/esm/factories/factory-types.js +1 -1
- package/esm/factories/rdflib-data-factory.js +9 -11
- package/esm/fetcher.js +1366 -1651
- package/esm/formula.js +631 -736
- package/esm/index.js +31 -48
- package/esm/jsonldparser.js +19 -26
- package/esm/jsonparser.js +1 -1
- package/esm/lists.js +38 -86
- package/esm/literal.js +120 -154
- package/esm/log.js +7 -7
- package/esm/n3parser.js +1009 -1086
- package/esm/named-node.js +69 -96
- package/esm/namespace.js +2 -4
- package/esm/node-internal.js +73 -96
- package/esm/node.js +1 -1
- package/esm/parse.js +3 -3
- package/esm/patch-parser.js +1 -1
- package/esm/query.js +15 -16
- package/esm/rdfaparser.js +775 -841
- package/esm/rdfxmlparser.js +348 -364
- package/esm/serialize.js +2 -2
- package/esm/serializer.js +835 -877
- package/esm/statement.js +52 -71
- package/esm/store.js +853 -957
- package/esm/types.js +21 -21
- package/esm/update-manager.js +965 -1100
- package/esm/updates-via.js +104 -132
- package/esm/uri.js +3 -3
- package/esm/utils/default-graph-uri.js +2 -2
- package/esm/utils/terms.js +4 -5
- package/esm/utils-js.js +5 -5
- package/esm/utils.js +6 -6
- package/esm/variable.js +32 -55
- package/esm/xsd.js +2 -2
- package/lib/blank-node.js +57 -80
- package/lib/class-order.js +1 -1
- package/lib/collection.js +70 -101
- package/lib/default-graph.js +14 -29
- package/lib/empty.js +9 -22
- package/lib/factories/canonical-data-factory.js +35 -31
- package/lib/factories/extended-term-factory.js +18 -13
- package/lib/factories/factory-types.js +1 -1
- package/lib/factories/rdflib-data-factory.js +9 -11
- package/lib/fetcher.js +1375 -1654
- package/lib/formula.js +632 -735
- package/lib/index.js +80 -84
- package/lib/jsonldparser.js +21 -32
- package/lib/jsonparser.js +1 -1
- package/lib/lists.js +47 -87
- package/lib/literal.js +121 -153
- package/lib/log.js +7 -7
- package/lib/n3parser.js +1012 -1090
- package/lib/named-node.js +70 -95
- package/lib/namespace.js +2 -4
- package/lib/node-internal.js +73 -94
- package/lib/node.js +1 -1
- package/lib/parse.js +5 -6
- package/lib/patch-parser.js +1 -1
- package/lib/query.js +20 -18
- package/lib/rdfaparser.js +778 -843
- package/lib/rdfxmlparser.js +351 -365
- package/lib/serialize.js +2 -2
- package/lib/serializer.js +840 -880
- package/lib/statement.js +55 -73
- package/lib/store.js +860 -958
- package/lib/types.js +21 -21
- package/lib/update-manager.js +970 -1102
- package/lib/updates-via.js +107 -132
- package/lib/uri.js +3 -3
- package/lib/utils/default-graph-uri.js +2 -2
- package/lib/utils/terms.js +4 -6
- package/lib/utils-js.js +8 -9
- package/lib/utils.js +6 -6
- package/lib/variable.js +35 -57
- package/lib/xsd.js +2 -2
- package/package.json +2 -2
- package/src/n3parser.js +1 -1
- package/src/serializer.js +1 -1
- package/src/update-manager.ts +2 -1
- 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
|
|
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
|
|
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
|
|
62
|
+
var pyjslib_Tuple = function (theList) {
|
|
66
63
|
return theList;
|
|
67
64
|
};
|
|
68
|
-
var pyjslib_List = function
|
|
65
|
+
var pyjslib_List = function (theList) {
|
|
69
66
|
return theList;
|
|
70
67
|
};
|
|
71
|
-
var pyjslib_Dict = function
|
|
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
|
|
72
|
+
var pyjslib_len = function (s) {
|
|
76
73
|
return s.length;
|
|
77
74
|
};
|
|
78
|
-
var pyjslib_slice = function
|
|
79
|
-
if (typeof str.slice == 'undefined') throw '@@ mising.js: No .slice function for ' + str + ' of type ' +
|
|
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
|
|
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
|
|
90
|
+
var ord = function (str) {
|
|
94
91
|
return str.charCodeAt(0);
|
|
95
92
|
};
|
|
96
|
-
var string_find = function
|
|
93
|
+
var string_find = function (str, s) {
|
|
97
94
|
return str.indexOf(s);
|
|
98
95
|
};
|
|
99
|
-
var assertFudge = function
|
|
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
|
|
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
|
|
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
|
|
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]+)?(
|
|
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
|
|
197
|
-
|
|
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
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
}
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
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
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
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
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
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
|
-
|
|
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
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
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
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
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
|
-
|
|
367
|
-
if (
|
|
368
|
-
|
|
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
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
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
|
-
|
|
398
|
-
|
|
399
|
-
|
|
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
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
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
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
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
|
-
|
|
448
|
-
if (
|
|
449
|
-
|
|
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
|
-
|
|
468
|
-
|
|
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
|
-
|
|
403
|
+
throw BadSyntax(this._thisDoc, this.lines, str, j, "expected qname after @prefix");
|
|
507
404
|
}
|
|
508
|
-
var j = this.
|
|
405
|
+
var j = this.uri_ref2(str, i, t);
|
|
509
406
|
if (j < 0) {
|
|
510
|
-
throw BadSyntax(this._thisDoc, this.lines, str, i, "expected
|
|
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
|
-
|
|
516
|
-
|
|
517
|
-
|
|
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
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
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
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
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
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
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
|
-
|
|
571
|
-
|
|
572
|
-
|
|
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
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
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
|
-
|
|
583
|
-
|
|
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
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
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
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
}
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
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
|
-
|
|
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
|
-
|
|
590
|
+
throw BadSyntax(this._thisDoc, this.lines, str, j, "EOF found in middle of path syntax");
|
|
621
591
|
}
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
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
|
-
|
|
598
|
+
res.push(obj);
|
|
645
599
|
}
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
600
|
+
return j;
|
|
601
|
+
}
|
|
602
|
+
anonymousNode(ln) {
|
|
603
|
+
/*
|
|
604
|
+
Remember or generate a term for one of these _: anonymous nodes*/
|
|
651
605
|
|
|
652
|
-
|
|
653
|
-
|
|
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
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
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
|
-
|
|
672
|
-
|
|
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
|
-
|
|
634
|
+
throw BadSyntax(this._thisDoc, this.lines, str, i, "EOF after '['");
|
|
675
635
|
}
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
var
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
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
|
-
|
|
704
|
-
|
|
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
|
-
|
|
764
|
-
|
|
765
|
-
|
|
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
|
-
|
|
780
|
-
|
|
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
|
-
|
|
795
|
-
this.
|
|
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 (
|
|
805
|
-
var
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
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 '
|
|
693
|
+
throw BadSyntax(this._thisDoc, this.lines, str, i, "needed '$}', found end.");
|
|
817
694
|
}
|
|
818
|
-
if (str.slice(i, i +
|
|
819
|
-
var j = i +
|
|
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
|
|
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(
|
|
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
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
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
|
-
|
|
871
|
-
|
|
872
|
-
var
|
|
873
|
-
|
|
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, "
|
|
743
|
+
throw BadSyntax(this._thisDoc, this.lines, str, i, "expected statement or '}'");
|
|
876
744
|
}
|
|
877
|
-
var i = j;
|
|
878
|
-
continue;
|
|
879
745
|
}
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
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,
|
|
768
|
+
throw BadSyntax(this._thisDoc, this.lines, str, i, "needed ')', found end.");
|
|
890
769
|
}
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
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
|
|
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,
|
|
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
|
-
|
|
779
|
+
mylist.push(item[0]);
|
|
918
780
|
}
|
|
781
|
+
res.push(thing_type(mylist, this._context));
|
|
782
|
+
return j;
|
|
919
783
|
}
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
return
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
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
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
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
|
-
|
|
947
|
-
var
|
|
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
|
-
|
|
825
|
+
throw BadSyntax(this._thisDoc, this.lines, str, i, "bad {} or () or [] node after :- ");
|
|
950
826
|
}
|
|
951
|
-
var
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
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
|
-
|
|
959
|
-
|
|
960
|
-
|
|
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
|
-
|
|
971
|
-
|
|
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
|
-
|
|
977
|
-
|
|
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
|
-
|
|
999
|
-
|
|
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 (
|
|
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
|
-
|
|
1008
|
-
|
|
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
|
-
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
|
|
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
|
-
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
|
|
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
|
|
1048
|
-
if (
|
|
1049
|
-
|
|
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
|
-
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
|
|
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
|
-
|
|
1062
|
-
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
|
|
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
|
-
|
|
1074
|
-
|
|
1075
|
-
|
|
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
|
-
|
|
1082
|
-
}
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
|
|
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
|
-
|
|
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
|
-
|
|
1101
|
-
|
|
1102
|
-
|
|
1103
|
-
|
|
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
|
+
*/
|
|
1105
1112
|
|
|
1106
|
-
|
|
1107
|
-
|
|
1108
|
-
|
|
1109
|
-
|
|
1110
|
-
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
|
|
1118
|
-
|
|
1119
|
-
|
|
1120
|
-
|
|
1121
|
-
|
|
1122
|
-
|
|
1123
|
-
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
|
-
|
|
1128
|
-
|
|
1129
|
-
|
|
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
|
-
|
|
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
|
-
|
|
1153
|
-
|
|
1154
|
-
|
|
1155
|
-
|
|
1156
|
-
var
|
|
1157
|
-
|
|
1158
|
-
|
|
1159
|
-
|
|
1160
|
-
|
|
1161
|
-
|
|
1162
|
-
|
|
1163
|
-
|
|
1164
|
-
|
|
1165
|
-
|
|
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(
|
|
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
|
-
|
|
1172
|
-
|
|
1173
|
-
|
|
1174
|
-
|
|
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
|
|
1182
|
-
|
|
1183
|
-
|
|
1184
|
-
|
|
1185
|
-
|
|
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
|
-
|
|
1197
|
-
|
|
1198
|
-
|
|
1199
|
-
|
|
1200
|
-
|
|
1201
|
-
|
|
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
|
|
1224
|
+
var i = j;
|
|
1226
1225
|
}
|
|
1227
|
-
|
|
1228
|
-
|
|
1229
|
-
|
|
1230
|
-
var
|
|
1231
|
-
|
|
1232
|
-
|
|
1233
|
-
|
|
1234
|
-
|
|
1235
|
-
|
|
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
|
-
|
|
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
|
-
|
|
1262
|
-
|
|
1263
|
-
|
|
1264
|
-
|
|
1265
|
-
|
|
1266
|
-
|
|
1267
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
|
1295
|
-
}
|
|
1296
|
-
var
|
|
1297
|
-
|
|
1298
|
-
|
|
1299
|
-
|
|
1300
|
-
|
|
1301
|
-
|
|
1302
|
-
|
|
1303
|
-
|
|
1304
|
-
|
|
1305
|
-
|
|
1306
|
-
|
|
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
|
-
|
|
1276
|
+
var i = langcode.lastIndex + j + 1;
|
|
1277
|
+
var lang = str.slice(j + 1, i);
|
|
1278
|
+
var j = i;
|
|
1327
1279
|
}
|
|
1328
|
-
if (str.
|
|
1329
|
-
|
|
1330
|
-
|
|
1331
|
-
|
|
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
|
-
|
|
1364
|
-
|
|
1365
|
-
|
|
1366
|
-
|
|
1367
|
-
|
|
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
|
-
|
|
1371
|
-
|
|
1372
|
-
|
|
1373
|
-
|
|
1374
|
-
|
|
1375
|
-
|
|
1376
|
-
|
|
1377
|
-
|
|
1378
|
-
|
|
1379
|
-
|
|
1380
|
-
|
|
1381
|
-
|
|
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
|
-
|
|
1384
|
-
var
|
|
1385
|
-
|
|
1386
|
-
|
|
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
|
|
1389
|
-
|
|
1390
|
-
|
|
1391
|
-
|
|
1392
|
-
var j =
|
|
1393
|
-
|
|
1394
|
-
|
|
1395
|
-
var j =
|
|
1396
|
-
|
|
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
|
-
|
|
1404
|
-
|
|
1405
|
-
|
|
1406
|
-
|
|
1407
|
-
var
|
|
1408
|
-
|
|
1409
|
-
|
|
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
|
-
|
|
1433
|
-
|
|
1434
|
-
}
|
|
1435
|
-
|
|
1436
|
-
|
|
1437
|
-
|
|
1438
|
-
|
|
1439
|
-
|
|
1440
|
-
|
|
1441
|
-
|
|
1442
|
-
|
|
1443
|
-
|
|
1444
|
-
|
|
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
|
|
1478
|
-
|
|
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
|
-
|
|
1512
|
-
|
|
1513
|
-
|
|
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;
|