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