rdflib 2.2.21 → 2.2.22-04669b23
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 +11 -1
- package/dist/rdflib.min.js.map +1 -1
- package/esm/blank-node.js +61 -114
- package/esm/class-order.js +1 -1
- package/esm/collection.js +70 -128
- package/esm/default-graph.js +14 -48
- package/esm/empty.js +8 -39
- package/esm/factories/canonical-data-factory.js +33 -65
- package/esm/factories/extended-term-factory.js +18 -25
- package/esm/factories/factory-types.js +3 -2
- package/esm/factories/rdflib-data-factory.js +9 -19
- package/esm/fetcher.js +1341 -1854
- package/esm/formula.js +639 -846
- package/esm/index.js +40 -77
- package/esm/jsonldparser.js +34 -50
- package/esm/jsonparser.js +1 -8
- package/esm/lists.js +47 -110
- package/esm/literal.js +120 -189
- package/esm/log.js +7 -7
- package/esm/n3parser.js +1022 -1412
- package/esm/named-node.js +70 -119
- package/esm/namespace.js +2 -5
- package/esm/node-internal.js +73 -110
- package/esm/node.js +2 -7
- package/esm/parse.js +12 -19
- package/esm/patch-parser.js +10 -30
- package/esm/query-to-sparql.js +0 -18
- package/esm/query.js +63 -147
- package/esm/rdfaparser.js +794 -997
- package/esm/rdfxmlparser.js +347 -461
- package/esm/serialize.js +9 -34
- package/esm/serializer.js +842 -1048
- package/esm/sparql-to-query.js +44 -134
- package/esm/statement.js +54 -85
- package/esm/store.js +830 -1103
- package/esm/types.js +22 -21
- package/esm/update-manager.js +869 -1106
- package/esm/updates-via.js +104 -161
- package/esm/uri.js +9 -53
- package/esm/utils/default-graph-uri.js +3 -2
- package/esm/utils/termValue.js +0 -1
- package/esm/utils/terms.js +19 -21
- package/esm/utils-js.js +20 -61
- package/esm/utils.js +10 -21
- package/esm/variable.js +32 -78
- package/esm/xsd.js +2 -2
- package/lib/blank-node.js +60 -113
- package/lib/class-order.js +1 -2
- package/lib/collection.js +69 -131
- package/lib/default-graph.js +13 -52
- package/lib/empty.js +8 -43
- package/lib/factories/canonical-data-factory.js +35 -79
- package/lib/factories/extended-term-factory.js +18 -32
- package/lib/factories/factory-types.d.ts +6 -6
- package/lib/factories/factory-types.js +1 -4
- package/lib/factories/rdflib-data-factory.js +9 -23
- package/lib/fetcher.d.ts +6 -6
- package/lib/fetcher.js +1370 -1843
- package/lib/formula.d.ts +1 -1
- package/lib/formula.js +640 -855
- package/lib/index.d.ts +1 -2
- package/lib/index.js +67 -156
- package/lib/jsonldparser.js +33 -54
- package/lib/jsonparser.js +1 -10
- package/lib/lists.js +55 -112
- package/lib/literal.js +120 -195
- package/lib/log.d.ts +0 -6
- package/lib/log.js +7 -8
- package/lib/n3parser.d.ts +1 -0
- package/lib/n3parser.js +1023 -1422
- package/lib/named-node.js +69 -126
- package/lib/namespace.js +2 -7
- package/lib/node-internal.js +74 -107
- package/lib/node.js +2 -12
- package/lib/parse.d.ts +1 -1
- package/lib/parse.js +12 -32
- package/lib/patch-parser.js +11 -34
- package/lib/query-to-sparql.js +0 -23
- package/lib/query.js +62 -167
- package/lib/rdfaparser.js +796 -1009
- package/lib/rdfxmlparser.js +349 -466
- package/lib/serialize.d.ts +1 -1
- package/lib/serialize.js +9 -44
- package/lib/serializer.d.ts +1 -0
- package/lib/serializer.js +846 -1063
- package/lib/sparql-to-query.js +42 -167
- package/lib/statement.js +55 -91
- package/lib/store.d.ts +2 -2
- package/lib/store.js +850 -1112
- package/lib/tf-types.d.ts +4 -4
- package/lib/types.d.ts +8 -8
- package/lib/types.js +23 -23
- package/lib/update-manager.d.ts +1 -1
- package/lib/update-manager.js +865 -1103
- package/lib/updates-via.js +105 -164
- package/lib/uri.js +8 -61
- package/lib/utils/default-graph-uri.js +3 -5
- package/lib/utils/termValue.js +0 -2
- package/lib/utils/terms.js +19 -40
- package/lib/utils-js.js +23 -88
- package/lib/utils.js +10 -27
- package/lib/variable.js +34 -85
- package/lib/xsd-internal.js +0 -3
- package/lib/xsd.js +2 -6
- package/package.json +40 -39
- package/src/fetcher.ts +2 -2
- package/src/index.ts +0 -2
- package/src/jsonldparser.js +13 -4
- package/src/n3parser.js +12 -4
- package/src/serialize.ts +4 -11
- package/src/serializer.js +24 -0
- package/src/update-manager.ts +12 -7
- package/changes.txt +0 -59
- package/esm/convert.js +0 -61
- package/lib/convert.d.ts +0 -2
- package/lib/convert.js +0 -77
- package/src/convert.js +0 -70
package/lib/n3parser.js
CHANGED
|
@@ -1,48 +1,32 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
|
|
5
|
-
var _typeof3 = require("@babel/runtime/helpers/typeof");
|
|
6
|
-
|
|
7
3
|
Object.defineProperty(exports, "__esModule", {
|
|
8
4
|
value: true
|
|
9
5
|
});
|
|
10
6
|
exports.default = exports.SinkParser = void 0;
|
|
11
|
-
|
|
12
|
-
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
|
|
13
|
-
|
|
14
|
-
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
|
|
15
|
-
|
|
16
|
-
var _typeof2 = _interopRequireDefault(require("@babel/runtime/helpers/typeof"));
|
|
17
|
-
|
|
18
7
|
var Uri = _interopRequireWildcard(require("./uri"));
|
|
19
|
-
|
|
20
8
|
var _utils = require("./utils");
|
|
21
|
-
|
|
22
|
-
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function
|
|
23
|
-
|
|
24
|
-
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof3(obj) !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
25
|
-
|
|
9
|
+
var _lists = require("./lists");
|
|
10
|
+
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
11
|
+
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
26
12
|
/**
|
|
27
13
|
*
|
|
28
14
|
* UTF-8 data encode / decode
|
|
29
15
|
* http://www.webtoolkit.info/
|
|
30
16
|
*
|
|
31
17
|
**/
|
|
18
|
+
|
|
32
19
|
function hexify(str) {
|
|
33
20
|
// also used in parser
|
|
34
21
|
return encodeURI(str);
|
|
35
22
|
}
|
|
36
|
-
|
|
37
23
|
var Utf8 = {
|
|
38
24
|
// public method for url encoding
|
|
39
|
-
encode: function
|
|
25
|
+
encode: function (string) {
|
|
40
26
|
string = string.replace(/\r\n/g, "\n");
|
|
41
27
|
var utftext = "";
|
|
42
|
-
|
|
43
28
|
for (var n = 0; n < string.length; n++) {
|
|
44
29
|
var c = string.charCodeAt(n);
|
|
45
|
-
|
|
46
30
|
if (c < 128) {
|
|
47
31
|
utftext += String.fromCharCode(c);
|
|
48
32
|
} else if (c > 127 && c < 2048) {
|
|
@@ -54,17 +38,14 @@ var Utf8 = {
|
|
|
54
38
|
utftext += String.fromCharCode(c & 63 | 128);
|
|
55
39
|
}
|
|
56
40
|
}
|
|
57
|
-
|
|
58
41
|
return utftext;
|
|
59
42
|
},
|
|
60
43
|
// public method for url decoding
|
|
61
|
-
decode: function
|
|
44
|
+
decode: function (utftext) {
|
|
62
45
|
var string = "";
|
|
63
46
|
var i = 0;
|
|
64
|
-
|
|
65
47
|
while (i < utftext.length) {
|
|
66
48
|
var c = utftext.charCodeAt(i);
|
|
67
|
-
|
|
68
49
|
if (c < 128) {
|
|
69
50
|
string += String.fromCharCode(c);
|
|
70
51
|
i++;
|
|
@@ -76,7 +57,6 @@ var Utf8 = {
|
|
|
76
57
|
i += 3;
|
|
77
58
|
}
|
|
78
59
|
}
|
|
79
|
-
|
|
80
60
|
return string;
|
|
81
61
|
}
|
|
82
62
|
}; // Things we need to define to make converted pythn code work in js
|
|
@@ -84,90 +64,77 @@ var Utf8 = {
|
|
|
84
64
|
|
|
85
65
|
var RDFSink_forSomeSym = "http://www.w3.org/2000/10/swap/log#forSome";
|
|
86
66
|
var RDFSink_forAllSym = "http://www.w3.org/2000/10/swap/log#forAll";
|
|
87
|
-
var Logic_NS = "http://www.w3.org/2000/10/swap/log#";
|
|
67
|
+
var Logic_NS = "http://www.w3.org/2000/10/swap/log#";
|
|
88
68
|
|
|
89
|
-
|
|
69
|
+
// pyjs seems to reference runtime library which I didn't find
|
|
70
|
+
|
|
71
|
+
var pyjslib_Tuple = function (theList) {
|
|
90
72
|
return theList;
|
|
91
73
|
};
|
|
92
|
-
|
|
93
|
-
var pyjslib_List = function pyjslib_List(theList) {
|
|
74
|
+
var pyjslib_List = function (theList) {
|
|
94
75
|
return theList;
|
|
95
76
|
};
|
|
96
|
-
|
|
97
|
-
var pyjslib_Dict = function pyjslib_Dict(listOfPairs) {
|
|
77
|
+
var pyjslib_Dict = function (listOfPairs) {
|
|
98
78
|
if (listOfPairs.length > 0) throw "missing.js: oops nnonempty dict not imp";
|
|
99
79
|
return [];
|
|
100
80
|
};
|
|
101
|
-
|
|
102
|
-
var pyjslib_len = function pyjslib_len(s) {
|
|
81
|
+
var pyjslib_len = function (s) {
|
|
103
82
|
return s.length;
|
|
104
83
|
};
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
if (typeof str.slice == 'undefined') throw '@@ mising.js: No .slice function for ' + str + ' of type ' + (0, _typeof2.default)(str);
|
|
84
|
+
var pyjslib_slice = function (str, i, j) {
|
|
85
|
+
if (typeof str.slice == 'undefined') throw '@@ mising.js: No .slice function for ' + str + ' of type ' + typeof str;
|
|
108
86
|
if (typeof j == 'undefined' || j == null) return str.slice(i);
|
|
109
87
|
return str.slice(i, j); // @ exactly the same spec?
|
|
110
88
|
};
|
|
111
89
|
|
|
112
90
|
var StopIteration = Error('dummy error stop iteration');
|
|
113
|
-
|
|
114
|
-
var pyjslib_Iterator = function pyjslib_Iterator(theList) {
|
|
91
|
+
var pyjslib_Iterator = function (theList) {
|
|
115
92
|
this.last = 0;
|
|
116
93
|
this.li = theList;
|
|
117
|
-
|
|
118
94
|
this.next = function () {
|
|
119
95
|
if (this.last == this.li.length) throw StopIteration;
|
|
120
96
|
return this.li[this.last++];
|
|
121
97
|
};
|
|
122
|
-
|
|
123
98
|
return this;
|
|
124
99
|
};
|
|
125
|
-
|
|
126
|
-
var ord = function ord(str) {
|
|
100
|
+
var ord = function (str) {
|
|
127
101
|
return str.charCodeAt(0);
|
|
128
102
|
};
|
|
129
|
-
|
|
130
|
-
var string_find = function string_find(str, s) {
|
|
103
|
+
var string_find = function (str, s) {
|
|
131
104
|
return str.indexOf(s);
|
|
132
105
|
};
|
|
133
|
-
|
|
134
|
-
var assertFudge = function assertFudge(condition, desc) {
|
|
106
|
+
var assertFudge = function (condition, desc) {
|
|
135
107
|
if (condition) return;
|
|
136
108
|
if (desc) throw "python Assertion failed: " + desc;
|
|
137
109
|
throw "(python) Assertion failed.";
|
|
138
110
|
};
|
|
139
|
-
|
|
140
|
-
var stringFromCharCode = function stringFromCharCode(uesc) {
|
|
111
|
+
var stringFromCharCode = function (uesc) {
|
|
141
112
|
return String.fromCharCode(uesc);
|
|
142
113
|
};
|
|
143
|
-
|
|
144
114
|
String.prototype.encode = function (encoding) {
|
|
145
115
|
if (encoding != 'utf-8') throw "UTF8_converter: can only do utf-8";
|
|
146
116
|
return Utf8.encode(this);
|
|
147
117
|
};
|
|
148
|
-
|
|
149
118
|
String.prototype.decode = function (encoding) {
|
|
150
|
-
if (encoding != 'utf-8') throw "UTF8_converter: can only do utf-8";
|
|
151
|
-
|
|
119
|
+
if (encoding != 'utf-8') throw "UTF8_converter: can only do utf-8";
|
|
120
|
+
//return Utf8.decode(this);
|
|
152
121
|
return this;
|
|
153
122
|
};
|
|
154
|
-
|
|
155
|
-
var uripath_join = function uripath_join(base, given) {
|
|
123
|
+
var uripath_join = function (base, given) {
|
|
156
124
|
return Uri.join(given, base); // sad but true
|
|
157
125
|
};
|
|
158
126
|
|
|
159
127
|
var becauseSubexpression = null; // No reason needed
|
|
160
|
-
|
|
161
128
|
var diag_tracking = 0;
|
|
162
129
|
var diag_chatty_flag = 0;
|
|
130
|
+
var diag_progress = function (str) {/*$rdf.log.debug(str);*/};
|
|
163
131
|
|
|
164
|
-
|
|
165
|
-
/*$rdf.log.debug(str);*/
|
|
166
|
-
}; // why_BecauseOfData = function(doc, reason) { return doc };
|
|
167
|
-
|
|
132
|
+
// why_BecauseOfData = function(doc, reason) { return doc };
|
|
168
133
|
|
|
169
134
|
var RDF_type_URI = "http://www.w3.org/1999/02/22-rdf-syntax-ns#type";
|
|
135
|
+
var RDF_nil_URI = "http://www.w3.org/1999/02/22-rdf-syntax-ns#nil";
|
|
170
136
|
var DAML_sameAs_URI = "http://www.w3.org/2002/07/owl#sameAs";
|
|
137
|
+
|
|
171
138
|
/*
|
|
172
139
|
function SyntaxError(details) {
|
|
173
140
|
return new __SyntaxError(details);
|
|
@@ -177,6 +144,7 @@ function SyntaxError(details) {
|
|
|
177
144
|
function __SyntaxError(details) {
|
|
178
145
|
this.details = details;
|
|
179
146
|
}
|
|
147
|
+
|
|
180
148
|
/*
|
|
181
149
|
|
|
182
150
|
$Id: n3parser.js 14561 2008-02-23 06:37:26Z kennyluck $
|
|
@@ -207,7 +175,6 @@ the module, including tests and test harness.
|
|
|
207
175
|
|
|
208
176
|
*/
|
|
209
177
|
|
|
210
|
-
|
|
211
178
|
var ADDED_HASH = "#";
|
|
212
179
|
var LOG_implies_URI = "http://www.w3.org/2000/10/swap/log#implies";
|
|
213
180
|
var INTEGER_DATATYPE = "http://www.w3.org/2001/XMLSchema#integer";
|
|
@@ -218,9 +185,7 @@ var DATETIME_DATATYPE = "http://www.w3.org/2001/XMLSchema#dateTime";
|
|
|
218
185
|
var BOOLEAN_DATATYPE = "http://www.w3.org/2001/XMLSchema#boolean";
|
|
219
186
|
var option_noregen = 0;
|
|
220
187
|
var _notQNameChars = "\t\r\n !\"#$%&'()*.,+/;<=>?@[\\]^`{|}~";
|
|
221
|
-
|
|
222
188
|
var _notNameChars = _notQNameChars + ":";
|
|
223
|
-
|
|
224
189
|
var _rdfns = "http://www.w3.org/1999/02/22-rdf-syntax-ns#";
|
|
225
190
|
var N3CommentCharacter = "#";
|
|
226
191
|
var eol = new RegExp("^[ \\t]*(#[^\\n]*)?\\r?\\n", 'g');
|
|
@@ -232,17 +197,13 @@ var datetime_syntax = new RegExp('^[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9](T[
|
|
|
232
197
|
var digitstring = new RegExp("^[0-9]+", 'g');
|
|
233
198
|
var interesting = new RegExp("[\\\\\\r\\n\\\"]", 'g');
|
|
234
199
|
var langcode = new RegExp("^[a-zA-Z0-9]+(-[a-zA-Z0-9]+)*", 'g');
|
|
235
|
-
|
|
236
200
|
function createSinkParser(store, openFormula, thisDoc, baseURI, genPrefix, metaURI, flags, why) {
|
|
237
201
|
return new SinkParser(store, openFormula, thisDoc, baseURI, genPrefix, metaURI, flags, why);
|
|
238
202
|
}
|
|
239
|
-
|
|
240
203
|
var _default = createSinkParser;
|
|
241
204
|
exports.default = _default;
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
function SinkParser(store, openFormula, thisDoc, baseURI, genPrefix, metaURI, flags, why) {
|
|
245
|
-
(0, _classCallCheck2.default)(this, SinkParser);
|
|
205
|
+
class SinkParser {
|
|
206
|
+
constructor(store, openFormula, thisDoc, baseURI, genPrefix, metaURI, flags, why) {
|
|
246
207
|
if (typeof openFormula == 'undefined') openFormula = null;
|
|
247
208
|
if (typeof thisDoc == 'undefined') thisDoc = "";
|
|
248
209
|
if (typeof baseURI == 'undefined') baseURI = null;
|
|
@@ -256,22 +217,19 @@ var SinkParser = /*#__PURE__*/function () {
|
|
|
256
217
|
|
|
257
218
|
this._bindings = new pyjslib_Dict([]);
|
|
258
219
|
this._flags = flags;
|
|
259
|
-
|
|
260
220
|
if (thisDoc != "") {
|
|
261
221
|
assertFudge(thisDoc.indexOf(":") >= 0, "Document URI not absolute: " + thisDoc);
|
|
262
222
|
this._bindings[""] = thisDoc + "#";
|
|
263
223
|
}
|
|
264
|
-
|
|
265
224
|
this._store = store;
|
|
266
|
-
|
|
267
225
|
if (genPrefix) {
|
|
268
226
|
store.setGenPrefix(genPrefix);
|
|
269
227
|
}
|
|
270
|
-
|
|
271
228
|
this._thisDoc = thisDoc;
|
|
272
229
|
this.source = store.sym(thisDoc);
|
|
273
230
|
this.lines = 0;
|
|
274
231
|
this.statementCount = 0;
|
|
232
|
+
this.hasNil = false;
|
|
275
233
|
this.startOfLine = 0;
|
|
276
234
|
this.previousLine = 0;
|
|
277
235
|
this._genPrefix = genPrefix;
|
|
@@ -282,11 +240,9 @@ var SinkParser = /*#__PURE__*/function () {
|
|
|
282
240
|
this._parentVariables = new pyjslib_Dict([]);
|
|
283
241
|
this._reason = why;
|
|
284
242
|
this._reason2 = null;
|
|
285
|
-
|
|
286
243
|
if (diag_tracking) {
|
|
287
244
|
this._reason2 = why_BecauseOfData(store.sym(thisDoc), this._reason);
|
|
288
245
|
}
|
|
289
|
-
|
|
290
246
|
if (baseURI) {
|
|
291
247
|
this._baseURI = baseURI;
|
|
292
248
|
} else {
|
|
@@ -296,9 +252,7 @@ var SinkParser = /*#__PURE__*/function () {
|
|
|
296
252
|
this._baseURI = null;
|
|
297
253
|
}
|
|
298
254
|
}
|
|
299
|
-
|
|
300
255
|
assertFudge(!this._baseURI || this._baseURI.indexOf(":") >= 0);
|
|
301
|
-
|
|
302
256
|
if (!this._genPrefix) {
|
|
303
257
|
if (this._thisDoc) {
|
|
304
258
|
this._genPrefix = this._thisDoc + "#_g";
|
|
@@ -306,7 +260,6 @@ var SinkParser = /*#__PURE__*/function () {
|
|
|
306
260
|
this._genPrefix = RDFSink_uniqueURI();
|
|
307
261
|
}
|
|
308
262
|
}
|
|
309
|
-
|
|
310
263
|
if (openFormula == null) {
|
|
311
264
|
if (this._thisDoc) {
|
|
312
265
|
this._formula = store.formula(thisDoc + "#_formula");
|
|
@@ -316,1499 +269,1158 @@ var SinkParser = /*#__PURE__*/function () {
|
|
|
316
269
|
} else {
|
|
317
270
|
this._formula = openFormula;
|
|
318
271
|
}
|
|
319
|
-
|
|
320
272
|
this._context = this._formula;
|
|
321
273
|
this._parentContext = null;
|
|
322
274
|
}
|
|
275
|
+
here(i) {
|
|
276
|
+
return this._genPrefix + "_L" + this.lines + "C" + (i - this.startOfLine + 1);
|
|
277
|
+
}
|
|
278
|
+
formula() {
|
|
279
|
+
return this._formula;
|
|
280
|
+
}
|
|
281
|
+
loadStream(stream) {
|
|
282
|
+
return this.loadBuf(stream.read());
|
|
283
|
+
}
|
|
284
|
+
loadBuf(buf) {
|
|
285
|
+
/*
|
|
286
|
+
Parses a buffer and returns its top level formula*/
|
|
323
287
|
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
Parses a buffer and returns its top level formula*/
|
|
344
|
-
this.startDoc();
|
|
345
|
-
this.feed(buf);
|
|
346
|
-
return this.endDoc();
|
|
347
|
-
}
|
|
348
|
-
}, {
|
|
349
|
-
key: "feed",
|
|
350
|
-
value: function feed(octets) {
|
|
351
|
-
/*
|
|
352
|
-
Feed an octet stream tothe parser
|
|
353
|
-
if BadSyntax is raised, the string
|
|
354
|
-
passed in the exception object is the
|
|
355
|
-
remainder after any statements have been parsed.
|
|
356
|
-
So if there is more data to feed to the
|
|
357
|
-
parser, it should be straightforward to recover.*/
|
|
358
|
-
var str = octets.decode("utf-8");
|
|
359
|
-
var i = 0;
|
|
360
|
-
|
|
361
|
-
while (i >= 0) {
|
|
362
|
-
var j = this.skipSpace(str, i);
|
|
363
|
-
|
|
364
|
-
if (j < 0) {
|
|
365
|
-
return;
|
|
366
|
-
}
|
|
367
|
-
|
|
368
|
-
var i = this.directiveOrStatement(str, j);
|
|
369
|
-
|
|
370
|
-
if (i < 0) {
|
|
371
|
-
throw BadSyntax(this._thisDoc, this.lines, str, j, "expected directive or statement");
|
|
372
|
-
}
|
|
288
|
+
this.startDoc();
|
|
289
|
+
this.feed(buf);
|
|
290
|
+
return this.endDoc();
|
|
291
|
+
}
|
|
292
|
+
feed(octets) {
|
|
293
|
+
/*
|
|
294
|
+
Feed an octet stream tothe parser
|
|
295
|
+
if BadSyntax is raised, the string
|
|
296
|
+
passed in the exception object is the
|
|
297
|
+
remainder after any statements have been parsed.
|
|
298
|
+
So if there is more data to feed to the
|
|
299
|
+
parser, it should be straightforward to recover.*/
|
|
300
|
+
|
|
301
|
+
var str = octets.decode("utf-8");
|
|
302
|
+
var i = 0;
|
|
303
|
+
while (i >= 0) {
|
|
304
|
+
var j = this.skipSpace(str, i);
|
|
305
|
+
if (j < 0) {
|
|
306
|
+
return;
|
|
373
307
|
}
|
|
374
|
-
|
|
375
|
-
}, {
|
|
376
|
-
key: "directiveOrStatement",
|
|
377
|
-
value: function directiveOrStatement(str, h) {
|
|
378
|
-
var i = this.skipSpace(str, h);
|
|
379
|
-
|
|
308
|
+
var i = this.directiveOrStatement(str, j);
|
|
380
309
|
if (i < 0) {
|
|
381
|
-
|
|
382
|
-
}
|
|
383
|
-
|
|
384
|
-
var j = this.directive(str, i);
|
|
385
|
-
|
|
386
|
-
if (j >= 0) {
|
|
387
|
-
return this.checkDot(str, j);
|
|
388
|
-
}
|
|
389
|
-
|
|
390
|
-
var j = this.statement(str, i);
|
|
391
|
-
|
|
392
|
-
if (j >= 0) {
|
|
393
|
-
return this.checkDot(str, j);
|
|
310
|
+
throw BadSyntax(this._thisDoc, this.lines, str, j, "expected directive or statement");
|
|
394
311
|
}
|
|
395
|
-
|
|
396
|
-
return j;
|
|
397
312
|
}
|
|
398
|
-
}
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
313
|
+
}
|
|
314
|
+
directiveOrStatement(str, h) {
|
|
315
|
+
var i = this.skipSpace(str, h);
|
|
316
|
+
if (i < 0) {
|
|
317
|
+
return i;
|
|
318
|
+
}
|
|
319
|
+
var j = this.directive(str, i);
|
|
320
|
+
if (j >= 0) {
|
|
321
|
+
return this.checkDot(str, j);
|
|
322
|
+
}
|
|
323
|
+
var j = this.statement(str, i);
|
|
324
|
+
if (j >= 0) {
|
|
325
|
+
return this.checkDot(str, j);
|
|
326
|
+
}
|
|
327
|
+
return j;
|
|
328
|
+
}
|
|
329
|
+
tok(tok, str, i) {
|
|
330
|
+
/*
|
|
331
|
+
Check for keyword. Space must have been stripped on entry and
|
|
332
|
+
we must not be at end of file.*/
|
|
333
|
+
var whitespace = "\t\n\v\f\r ";
|
|
334
|
+
if (str.slice(i, i + 1) == "@") {
|
|
335
|
+
var i = i + 1;
|
|
336
|
+
} else {
|
|
337
|
+
if ((0, _utils.ArrayIndexOf)(this.keywords, tok) < 0) {
|
|
419
338
|
return -1;
|
|
420
339
|
}
|
|
421
340
|
}
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
341
|
+
var k = i + pyjslib_len(tok);
|
|
342
|
+
if (str.slice(i, k) == tok && _notQNameChars.indexOf(str.charAt(k)) >= 0) {
|
|
343
|
+
return k;
|
|
344
|
+
} else {
|
|
345
|
+
return -1;
|
|
346
|
+
}
|
|
347
|
+
}
|
|
348
|
+
directive(str, i) {
|
|
349
|
+
var j = this.skipSpace(str, i);
|
|
350
|
+
if (j < 0) {
|
|
351
|
+
return j;
|
|
352
|
+
}
|
|
353
|
+
var res = new pyjslib_List([]);
|
|
354
|
+
var j = this.tok("bind", str, i);
|
|
355
|
+
if (j > 0) {
|
|
356
|
+
throw BadSyntax(this._thisDoc, this.lines, str, i, "keyword bind is obsolete: use @prefix");
|
|
357
|
+
}
|
|
358
|
+
var j = this.tok("keywords", str, i);
|
|
359
|
+
if (j > 0) {
|
|
360
|
+
var i = this.commaSeparatedList(str, j, res, false);
|
|
361
|
+
if (i < 0) {
|
|
362
|
+
throw BadSyntax(this._thisDoc, this.lines, str, i, "'@keywords' needs comma separated list of words");
|
|
436
363
|
}
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
if (j > 0) {
|
|
441
|
-
var i = this.commaSeparatedList(str, j, res, false);
|
|
442
|
-
|
|
443
|
-
if (i < 0) {
|
|
444
|
-
throw BadSyntax(this._thisDoc, this.lines, str, i, "'@keywords' needs comma separated list of words");
|
|
445
|
-
}
|
|
446
|
-
|
|
447
|
-
this.setKeywords(pyjslib_slice(res, null, null));
|
|
448
|
-
|
|
449
|
-
if (diag_chatty_flag > 80) {
|
|
450
|
-
diag_progress("Keywords ", this.keywords);
|
|
451
|
-
}
|
|
452
|
-
|
|
453
|
-
return i;
|
|
364
|
+
this.setKeywords(pyjslib_slice(res, null, null));
|
|
365
|
+
if (diag_chatty_flag > 80) {
|
|
366
|
+
diag_progress("Keywords ", this.keywords);
|
|
454
367
|
}
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
var x = __x.next();
|
|
470
|
-
|
|
471
|
-
if ((0, _utils.ArrayIndexOf)(this._variables, x) < 0 || (0, _utils.ArrayIndexOf)(this._parentVariables, x) >= 0) {
|
|
472
|
-
this._variables[x] = this._context.newUniversal(x);
|
|
473
|
-
}
|
|
474
|
-
}
|
|
475
|
-
} catch (e) {
|
|
476
|
-
if (e != StopIteration) {
|
|
477
|
-
throw e;
|
|
368
|
+
return i;
|
|
369
|
+
}
|
|
370
|
+
var j = this.tok("forAll", str, i);
|
|
371
|
+
if (j > 0) {
|
|
372
|
+
var i = this.commaSeparatedList(str, j, res, true);
|
|
373
|
+
if (i < 0) {
|
|
374
|
+
throw BadSyntax(this._thisDoc, this.lines, str, i, "Bad variable list after @forAll");
|
|
375
|
+
}
|
|
376
|
+
var __x = new pyjslib_Iterator(res);
|
|
377
|
+
try {
|
|
378
|
+
while (true) {
|
|
379
|
+
var x = __x.next();
|
|
380
|
+
if ((0, _utils.ArrayIndexOf)(this._variables, x) < 0 || (0, _utils.ArrayIndexOf)(this._parentVariables, x) >= 0) {
|
|
381
|
+
this._variables[x] = this._context.newUniversal(x);
|
|
478
382
|
}
|
|
479
383
|
}
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
var j = this.tok("forSome", str, i);
|
|
485
|
-
|
|
486
|
-
if (j > 0) {
|
|
487
|
-
var i = this.commaSeparatedList(str, j, res, this.uri_ref2);
|
|
488
|
-
|
|
489
|
-
if (i < 0) {
|
|
490
|
-
throw BadSyntax(this._thisDoc, this.lines, str, i, "Bad variable list after @forSome");
|
|
491
|
-
}
|
|
492
|
-
|
|
493
|
-
var __x = new pyjslib_Iterator(res);
|
|
494
|
-
|
|
495
|
-
try {
|
|
496
|
-
while (true) {
|
|
497
|
-
var x = __x.next();
|
|
498
|
-
|
|
499
|
-
this._context.declareExistential(x);
|
|
500
|
-
}
|
|
501
|
-
} catch (e) {
|
|
502
|
-
if (e != StopIteration) {
|
|
503
|
-
throw e;
|
|
504
|
-
}
|
|
384
|
+
} catch (e) {
|
|
385
|
+
if (e != StopIteration) {
|
|
386
|
+
throw e;
|
|
505
387
|
}
|
|
506
|
-
|
|
507
|
-
return i;
|
|
508
388
|
}
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
if (i < 0) {
|
|
517
|
-
throw BadSyntax(this._thisDoc, this.lines, str, j, "expected qname after @prefix");
|
|
518
|
-
}
|
|
519
|
-
|
|
520
|
-
var j = this.uri_ref2(str, i, t);
|
|
521
|
-
|
|
522
|
-
if (j < 0) {
|
|
523
|
-
throw BadSyntax(this._thisDoc, this.lines, str, i, "expected <uriref> after @prefix _qname_");
|
|
524
|
-
}
|
|
525
|
-
|
|
526
|
-
var ns = t[1].uri;
|
|
527
|
-
|
|
528
|
-
if (this._baseURI) {
|
|
529
|
-
var ns = uripath_join(this._baseURI, ns);
|
|
530
|
-
} else {
|
|
531
|
-
assertFudge(ns.indexOf(":") >= 0, "With no base URI, cannot handle relative URI for NS");
|
|
532
|
-
}
|
|
533
|
-
|
|
534
|
-
assertFudge(ns.indexOf(":") >= 0);
|
|
535
|
-
this._bindings[t[0][0]] = ns;
|
|
536
|
-
this.bind(t[0][0], hexify(ns));
|
|
537
|
-
return j;
|
|
389
|
+
return i;
|
|
390
|
+
}
|
|
391
|
+
var j = this.tok("forSome", str, i);
|
|
392
|
+
if (j > 0) {
|
|
393
|
+
var i = this.commaSeparatedList(str, j, res, this.uri_ref2);
|
|
394
|
+
if (i < 0) {
|
|
395
|
+
throw BadSyntax(this._thisDoc, this.lines, str, i, "Bad variable list after @forSome");
|
|
538
396
|
}
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
var i = this.uri_ref2(str, j, t);
|
|
545
|
-
|
|
546
|
-
if (i < 0) {
|
|
547
|
-
throw BadSyntax(this._thisDoc, this.lines, str, j, "expected <uri> after @base ");
|
|
397
|
+
var __x = new pyjslib_Iterator(res);
|
|
398
|
+
try {
|
|
399
|
+
while (true) {
|
|
400
|
+
var x = __x.next();
|
|
401
|
+
this._context.declareExistential(x);
|
|
548
402
|
}
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
if (this._baseURI) {
|
|
553
|
-
var ns = uripath_join(this._baseURI, ns);
|
|
554
|
-
} else {
|
|
555
|
-
throw BadSyntax(this._thisDoc, this.lines, str, j, "With no previous base URI, cannot use relative URI in @base <" + ns + ">");
|
|
403
|
+
} catch (e) {
|
|
404
|
+
if (e != StopIteration) {
|
|
405
|
+
throw e;
|
|
556
406
|
}
|
|
557
|
-
|
|
558
|
-
assertFudge(ns.indexOf(":") >= 0);
|
|
559
|
-
this._baseURI = ns;
|
|
560
|
-
return i;
|
|
561
407
|
}
|
|
562
|
-
|
|
563
|
-
return -1;
|
|
408
|
+
return i;
|
|
564
409
|
}
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
410
|
+
var j = this.tok("prefix", str, i);
|
|
411
|
+
if (j >= 0) {
|
|
412
|
+
var t = new pyjslib_List([]);
|
|
413
|
+
var i = this.qname(str, j, t);
|
|
414
|
+
if (i < 0) {
|
|
415
|
+
throw BadSyntax(this._thisDoc, this.lines, str, j, "expected qname after @prefix");
|
|
570
416
|
}
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
this.keywordsSet = 0;
|
|
417
|
+
var j = this.uri_ref2(str, i, t);
|
|
418
|
+
if (j < 0) {
|
|
419
|
+
throw BadSyntax(this._thisDoc, this.lines, str, i, "expected <uriref> after @prefix _qname_");
|
|
420
|
+
}
|
|
421
|
+
var ns = t[1].uri;
|
|
422
|
+
if (this._baseURI) {
|
|
423
|
+
var ns = uripath_join(this._baseURI, ns);
|
|
579
424
|
} else {
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
Signal end of document and stop parsing. returns formula*/
|
|
592
|
-
return this._formula;
|
|
593
|
-
}
|
|
594
|
-
}, {
|
|
595
|
-
key: "makeStatement",
|
|
596
|
-
value: function makeStatement(quad) {
|
|
597
|
-
quad[0].add(quad[2], quad[1], quad[3], this.source);
|
|
598
|
-
this.statementCount += 1;
|
|
599
|
-
}
|
|
600
|
-
}, {
|
|
601
|
-
key: "statement",
|
|
602
|
-
value: function statement(str, i) {
|
|
603
|
-
var r = new pyjslib_List([]);
|
|
604
|
-
var i = this.object(str, i, r);
|
|
605
|
-
|
|
425
|
+
assertFudge(ns.indexOf(":") >= 0, "With no base URI, cannot handle relative URI for NS");
|
|
426
|
+
}
|
|
427
|
+
assertFudge(ns.indexOf(":") >= 0);
|
|
428
|
+
this._bindings[t[0][0]] = ns;
|
|
429
|
+
this.bind(t[0][0], hexify(ns));
|
|
430
|
+
return j;
|
|
431
|
+
}
|
|
432
|
+
var j = this.tok("base", str, i);
|
|
433
|
+
if (j >= 0) {
|
|
434
|
+
var t = new pyjslib_List([]);
|
|
435
|
+
var i = this.uri_ref2(str, j, t);
|
|
606
436
|
if (i < 0) {
|
|
607
|
-
|
|
437
|
+
throw BadSyntax(this._thisDoc, this.lines, str, j, "expected <uri> after @base ");
|
|
608
438
|
}
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
throw BadSyntax(this._thisDoc, this.lines, str,
|
|
439
|
+
var ns = t[0].uri;
|
|
440
|
+
if (this._baseURI) {
|
|
441
|
+
var ns = uripath_join(this._baseURI, ns);
|
|
442
|
+
} else {
|
|
443
|
+
throw BadSyntax(this._thisDoc, this.lines, str, j, "With no previous base URI, cannot use relative URI in @base <" + ns + ">");
|
|
614
444
|
}
|
|
445
|
+
assertFudge(ns.indexOf(":") >= 0);
|
|
446
|
+
this._baseURI = ns;
|
|
447
|
+
return i;
|
|
448
|
+
}
|
|
449
|
+
return -1;
|
|
450
|
+
}
|
|
451
|
+
bind(qn, uri) {
|
|
452
|
+
if (qn == "") {} else {
|
|
453
|
+
this._store.setPrefixForURI(qn, uri);
|
|
454
|
+
}
|
|
455
|
+
}
|
|
456
|
+
setKeywords(k) {
|
|
457
|
+
/*
|
|
458
|
+
Takes a list of strings*/
|
|
615
459
|
|
|
460
|
+
if (k == null) {
|
|
461
|
+
this.keywordsSet = 0;
|
|
462
|
+
} else {
|
|
463
|
+
this.keywords = k;
|
|
464
|
+
this.keywordsSet = 1;
|
|
465
|
+
}
|
|
466
|
+
}
|
|
467
|
+
startDoc() {}
|
|
468
|
+
/* Signal end of document and stop parsing. returns formula */
|
|
469
|
+
endDoc() {
|
|
470
|
+
if (this.hasNil && this._store.rdfFactory.supports["COLLECTIONS"]) {
|
|
471
|
+
(0, _lists.convertFirstRestNil)(this._store, this.source);
|
|
472
|
+
}
|
|
473
|
+
return this._formula;
|
|
474
|
+
}
|
|
475
|
+
makeStatement(quad) {
|
|
476
|
+
quad[0].add(quad[2], quad[1], quad[3], this.source);
|
|
477
|
+
if (quad[2].uri && quad[2].uri === RDF_nil_URI || quad[3].uri && quad[3].uri === RDF_nil_URI) {
|
|
478
|
+
this.hasNil = true;
|
|
479
|
+
}
|
|
480
|
+
this.statementCount += 1;
|
|
481
|
+
}
|
|
482
|
+
statement(str, i) {
|
|
483
|
+
var r = new pyjslib_List([]);
|
|
484
|
+
var i = this.object(str, i, r);
|
|
485
|
+
if (i < 0) {
|
|
486
|
+
return i;
|
|
487
|
+
}
|
|
488
|
+
var j = this.property_list(str, i, r[0]);
|
|
489
|
+
if (j < 0) {
|
|
490
|
+
throw BadSyntax(this._thisDoc, this.lines, str, i, "expected propertylist");
|
|
491
|
+
}
|
|
492
|
+
return j;
|
|
493
|
+
}
|
|
494
|
+
subject(str, i, res) {
|
|
495
|
+
return this.item(str, i, res);
|
|
496
|
+
}
|
|
497
|
+
verb(str, i, res) {
|
|
498
|
+
/*
|
|
499
|
+
has _prop_
|
|
500
|
+
is _prop_ of
|
|
501
|
+
a
|
|
502
|
+
=
|
|
503
|
+
_prop_
|
|
504
|
+
>- prop ->
|
|
505
|
+
<- prop -<
|
|
506
|
+
_operator_*/
|
|
507
|
+
|
|
508
|
+
var j = this.skipSpace(str, i);
|
|
509
|
+
if (j < 0) {
|
|
616
510
|
return j;
|
|
617
511
|
}
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
=
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
_operator_*/
|
|
512
|
+
var r = new pyjslib_List([]);
|
|
513
|
+
var j = this.tok("has", str, i);
|
|
514
|
+
if (j >= 0) {
|
|
515
|
+
var i = this.prop(str, j, r);
|
|
516
|
+
if (i < 0) {
|
|
517
|
+
throw BadSyntax(this._thisDoc, this.lines, str, j, "expected property after 'has'");
|
|
518
|
+
}
|
|
519
|
+
res.push(new pyjslib_Tuple(["->", r[0]]));
|
|
520
|
+
return i;
|
|
521
|
+
}
|
|
522
|
+
var j = this.tok("is", str, i);
|
|
523
|
+
if (j >= 0) {
|
|
524
|
+
var i = this.prop(str, j, r);
|
|
525
|
+
if (i < 0) {
|
|
526
|
+
throw BadSyntax(this._thisDoc, this.lines, str, j, "expected <property> after 'is'");
|
|
527
|
+
}
|
|
635
528
|
var j = this.skipSpace(str, i);
|
|
636
|
-
|
|
637
529
|
if (j < 0) {
|
|
530
|
+
throw BadSyntax(this._thisDoc, this.lines, str, i, "End of file found, expected property after 'is'");
|
|
638
531
|
return j;
|
|
639
532
|
}
|
|
533
|
+
var i = j;
|
|
534
|
+
var j = this.tok("of", str, i);
|
|
535
|
+
if (j < 0) {
|
|
536
|
+
throw BadSyntax(this._thisDoc, this.lines, str, i, "expected 'of' after 'is' <prop>");
|
|
537
|
+
}
|
|
538
|
+
res.push(new pyjslib_Tuple(["<-", r[0]]));
|
|
539
|
+
return j;
|
|
540
|
+
}
|
|
541
|
+
var j = this.tok("a", str, i);
|
|
542
|
+
if (j >= 0) {
|
|
543
|
+
res.push(new pyjslib_Tuple(["->", this._store.sym(RDF_type_URI)]));
|
|
544
|
+
return j;
|
|
545
|
+
}
|
|
546
|
+
if (str.slice(i, i + 2) == "<=") {
|
|
547
|
+
res.push(new pyjslib_Tuple(["<-", this._store.sym(Logic_NS + "implies")]));
|
|
548
|
+
return i + 2;
|
|
549
|
+
}
|
|
550
|
+
if (str.slice(i, i + 1) == "=") {
|
|
551
|
+
if (str.slice(i + 1, i + 2) == ">") {
|
|
552
|
+
res.push(new pyjslib_Tuple(["->", this._store.sym(Logic_NS + "implies")]));
|
|
553
|
+
return i + 2;
|
|
554
|
+
}
|
|
555
|
+
res.push(new pyjslib_Tuple(["->", this._store.sym(DAML_sameAs_URI)]));
|
|
556
|
+
return i + 1;
|
|
557
|
+
}
|
|
558
|
+
if (str.slice(i, i + 2) == ":=") {
|
|
559
|
+
res.push(new pyjslib_Tuple(["->", Logic_NS + "becomes"]));
|
|
560
|
+
return i + 2;
|
|
561
|
+
}
|
|
562
|
+
var j = this.prop(str, i, r);
|
|
563
|
+
if (j >= 0) {
|
|
564
|
+
res.push(new pyjslib_Tuple(["->", r[0]]));
|
|
565
|
+
return j;
|
|
566
|
+
}
|
|
567
|
+
if (str.slice(i, i + 2) == ">-" || str.slice(i, i + 2) == "<-") {
|
|
568
|
+
throw BadSyntax(this._thisDoc, this.lines, str, j, ">- ... -> syntax is obsolete.");
|
|
569
|
+
}
|
|
570
|
+
return -1;
|
|
571
|
+
}
|
|
572
|
+
prop(str, i, res) {
|
|
573
|
+
return this.item(str, i, res);
|
|
574
|
+
}
|
|
575
|
+
item(str, i, res) {
|
|
576
|
+
return this.path(str, i, res);
|
|
577
|
+
}
|
|
578
|
+
blankNode(uri) {
|
|
579
|
+
return this._context.bnode(uri, this._reason2);
|
|
580
|
+
}
|
|
581
|
+
path(str, i, res) {
|
|
582
|
+
/*
|
|
583
|
+
Parse the path production.
|
|
584
|
+
*/
|
|
640
585
|
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
586
|
+
var j = this.nodeOrLiteral(str, i, res);
|
|
587
|
+
if (j < 0) {
|
|
588
|
+
return j;
|
|
589
|
+
}
|
|
590
|
+
while ("!^.".indexOf(str.slice(j, j + 1)) >= 0) {
|
|
591
|
+
var ch = str.slice(j, j + 1);
|
|
592
|
+
if (ch == ".") {
|
|
593
|
+
var ahead = str.slice(j + 1, j + 2);
|
|
594
|
+
if (!ahead || _notNameChars.indexOf(ahead) >= 0 && ":?<[{(".indexOf(ahead) < 0) {
|
|
595
|
+
break;
|
|
649
596
|
}
|
|
650
|
-
|
|
651
|
-
res.push(new pyjslib_Tuple(["->", r[0]]));
|
|
652
|
-
return i;
|
|
653
|
-
}
|
|
654
|
-
|
|
655
|
-
var j = this.tok("is", str, i);
|
|
656
|
-
|
|
657
|
-
if (j >= 0) {
|
|
658
|
-
var i = this.prop(str, j, r);
|
|
659
|
-
|
|
660
|
-
if (i < 0) {
|
|
661
|
-
throw BadSyntax(this._thisDoc, this.lines, str, j, "expected <property> after 'is'");
|
|
662
|
-
}
|
|
663
|
-
|
|
664
|
-
var j = this.skipSpace(str, i);
|
|
665
|
-
|
|
666
|
-
if (j < 0) {
|
|
667
|
-
throw BadSyntax(this._thisDoc, this.lines, str, i, "End of file found, expected property after 'is'");
|
|
668
|
-
return j;
|
|
669
|
-
}
|
|
670
|
-
|
|
671
|
-
var i = j;
|
|
672
|
-
var j = this.tok("of", str, i);
|
|
673
|
-
|
|
674
|
-
if (j < 0) {
|
|
675
|
-
throw BadSyntax(this._thisDoc, this.lines, str, i, "expected 'of' after 'is' <prop>");
|
|
676
|
-
}
|
|
677
|
-
|
|
678
|
-
res.push(new pyjslib_Tuple(["<-", r[0]]));
|
|
679
|
-
return j;
|
|
680
597
|
}
|
|
681
|
-
|
|
682
|
-
var
|
|
683
|
-
|
|
684
|
-
if (j >= 0) {
|
|
685
|
-
res.push(new pyjslib_Tuple(["->", this._store.sym(RDF_type_URI)]));
|
|
686
|
-
return j;
|
|
687
|
-
}
|
|
688
|
-
|
|
689
|
-
if (str.slice(i, i + 2) == "<=") {
|
|
690
|
-
res.push(new pyjslib_Tuple(["<-", this._store.sym(Logic_NS + "implies")]));
|
|
691
|
-
return i + 2;
|
|
692
|
-
}
|
|
693
|
-
|
|
694
|
-
if (str.slice(i, i + 1) == "=") {
|
|
695
|
-
if (str.slice(i + 1, i + 2) == ">") {
|
|
696
|
-
res.push(new pyjslib_Tuple(["->", this._store.sym(Logic_NS + "implies")]));
|
|
697
|
-
return i + 2;
|
|
698
|
-
}
|
|
699
|
-
|
|
700
|
-
res.push(new pyjslib_Tuple(["->", this._store.sym(DAML_sameAs_URI)]));
|
|
701
|
-
return i + 1;
|
|
702
|
-
}
|
|
703
|
-
|
|
704
|
-
if (str.slice(i, i + 2) == ":=") {
|
|
705
|
-
res.push(new pyjslib_Tuple(["->", Logic_NS + "becomes"]));
|
|
706
|
-
return i + 2;
|
|
707
|
-
}
|
|
708
|
-
|
|
709
|
-
var j = this.prop(str, i, r);
|
|
710
|
-
|
|
711
|
-
if (j >= 0) {
|
|
712
|
-
res.push(new pyjslib_Tuple(["->", r[0]]));
|
|
713
|
-
return j;
|
|
714
|
-
}
|
|
715
|
-
|
|
716
|
-
if (str.slice(i, i + 2) == ">-" || str.slice(i, i + 2) == "<-") {
|
|
717
|
-
throw BadSyntax(this._thisDoc, this.lines, str, j, ">- ... -> syntax is obsolete.");
|
|
718
|
-
}
|
|
719
|
-
|
|
720
|
-
return -1;
|
|
721
|
-
}
|
|
722
|
-
}, {
|
|
723
|
-
key: "prop",
|
|
724
|
-
value: function prop(str, i, res) {
|
|
725
|
-
return this.item(str, i, res);
|
|
726
|
-
}
|
|
727
|
-
}, {
|
|
728
|
-
key: "item",
|
|
729
|
-
value: function item(str, i, res) {
|
|
730
|
-
return this.path(str, i, res);
|
|
731
|
-
}
|
|
732
|
-
}, {
|
|
733
|
-
key: "blankNode",
|
|
734
|
-
value: function blankNode(uri) {
|
|
735
|
-
return this._context.bnode(uri, this._reason2);
|
|
736
|
-
}
|
|
737
|
-
}, {
|
|
738
|
-
key: "path",
|
|
739
|
-
value: function path(str, i, res) {
|
|
740
|
-
/*
|
|
741
|
-
Parse the path production.
|
|
742
|
-
*/
|
|
743
|
-
var j = this.nodeOrLiteral(str, i, res);
|
|
744
|
-
|
|
598
|
+
var subj = res.pop();
|
|
599
|
+
var obj = this.blankNode(this.here(j));
|
|
600
|
+
var j = this.node(str, j + 1, res);
|
|
745
601
|
if (j < 0) {
|
|
746
|
-
|
|
602
|
+
throw BadSyntax(this._thisDoc, this.lines, str, j, "EOF found in middle of path syntax");
|
|
747
603
|
}
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
var ahead = str.slice(j + 1, j + 2);
|
|
754
|
-
|
|
755
|
-
if (!ahead || _notNameChars.indexOf(ahead) >= 0 && ":?<[{(".indexOf(ahead) < 0) {
|
|
756
|
-
break;
|
|
757
|
-
}
|
|
758
|
-
}
|
|
759
|
-
|
|
760
|
-
var subj = res.pop();
|
|
761
|
-
var obj = this.blankNode(this.here(j));
|
|
762
|
-
var j = this.node(str, j + 1, res);
|
|
763
|
-
|
|
764
|
-
if (j < 0) {
|
|
765
|
-
throw BadSyntax(this._thisDoc, this.lines, str, j, "EOF found in middle of path syntax");
|
|
766
|
-
}
|
|
767
|
-
|
|
768
|
-
var pred = res.pop();
|
|
769
|
-
|
|
770
|
-
if (ch == "^") {
|
|
771
|
-
this.makeStatement(new pyjslib_Tuple([this._context, pred, obj, subj]));
|
|
772
|
-
} else {
|
|
773
|
-
this.makeStatement(new pyjslib_Tuple([this._context, pred, subj, obj]));
|
|
774
|
-
}
|
|
775
|
-
|
|
776
|
-
res.push(obj);
|
|
604
|
+
var pred = res.pop();
|
|
605
|
+
if (ch == "^") {
|
|
606
|
+
this.makeStatement(new pyjslib_Tuple([this._context, pred, obj, subj]));
|
|
607
|
+
} else {
|
|
608
|
+
this.makeStatement(new pyjslib_Tuple([this._context, pred, subj, obj]));
|
|
777
609
|
}
|
|
778
|
-
|
|
779
|
-
return j;
|
|
610
|
+
res.push(obj);
|
|
780
611
|
}
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
var term = this._anonymousNodes[ln];
|
|
787
|
-
|
|
788
|
-
if (term) {
|
|
789
|
-
return term;
|
|
790
|
-
}
|
|
791
|
-
|
|
792
|
-
var term = this._store.bnode(ln); // var term = this._store.bnode(this._context, this._reason2); eh?
|
|
793
|
-
|
|
612
|
+
return j;
|
|
613
|
+
}
|
|
614
|
+
anonymousNode(ln) {
|
|
615
|
+
/*
|
|
616
|
+
Remember or generate a term for one of these _: anonymous nodes*/
|
|
794
617
|
|
|
795
|
-
|
|
618
|
+
var term = this._anonymousNodes[ln];
|
|
619
|
+
if (term) {
|
|
796
620
|
return term;
|
|
797
621
|
}
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
622
|
+
var term = this._store.bnode(ln);
|
|
623
|
+
// var term = this._store.bnode(this._context, this._reason2); eh?
|
|
624
|
+
this._anonymousNodes[ln] = term;
|
|
625
|
+
return term;
|
|
626
|
+
}
|
|
627
|
+
node(str, i, res, subjectAlready) {
|
|
628
|
+
if (typeof subjectAlready == 'undefined') subjectAlready = null;
|
|
629
|
+
/*
|
|
630
|
+
Parse the <node> production.
|
|
631
|
+
Space is now skipped once at the beginning
|
|
632
|
+
instead of in multipe calls to self.skipSpace().
|
|
633
|
+
*/
|
|
634
|
+
|
|
635
|
+
var subj = subjectAlready;
|
|
636
|
+
var j = this.skipSpace(str, i);
|
|
637
|
+
if (j < 0) {
|
|
638
|
+
return j;
|
|
639
|
+
}
|
|
640
|
+
var i = j;
|
|
641
|
+
var ch = str.slice(i, i + 1);
|
|
642
|
+
if (ch == "[") {
|
|
643
|
+
var bnodeID = this.here(i);
|
|
644
|
+
var j = this.skipSpace(str, i + 1);
|
|
811
645
|
if (j < 0) {
|
|
812
|
-
|
|
646
|
+
throw BadSyntax(this._thisDoc, this.lines, str, i, "EOF after '['");
|
|
813
647
|
}
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
if (str.slice(j, j + 1) == "=") {
|
|
827
|
-
var i = j + 1;
|
|
828
|
-
var objs = new pyjslib_List([]);
|
|
829
|
-
var j = this.objectList(str, i, objs);
|
|
830
|
-
|
|
831
|
-
if (j >= 0) {
|
|
832
|
-
var subj = objs[0];
|
|
833
|
-
|
|
834
|
-
if (pyjslib_len(objs) > 1) {
|
|
835
|
-
var __obj = new pyjslib_Iterator(objs);
|
|
836
|
-
|
|
837
|
-
try {
|
|
838
|
-
while (true) {
|
|
839
|
-
var obj = __obj.next();
|
|
840
|
-
|
|
841
|
-
this.makeStatement(new pyjslib_Tuple([this._context, this._store.sym(DAML_sameAs_URI), subj, obj]));
|
|
842
|
-
}
|
|
843
|
-
} catch (e) {
|
|
844
|
-
if (e != StopIteration) {
|
|
845
|
-
throw e;
|
|
846
|
-
}
|
|
648
|
+
if (str.slice(j, j + 1) == "=") {
|
|
649
|
+
var i = j + 1;
|
|
650
|
+
var objs = new pyjslib_List([]);
|
|
651
|
+
var j = this.objectList(str, i, objs);
|
|
652
|
+
if (j >= 0) {
|
|
653
|
+
var subj = objs[0];
|
|
654
|
+
if (pyjslib_len(objs) > 1) {
|
|
655
|
+
var __obj = new pyjslib_Iterator(objs);
|
|
656
|
+
try {
|
|
657
|
+
while (true) {
|
|
658
|
+
var obj = __obj.next();
|
|
659
|
+
this.makeStatement(new pyjslib_Tuple([this._context, this._store.sym(DAML_sameAs_URI), subj, obj]));
|
|
847
660
|
}
|
|
848
|
-
}
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
if (j < 0) {
|
|
853
|
-
throw BadSyntax(this._thisDoc, this.lines, str, i, "EOF when objectList expected after [ = ");
|
|
854
|
-
}
|
|
855
|
-
|
|
856
|
-
if (str.slice(j, j + 1) == ";") {
|
|
857
|
-
var j = j + 1;
|
|
858
|
-
}
|
|
859
|
-
} else {
|
|
860
|
-
throw BadSyntax(this._thisDoc, this.lines, str, i, "objectList expected after [= ");
|
|
861
|
-
}
|
|
862
|
-
}
|
|
863
|
-
|
|
864
|
-
if (subj == null) {
|
|
865
|
-
var subj = this.blankNode(bnodeID);
|
|
866
|
-
}
|
|
867
|
-
|
|
868
|
-
var i = this.property_list(str, j, subj);
|
|
869
|
-
|
|
870
|
-
if (i < 0) {
|
|
871
|
-
throw BadSyntax(this._thisDoc, this.lines, str, j, "property_list expected");
|
|
872
|
-
}
|
|
873
|
-
|
|
874
|
-
var j = this.skipSpace(str, i);
|
|
875
|
-
|
|
876
|
-
if (j < 0) {
|
|
877
|
-
throw BadSyntax(this._thisDoc, this.lines, str, i, "EOF when ']' expected after [ <propertyList>");
|
|
878
|
-
}
|
|
879
|
-
|
|
880
|
-
if (str.slice(j, j + 1) != "]") {
|
|
881
|
-
throw BadSyntax(this._thisDoc, this.lines, str, j, "']' expected");
|
|
882
|
-
}
|
|
883
|
-
|
|
884
|
-
res.push(subj);
|
|
885
|
-
return j + 1;
|
|
886
|
-
}
|
|
887
|
-
|
|
888
|
-
if (ch == "{") {
|
|
889
|
-
var ch2 = str.slice(i + 1, i + 2);
|
|
890
|
-
|
|
891
|
-
if (ch2 == "$") {
|
|
892
|
-
i += 1;
|
|
893
|
-
var j = i + 1;
|
|
894
|
-
var mylist = new pyjslib_List([]);
|
|
895
|
-
var first_run = true;
|
|
896
|
-
|
|
897
|
-
while (1) {
|
|
898
|
-
var i = this.skipSpace(str, j);
|
|
899
|
-
|
|
900
|
-
if (i < 0) {
|
|
901
|
-
throw BadSyntax(this._thisDoc, this.lines, str, i, "needed '$}', found end.");
|
|
902
|
-
}
|
|
903
|
-
|
|
904
|
-
if (str.slice(i, i + 2) == "$}") {
|
|
905
|
-
var j = i + 2;
|
|
906
|
-
break;
|
|
907
|
-
}
|
|
908
|
-
|
|
909
|
-
if (!first_run) {
|
|
910
|
-
if (str.slice(i, i + 1) == ",") {
|
|
911
|
-
i += 1;
|
|
912
|
-
} else {
|
|
913
|
-
throw BadSyntax(this._thisDoc, this.lines, str, i, "expected: ','");
|
|
661
|
+
} catch (e) {
|
|
662
|
+
if (e != StopIteration) {
|
|
663
|
+
throw e;
|
|
914
664
|
}
|
|
915
|
-
} else {
|
|
916
|
-
var first_run = false;
|
|
917
|
-
}
|
|
918
|
-
|
|
919
|
-
var item = new pyjslib_List([]);
|
|
920
|
-
var j = this.item(str, i, item);
|
|
921
|
-
|
|
922
|
-
if (j < 0) {
|
|
923
|
-
throw BadSyntax(this._thisDoc, this.lines, str, i, "expected item in set or '$}'");
|
|
924
665
|
}
|
|
925
|
-
|
|
926
|
-
mylist.push(item[0]);
|
|
927
666
|
}
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
} else {
|
|
932
|
-
var j = i + 1;
|
|
933
|
-
var oldParentContext = this._parentContext;
|
|
934
|
-
this._parentContext = this._context;
|
|
935
|
-
var parentAnonymousNodes = this._anonymousNodes;
|
|
936
|
-
var grandParentVariables = this._parentVariables;
|
|
937
|
-
this._parentVariables = this._variables;
|
|
938
|
-
this._anonymousNodes = new pyjslib_Dict([]);
|
|
939
|
-
this._variables = this._variables.slice();
|
|
940
|
-
var reason2 = this._reason2;
|
|
941
|
-
this._reason2 = becauseSubexpression;
|
|
942
|
-
|
|
943
|
-
if (subj == null) {
|
|
944
|
-
var subj = this._store.formula();
|
|
667
|
+
var j = this.skipSpace(str, j);
|
|
668
|
+
if (j < 0) {
|
|
669
|
+
throw BadSyntax(this._thisDoc, this.lines, str, i, "EOF when objectList expected after [ = ");
|
|
945
670
|
}
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
while (1) {
|
|
950
|
-
var i = this.skipSpace(str, j);
|
|
951
|
-
|
|
952
|
-
if (i < 0) {
|
|
953
|
-
throw BadSyntax(this._thisDoc, this.lines, str, i, "needed '}', found end.");
|
|
954
|
-
}
|
|
955
|
-
|
|
956
|
-
if (str.slice(i, i + 1) == "}") {
|
|
957
|
-
var j = i + 1;
|
|
958
|
-
break;
|
|
959
|
-
}
|
|
960
|
-
|
|
961
|
-
var j = this.directiveOrStatement(str, i);
|
|
962
|
-
|
|
963
|
-
if (j < 0) {
|
|
964
|
-
throw BadSyntax(this._thisDoc, this.lines, str, i, "expected statement or '}'");
|
|
965
|
-
}
|
|
671
|
+
if (str.slice(j, j + 1) == ";") {
|
|
672
|
+
var j = j + 1;
|
|
966
673
|
}
|
|
967
|
-
|
|
968
|
-
this.
|
|
969
|
-
this._variables = this._parentVariables;
|
|
970
|
-
this._parentVariables = grandParentVariables;
|
|
971
|
-
this._context = this._parentContext;
|
|
972
|
-
this._reason2 = reason2;
|
|
973
|
-
this._parentContext = oldParentContext;
|
|
974
|
-
res.push(subj.close());
|
|
975
|
-
return j;
|
|
674
|
+
} else {
|
|
675
|
+
throw BadSyntax(this._thisDoc, this.lines, str, i, "objectList expected after [= ");
|
|
976
676
|
}
|
|
977
677
|
}
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
678
|
+
if (subj == null) {
|
|
679
|
+
var subj = this.blankNode(bnodeID);
|
|
680
|
+
}
|
|
681
|
+
var i = this.property_list(str, j, subj);
|
|
682
|
+
if (i < 0) {
|
|
683
|
+
throw BadSyntax(this._thisDoc, this.lines, str, j, "property_list expected");
|
|
684
|
+
}
|
|
685
|
+
var j = this.skipSpace(str, i);
|
|
686
|
+
if (j < 0) {
|
|
687
|
+
throw BadSyntax(this._thisDoc, this.lines, str, i, "EOF when ']' expected after [ <propertyList>");
|
|
688
|
+
}
|
|
689
|
+
if (str.slice(j, j + 1) != "]") {
|
|
690
|
+
throw BadSyntax(this._thisDoc, this.lines, str, j, "']' expected");
|
|
691
|
+
}
|
|
692
|
+
res.push(subj);
|
|
693
|
+
return j + 1;
|
|
694
|
+
}
|
|
695
|
+
if (ch == "{") {
|
|
696
|
+
var ch2 = str.slice(i + 1, i + 2);
|
|
697
|
+
if (ch2 == "$") {
|
|
698
|
+
i += 1;
|
|
988
699
|
var j = i + 1;
|
|
989
700
|
var mylist = new pyjslib_List([]);
|
|
990
|
-
|
|
701
|
+
var first_run = true;
|
|
991
702
|
while (1) {
|
|
992
703
|
var i = this.skipSpace(str, j);
|
|
993
|
-
|
|
994
704
|
if (i < 0) {
|
|
995
|
-
throw BadSyntax(this._thisDoc, this.lines, str, i, "needed '
|
|
705
|
+
throw BadSyntax(this._thisDoc, this.lines, str, i, "needed '$}', found end.");
|
|
996
706
|
}
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
var j = i + 1;
|
|
707
|
+
if (str.slice(i, i + 2) == "$}") {
|
|
708
|
+
var j = i + 2;
|
|
1000
709
|
break;
|
|
1001
710
|
}
|
|
1002
|
-
|
|
711
|
+
if (!first_run) {
|
|
712
|
+
if (str.slice(i, i + 1) == ",") {
|
|
713
|
+
i += 1;
|
|
714
|
+
} else {
|
|
715
|
+
throw BadSyntax(this._thisDoc, this.lines, str, i, "expected: ','");
|
|
716
|
+
}
|
|
717
|
+
} else {
|
|
718
|
+
var first_run = false;
|
|
719
|
+
}
|
|
1003
720
|
var item = new pyjslib_List([]);
|
|
1004
721
|
var j = this.item(str, i, item);
|
|
1005
|
-
|
|
1006
722
|
if (j < 0) {
|
|
1007
|
-
throw BadSyntax(this._thisDoc, this.lines, str, i, "expected item in
|
|
723
|
+
throw BadSyntax(this._thisDoc, this.lines, str, i, "expected item in set or '$}'");
|
|
1008
724
|
}
|
|
1009
|
-
|
|
1010
725
|
mylist.push(item[0]);
|
|
1011
726
|
}
|
|
1012
|
-
|
|
1013
|
-
res.push(thing_type(mylist, this._context));
|
|
1014
|
-
return j;
|
|
1015
|
-
}
|
|
1016
|
-
|
|
1017
|
-
var j = this.tok("this", str, i);
|
|
1018
|
-
|
|
1019
|
-
if (j >= 0) {
|
|
1020
|
-
throw BadSyntax(this._thisDoc, this.lines, str, i, "Keyword 'this' was ancient N3. Now use @forSome and @forAll keywords.");
|
|
1021
|
-
res.push(this._context);
|
|
1022
|
-
return j;
|
|
1023
|
-
}
|
|
1024
|
-
|
|
1025
|
-
var j = this.tok("true", str, i);
|
|
1026
|
-
|
|
1027
|
-
if (j >= 0) {
|
|
1028
|
-
res.push(true);
|
|
1029
|
-
return j;
|
|
1030
|
-
}
|
|
1031
|
-
|
|
1032
|
-
var j = this.tok("false", str, i);
|
|
1033
|
-
|
|
1034
|
-
if (j >= 0) {
|
|
1035
|
-
res.push(false);
|
|
727
|
+
res.push(this._store.newSet(mylist, this._context));
|
|
1036
728
|
return j;
|
|
1037
|
-
}
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
key: "property_list",
|
|
1051
|
-
value: function property_list(str, i, subj) {
|
|
1052
|
-
/*
|
|
1053
|
-
Parse property list
|
|
1054
|
-
Leaves the terminating punctuation in the buffer
|
|
1055
|
-
*/
|
|
1056
|
-
while (1) {
|
|
1057
|
-
var j = this.skipSpace(str, i);
|
|
1058
|
-
|
|
1059
|
-
if (j < 0) {
|
|
1060
|
-
throw BadSyntax(this._thisDoc, this.lines, str, i, "EOF found when expected verb in property list");
|
|
1061
|
-
return j;
|
|
729
|
+
} else {
|
|
730
|
+
var j = i + 1;
|
|
731
|
+
var oldParentContext = this._parentContext;
|
|
732
|
+
this._parentContext = this._context;
|
|
733
|
+
var parentAnonymousNodes = this._anonymousNodes;
|
|
734
|
+
var grandParentVariables = this._parentVariables;
|
|
735
|
+
this._parentVariables = this._variables;
|
|
736
|
+
this._anonymousNodes = new pyjslib_Dict([]);
|
|
737
|
+
this._variables = this._variables.slice();
|
|
738
|
+
var reason2 = this._reason2;
|
|
739
|
+
this._reason2 = becauseSubexpression;
|
|
740
|
+
if (subj == null) {
|
|
741
|
+
var subj = this._store.formula();
|
|
1062
742
|
}
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
var i = j
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
|
|
743
|
+
this._context = subj;
|
|
744
|
+
while (1) {
|
|
745
|
+
var i = this.skipSpace(str, j);
|
|
746
|
+
if (i < 0) {
|
|
747
|
+
throw BadSyntax(this._thisDoc, this.lines, str, i, "needed '}', found end.");
|
|
748
|
+
}
|
|
749
|
+
if (str.slice(i, i + 1) == "}") {
|
|
750
|
+
var j = i + 1;
|
|
751
|
+
break;
|
|
752
|
+
}
|
|
753
|
+
var j = this.directiveOrStatement(str, i);
|
|
1069
754
|
if (j < 0) {
|
|
1070
|
-
throw BadSyntax(this._thisDoc, this.lines, str, i, "
|
|
755
|
+
throw BadSyntax(this._thisDoc, this.lines, str, i, "expected statement or '}'");
|
|
1071
756
|
}
|
|
1072
|
-
|
|
1073
|
-
var i = j;
|
|
1074
|
-
continue;
|
|
1075
|
-
}
|
|
1076
|
-
|
|
1077
|
-
var i = j;
|
|
1078
|
-
var v = new pyjslib_List([]);
|
|
1079
|
-
var j = this.verb(str, i, v);
|
|
1080
|
-
|
|
1081
|
-
if (j <= 0) {
|
|
1082
|
-
return i;
|
|
1083
757
|
}
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
|
|
758
|
+
this._anonymousNodes = parentAnonymousNodes;
|
|
759
|
+
this._variables = this._parentVariables;
|
|
760
|
+
this._parentVariables = grandParentVariables;
|
|
761
|
+
this._context = this._parentContext;
|
|
762
|
+
this._reason2 = reason2;
|
|
763
|
+
this._parentContext = oldParentContext;
|
|
764
|
+
res.push(subj.close());
|
|
765
|
+
return j;
|
|
766
|
+
}
|
|
767
|
+
}
|
|
768
|
+
if (ch == "(") {
|
|
769
|
+
var thing_type = this._store.list;
|
|
770
|
+
var ch2 = str.slice(i + 1, i + 2);
|
|
771
|
+
if (ch2 == "$") {
|
|
772
|
+
var thing_type = this._store.newSet;
|
|
773
|
+
i += 1;
|
|
774
|
+
}
|
|
775
|
+
var j = i + 1;
|
|
776
|
+
var mylist = new pyjslib_List([]);
|
|
777
|
+
while (1) {
|
|
778
|
+
var i = this.skipSpace(str, j);
|
|
1088
779
|
if (i < 0) {
|
|
1089
|
-
throw BadSyntax(this._thisDoc, this.lines, str,
|
|
780
|
+
throw BadSyntax(this._thisDoc, this.lines, str, i, "needed ')', found end.");
|
|
1090
781
|
}
|
|
1091
|
-
|
|
1092
|
-
|
|
1093
|
-
|
|
1094
|
-
try {
|
|
1095
|
-
while (true) {
|
|
1096
|
-
var obj = __obj.next();
|
|
1097
|
-
|
|
1098
|
-
var pairFudge = v[0];
|
|
1099
|
-
var dir = pairFudge[0];
|
|
1100
|
-
var sym = pairFudge[1];
|
|
1101
|
-
|
|
1102
|
-
if (dir == "->") {
|
|
1103
|
-
this.makeStatement(new pyjslib_Tuple([this._context, sym, subj, obj]));
|
|
1104
|
-
} else {
|
|
1105
|
-
this.makeStatement(new pyjslib_Tuple([this._context, sym, obj, subj]));
|
|
1106
|
-
}
|
|
1107
|
-
}
|
|
1108
|
-
} catch (e) {
|
|
1109
|
-
if (e != StopIteration) {
|
|
1110
|
-
throw e;
|
|
1111
|
-
}
|
|
782
|
+
if (str.slice(i, i + 1) == ")") {
|
|
783
|
+
var j = i + 1;
|
|
784
|
+
break;
|
|
1112
785
|
}
|
|
1113
|
-
|
|
1114
|
-
var j = this.
|
|
1115
|
-
|
|
786
|
+
var item = new pyjslib_List([]);
|
|
787
|
+
var j = this.item(str, i, item);
|
|
1116
788
|
if (j < 0) {
|
|
1117
|
-
throw BadSyntax(this._thisDoc, this.lines, str,
|
|
1118
|
-
return j;
|
|
1119
|
-
}
|
|
1120
|
-
|
|
1121
|
-
if (str.slice(i, i + 1) != ";") {
|
|
1122
|
-
return i;
|
|
789
|
+
throw BadSyntax(this._thisDoc, this.lines, str, i, "expected item in list or ')'");
|
|
1123
790
|
}
|
|
1124
|
-
|
|
1125
|
-
var i = i + 1;
|
|
791
|
+
mylist.push(item[0]);
|
|
1126
792
|
}
|
|
793
|
+
res.push(thing_type(mylist, this._context));
|
|
794
|
+
return j;
|
|
1127
795
|
}
|
|
1128
|
-
|
|
1129
|
-
|
|
1130
|
-
|
|
1131
|
-
|
|
1132
|
-
return
|
|
1133
|
-
|
|
1134
|
-
|
|
1135
|
-
|
|
1136
|
-
|
|
1137
|
-
|
|
1138
|
-
|
|
1139
|
-
|
|
1140
|
-
|
|
1141
|
-
|
|
1142
|
-
|
|
1143
|
-
|
|
1144
|
-
|
|
796
|
+
var j = this.tok("this", str, i);
|
|
797
|
+
if (j >= 0) {
|
|
798
|
+
throw BadSyntax(this._thisDoc, this.lines, str, i, "Keyword 'this' was ancient N3. Now use @forSome and @forAll keywords.");
|
|
799
|
+
res.push(this._context);
|
|
800
|
+
return j;
|
|
801
|
+
}
|
|
802
|
+
var j = this.tok("true", str, i);
|
|
803
|
+
if (j >= 0) {
|
|
804
|
+
res.push(true);
|
|
805
|
+
return j;
|
|
806
|
+
}
|
|
807
|
+
var j = this.tok("false", str, i);
|
|
808
|
+
if (j >= 0) {
|
|
809
|
+
res.push(false);
|
|
810
|
+
return j;
|
|
811
|
+
}
|
|
812
|
+
if (subj == null) {
|
|
813
|
+
var j = this.uri_ref2(str, i, res);
|
|
814
|
+
if (j >= 0) {
|
|
1145
815
|
return j;
|
|
1146
816
|
}
|
|
817
|
+
}
|
|
818
|
+
return -1;
|
|
819
|
+
}
|
|
820
|
+
property_list(str, i, subj) {
|
|
821
|
+
/*
|
|
822
|
+
Parse property list
|
|
823
|
+
Leaves the terminating punctuation in the buffer
|
|
824
|
+
*/
|
|
1147
825
|
|
|
1148
|
-
|
|
1149
|
-
|
|
1150
|
-
|
|
1151
|
-
|
|
1152
|
-
|
|
1153
|
-
|
|
1154
|
-
if (i < 0) {
|
|
1155
|
-
return -1;
|
|
826
|
+
while (1) {
|
|
827
|
+
var j = this.skipSpace(str, i);
|
|
828
|
+
if (j < 0) {
|
|
829
|
+
throw BadSyntax(this._thisDoc, this.lines, str, i, "EOF found when expected verb in property list");
|
|
830
|
+
return j;
|
|
1156
831
|
}
|
|
1157
|
-
|
|
1158
|
-
|
|
1159
|
-
var
|
|
1160
|
-
|
|
832
|
+
if (str.slice(j, j + 2) == ":-") {
|
|
833
|
+
var i = j + 2;
|
|
834
|
+
var res = new pyjslib_List([]);
|
|
835
|
+
var j = this.node(str, i, res, subj);
|
|
1161
836
|
if (j < 0) {
|
|
1162
|
-
|
|
837
|
+
throw BadSyntax(this._thisDoc, this.lines, str, i, "bad {} or () or [] node after :- ");
|
|
1163
838
|
}
|
|
1164
|
-
|
|
1165
|
-
|
|
1166
|
-
|
|
1167
|
-
|
|
1168
|
-
|
|
1169
|
-
|
|
839
|
+
var i = j;
|
|
840
|
+
continue;
|
|
841
|
+
}
|
|
842
|
+
var i = j;
|
|
843
|
+
var v = new pyjslib_List([]);
|
|
844
|
+
var j = this.verb(str, i, v);
|
|
845
|
+
if (j <= 0) {
|
|
846
|
+
return i;
|
|
847
|
+
}
|
|
848
|
+
var objs = new pyjslib_List([]);
|
|
849
|
+
var i = this.objectList(str, j, objs);
|
|
850
|
+
if (i < 0) {
|
|
851
|
+
throw BadSyntax(this._thisDoc, this.lines, str, j, "objectList expected");
|
|
852
|
+
}
|
|
853
|
+
var __obj = new pyjslib_Iterator(objs);
|
|
854
|
+
try {
|
|
855
|
+
while (true) {
|
|
856
|
+
var obj = __obj.next();
|
|
857
|
+
var pairFudge = v[0];
|
|
858
|
+
var dir = pairFudge[0];
|
|
859
|
+
var sym = pairFudge[1];
|
|
860
|
+
if (dir == "->") {
|
|
861
|
+
this.makeStatement(new pyjslib_Tuple([this._context, sym, subj, obj]));
|
|
862
|
+
} else {
|
|
863
|
+
this.makeStatement(new pyjslib_Tuple([this._context, sym, obj, subj]));
|
|
1170
864
|
}
|
|
1171
|
-
|
|
1172
|
-
return j;
|
|
1173
865
|
}
|
|
1174
|
-
|
|
1175
|
-
if (
|
|
1176
|
-
|
|
1177
|
-
} else {
|
|
1178
|
-
var i = this.bareWord(str, j + 1, res);
|
|
1179
|
-
}
|
|
1180
|
-
|
|
1181
|
-
if (i < 0) {
|
|
1182
|
-
throw BadSyntax(this._thisDoc, this.lines, str, i, "bad list content");
|
|
1183
|
-
return i;
|
|
866
|
+
} catch (e) {
|
|
867
|
+
if (e != StopIteration) {
|
|
868
|
+
throw e;
|
|
1184
869
|
}
|
|
1185
870
|
}
|
|
1186
|
-
|
|
1187
|
-
|
|
1188
|
-
|
|
1189
|
-
|
|
1190
|
-
var i = this.object(str, i, res);
|
|
1191
|
-
|
|
1192
|
-
if (i < 0) {
|
|
1193
|
-
return -1;
|
|
871
|
+
var j = this.skipSpace(str, i);
|
|
872
|
+
if (j < 0) {
|
|
873
|
+
throw BadSyntax(this._thisDoc, this.lines, str, j, "EOF found in list of objects");
|
|
874
|
+
return j;
|
|
1194
875
|
}
|
|
1195
|
-
|
|
1196
|
-
|
|
1197
|
-
var j = this.skipSpace(str, i);
|
|
1198
|
-
|
|
1199
|
-
if (j < 0) {
|
|
1200
|
-
throw BadSyntax(this._thisDoc, this.lines, str, j, "EOF found after object");
|
|
1201
|
-
return j;
|
|
1202
|
-
}
|
|
1203
|
-
|
|
1204
|
-
if (str.slice(j, j + 1) != ",") {
|
|
1205
|
-
return j;
|
|
1206
|
-
}
|
|
1207
|
-
|
|
1208
|
-
var i = this.object(str, j + 1, res);
|
|
1209
|
-
|
|
1210
|
-
if (i < 0) {
|
|
1211
|
-
return i;
|
|
1212
|
-
}
|
|
876
|
+
if (str.slice(i, i + 1) != ";") {
|
|
877
|
+
return i;
|
|
1213
878
|
}
|
|
879
|
+
var i = i + 1;
|
|
880
|
+
}
|
|
881
|
+
}
|
|
882
|
+
commaSeparatedList(str, j, res, ofUris) {
|
|
883
|
+
/*
|
|
884
|
+
return value: -1 bad syntax; >1 new position in str
|
|
885
|
+
res has things found appended
|
|
886
|
+
Used to use a final value of the function to be called, e.g. this.bareWord
|
|
887
|
+
but passing the function didn't work fo js converion pyjs
|
|
888
|
+
*/
|
|
889
|
+
|
|
890
|
+
var i = this.skipSpace(str, j);
|
|
891
|
+
if (i < 0) {
|
|
892
|
+
throw BadSyntax(this._thisDoc, this.lines, str, i, "EOF found expecting comma sep list");
|
|
893
|
+
return i;
|
|
894
|
+
}
|
|
895
|
+
if (str.charAt(i) == ".") {
|
|
896
|
+
return j;
|
|
1214
897
|
}
|
|
1215
|
-
|
|
1216
|
-
|
|
1217
|
-
|
|
898
|
+
if (ofUris) {
|
|
899
|
+
var i = this.uri_ref2(str, i, res);
|
|
900
|
+
} else {
|
|
901
|
+
var i = this.bareWord(str, i, res);
|
|
902
|
+
}
|
|
903
|
+
if (i < 0) {
|
|
904
|
+
return -1;
|
|
905
|
+
}
|
|
906
|
+
while (1) {
|
|
1218
907
|
var j = this.skipSpace(str, i);
|
|
1219
|
-
|
|
1220
908
|
if (j < 0) {
|
|
1221
909
|
return j;
|
|
1222
910
|
}
|
|
1223
|
-
|
|
1224
|
-
if (
|
|
1225
|
-
|
|
911
|
+
var ch = str.slice(j, j + 1);
|
|
912
|
+
if (ch != ",") {
|
|
913
|
+
if (ch != ".") {
|
|
914
|
+
return -1;
|
|
915
|
+
}
|
|
916
|
+
return j;
|
|
1226
917
|
}
|
|
1227
|
-
|
|
1228
|
-
|
|
918
|
+
if (ofUris) {
|
|
919
|
+
var i = this.uri_ref2(str, j + 1, res);
|
|
920
|
+
} else {
|
|
921
|
+
var i = this.bareWord(str, j + 1, res);
|
|
922
|
+
}
|
|
923
|
+
if (i < 0) {
|
|
924
|
+
throw BadSyntax(this._thisDoc, this.lines, str, i, "bad list content");
|
|
925
|
+
return i;
|
|
926
|
+
}
|
|
927
|
+
}
|
|
928
|
+
}
|
|
929
|
+
objectList(str, i, res) {
|
|
930
|
+
var i = this.object(str, i, res);
|
|
931
|
+
if (i < 0) {
|
|
932
|
+
return -1;
|
|
933
|
+
}
|
|
934
|
+
while (1) {
|
|
935
|
+
var j = this.skipSpace(str, i);
|
|
936
|
+
if (j < 0) {
|
|
937
|
+
throw BadSyntax(this._thisDoc, this.lines, str, j, "EOF found after object");
|
|
1229
938
|
return j;
|
|
1230
939
|
}
|
|
1231
|
-
|
|
1232
|
-
if (str.slice(j, j + 1) == "]") {
|
|
940
|
+
if (str.slice(j, j + 1) != ",") {
|
|
1233
941
|
return j;
|
|
1234
942
|
}
|
|
1235
|
-
|
|
1236
|
-
|
|
1237
|
-
|
|
943
|
+
var i = this.object(str, j + 1, res);
|
|
944
|
+
if (i < 0) {
|
|
945
|
+
return i;
|
|
946
|
+
}
|
|
1238
947
|
}
|
|
1239
|
-
}
|
|
1240
|
-
|
|
1241
|
-
|
|
1242
|
-
|
|
1243
|
-
|
|
1244
|
-
|
|
1245
|
-
|
|
1246
|
-
|
|
1247
|
-
|
|
1248
|
-
|
|
1249
|
-
|
|
1250
|
-
|
|
1251
|
-
|
|
1252
|
-
|
|
1253
|
-
|
|
1254
|
-
|
|
1255
|
-
|
|
1256
|
-
|
|
1257
|
-
|
|
1258
|
-
|
|
1259
|
-
|
|
1260
|
-
|
|
1261
|
-
|
|
1262
|
-
|
|
1263
|
-
|
|
1264
|
-
|
|
1265
|
-
|
|
1266
|
-
|
|
1267
|
-
|
|
1268
|
-
|
|
948
|
+
}
|
|
949
|
+
checkDot(str, i) {
|
|
950
|
+
var j = this.skipSpace(str, i);
|
|
951
|
+
if (j < 0) {
|
|
952
|
+
return j;
|
|
953
|
+
}
|
|
954
|
+
if (str.slice(j, j + 1) == ".") {
|
|
955
|
+
return j + 1;
|
|
956
|
+
}
|
|
957
|
+
if (str.slice(j, j + 1) == "}") {
|
|
958
|
+
return j;
|
|
959
|
+
}
|
|
960
|
+
if (str.slice(j, j + 1) == "]") {
|
|
961
|
+
return j;
|
|
962
|
+
}
|
|
963
|
+
throw BadSyntax(this._thisDoc, this.lines, str, j, "expected '.' or '}' or ']' at end of statement");
|
|
964
|
+
return i;
|
|
965
|
+
}
|
|
966
|
+
uri_ref2(str, i, res) {
|
|
967
|
+
/*
|
|
968
|
+
Generate uri from n3 representation.
|
|
969
|
+
Note that the RDF convention of directly concatenating
|
|
970
|
+
NS and local name is now used though I prefer inserting a '#'
|
|
971
|
+
to make the namesapces look more like what XML folks expect.
|
|
972
|
+
*/
|
|
973
|
+
|
|
974
|
+
var qn = new pyjslib_List([]);
|
|
975
|
+
var j = this.qname(str, i, qn);
|
|
976
|
+
if (j >= 0) {
|
|
977
|
+
var pairFudge = qn[0];
|
|
978
|
+
var pfx = pairFudge[0];
|
|
979
|
+
var ln = pairFudge[1];
|
|
980
|
+
if (pfx == null) {
|
|
981
|
+
assertFudge(0, "not used?");
|
|
982
|
+
var ns = this._baseURI + ADDED_HASH;
|
|
983
|
+
} else {
|
|
984
|
+
var ns = this._bindings[pfx];
|
|
985
|
+
if (!ns) {
|
|
986
|
+
if (pfx == "_") {
|
|
987
|
+
res.push(this.anonymousNode(ln));
|
|
988
|
+
return j;
|
|
1269
989
|
}
|
|
990
|
+
throw BadSyntax(this._thisDoc, this.lines, str, i, "Prefix " + pfx + " not bound.");
|
|
1270
991
|
}
|
|
1271
|
-
|
|
1272
|
-
var symb = this._store.sym(ns + ln);
|
|
1273
|
-
|
|
1274
|
-
if ((0, _utils.ArrayIndexOf)(this._variables, symb) >= 0) {
|
|
1275
|
-
res.push(this._variables[symb]);
|
|
1276
|
-
} else {
|
|
1277
|
-
res.push(symb);
|
|
1278
|
-
}
|
|
1279
|
-
|
|
1280
|
-
return j;
|
|
1281
992
|
}
|
|
1282
|
-
|
|
1283
|
-
|
|
1284
|
-
|
|
1285
|
-
|
|
1286
|
-
|
|
993
|
+
var symb = this._store.sym(ns + ln);
|
|
994
|
+
if ((0, _utils.ArrayIndexOf)(this._variables, symb) >= 0) {
|
|
995
|
+
res.push(this._variables[symb]);
|
|
996
|
+
} else {
|
|
997
|
+
res.push(symb);
|
|
1287
998
|
}
|
|
1288
|
-
|
|
1289
|
-
|
|
1290
|
-
|
|
1291
|
-
|
|
1292
|
-
|
|
1293
|
-
|
|
1294
|
-
|
|
1295
|
-
|
|
1296
|
-
|
|
1297
|
-
|
|
1298
|
-
|
|
1299
|
-
|
|
1300
|
-
|
|
1301
|
-
|
|
1302
|
-
|
|
1303
|
-
|
|
1304
|
-
|
|
1305
|
-
|
|
1306
|
-
|
|
1307
|
-
|
|
1308
|
-
|
|
1309
|
-
|
|
1310
|
-
|
|
1311
|
-
|
|
1312
|
-
|
|
1313
|
-
if (str.slice(i - 1, i) == "#" && !(pyjslib_slice(uref, -1, null) == "#")) {
|
|
1314
|
-
var uref = uref + "#";
|
|
1315
|
-
}
|
|
1316
|
-
|
|
1317
|
-
var symb = this._store.sym(uref);
|
|
1318
|
-
|
|
1319
|
-
if ((0, _utils.ArrayIndexOf)(this._variables, symb) >= 0) {
|
|
1320
|
-
res.push(this._variables[symb]);
|
|
1321
|
-
} else {
|
|
1322
|
-
res.push(symb);
|
|
1323
|
-
}
|
|
1324
|
-
|
|
1325
|
-
return i + 1;
|
|
999
|
+
return j;
|
|
1000
|
+
}
|
|
1001
|
+
var i = this.skipSpace(str, i);
|
|
1002
|
+
if (i < 0) {
|
|
1003
|
+
return -1;
|
|
1004
|
+
}
|
|
1005
|
+
if (str.charAt(i) == "?") {
|
|
1006
|
+
var v = new pyjslib_List([]);
|
|
1007
|
+
var j = this.variable(str, i, v);
|
|
1008
|
+
if (j > 0) {
|
|
1009
|
+
res.push(v[0]);
|
|
1010
|
+
return j;
|
|
1011
|
+
}
|
|
1012
|
+
return -1;
|
|
1013
|
+
} else if (str.charAt(i) == "<") {
|
|
1014
|
+
var i = i + 1;
|
|
1015
|
+
var st = i;
|
|
1016
|
+
while (i < pyjslib_len(str)) {
|
|
1017
|
+
if (str.charAt(i) == ">") {
|
|
1018
|
+
var uref = str.slice(st, i);
|
|
1019
|
+
if (this._baseURI) {
|
|
1020
|
+
var uref = uripath_join(this._baseURI, uref);
|
|
1021
|
+
} else {
|
|
1022
|
+
assertFudge(uref.indexOf(":") >= 0, "With no base URI, cannot deal with relative URIs");
|
|
1326
1023
|
}
|
|
1327
|
-
|
|
1328
|
-
|
|
1329
|
-
|
|
1330
|
-
|
|
1331
|
-
|
|
1332
|
-
|
|
1333
|
-
|
|
1334
|
-
|
|
1335
|
-
|
|
1336
|
-
|
|
1337
|
-
return -1;
|
|
1338
|
-
}
|
|
1339
|
-
|
|
1340
|
-
if ((0, _utils.ArrayIndexOf)(this.keywords, v[0]) >= 0) {
|
|
1341
|
-
throw BadSyntax(this._thisDoc, this.lines, str, i, "Keyword \"" + v[0] + "\" not allowed here.");
|
|
1024
|
+
if (str.slice(i - 1, i) == "#" && !(pyjslib_slice(uref, -1, null) == "#")) {
|
|
1025
|
+
var uref = uref + "#";
|
|
1026
|
+
}
|
|
1027
|
+
var symb = this._store.sym(uref);
|
|
1028
|
+
if ((0, _utils.ArrayIndexOf)(this._variables, symb) >= 0) {
|
|
1029
|
+
res.push(this._variables[symb]);
|
|
1030
|
+
} else {
|
|
1031
|
+
res.push(symb);
|
|
1032
|
+
}
|
|
1033
|
+
return i + 1;
|
|
1342
1034
|
}
|
|
1343
|
-
|
|
1344
|
-
|
|
1345
|
-
|
|
1346
|
-
|
|
1035
|
+
var i = i + 1;
|
|
1036
|
+
}
|
|
1037
|
+
throw BadSyntax(this._thisDoc, this.lines, str, j, "unterminated URI reference");
|
|
1038
|
+
} else if (this.keywordsSet) {
|
|
1039
|
+
var v = new pyjslib_List([]);
|
|
1040
|
+
var j = this.bareWord(str, i, v);
|
|
1041
|
+
if (j < 0) {
|
|
1347
1042
|
return -1;
|
|
1348
1043
|
}
|
|
1044
|
+
if ((0, _utils.ArrayIndexOf)(this.keywords, v[0]) >= 0) {
|
|
1045
|
+
throw BadSyntax(this._thisDoc, this.lines, str, i, "Keyword \"" + v[0] + "\" not allowed here.");
|
|
1046
|
+
}
|
|
1047
|
+
res.push(this._store.sym(this._bindings[""] + v[0]));
|
|
1048
|
+
return j;
|
|
1049
|
+
} else {
|
|
1050
|
+
return -1;
|
|
1349
1051
|
}
|
|
1350
|
-
}
|
|
1351
|
-
|
|
1352
|
-
|
|
1353
|
-
|
|
1354
|
-
|
|
1355
|
-
return -1 if EOF, else position of first non-ws character*/
|
|
1356
|
-
var whitespace = " \n\r\t\f\x0B\xA0\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200A\u200B\u2028\u2029\u3000";
|
|
1357
|
-
|
|
1358
|
-
for (var j = i ? i : 0; j < str.length; j++) {
|
|
1359
|
-
var ch = str.charAt(j); // console.log(" skipspace j= "+j + " i= " + i + " n= " + str.length);
|
|
1360
|
-
// console.log(" skipspace ch <" + ch + ">");
|
|
1361
|
-
|
|
1362
|
-
if (whitespace.indexOf(ch) < 0) {
|
|
1363
|
-
//not ws
|
|
1364
|
-
// console.log(" skipspace 2 ch <" + ch + ">");
|
|
1365
|
-
if (str.charAt(j) === '#') {
|
|
1366
|
-
for (;; j++) {
|
|
1367
|
-
// console.log(" skipspace2 j= "+j + " i= " + i + " n= " + str.length);
|
|
1368
|
-
if (j === str.length) {
|
|
1369
|
-
return -1; // EOF
|
|
1370
|
-
}
|
|
1052
|
+
}
|
|
1053
|
+
skipSpace(str, i) {
|
|
1054
|
+
/*
|
|
1055
|
+
Skip white space, newlines and comments.
|
|
1056
|
+
return -1 if EOF, else position of first non-ws character*/
|
|
1371
1057
|
|
|
1372
|
-
|
|
1373
|
-
|
|
1374
|
-
|
|
1375
|
-
|
|
1058
|
+
var whitespace = ' \n\r\t\f\x0b\xa0\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200a\u200b\u2028\u2029\u3000';
|
|
1059
|
+
for (var j = i ? i : 0; j < str.length; j++) {
|
|
1060
|
+
var ch = str.charAt(j);
|
|
1061
|
+
// console.log(" skipspace j= "+j + " i= " + i + " n= " + str.length);
|
|
1062
|
+
// console.log(" skipspace ch <" + ch + ">");
|
|
1063
|
+
if (whitespace.indexOf(ch) < 0) {
|
|
1064
|
+
//not ws
|
|
1065
|
+
// console.log(" skipspace 2 ch <" + ch + ">");
|
|
1066
|
+
if (str.charAt(j) === '#') {
|
|
1067
|
+
for (;; j++) {
|
|
1068
|
+
// console.log(" skipspace2 j= "+j + " i= " + i + " n= " + str.length);
|
|
1069
|
+
if (j === str.length) {
|
|
1070
|
+
return -1; // EOF
|
|
1376
1071
|
}
|
|
1377
1072
|
|
|
1378
|
-
|
|
1379
|
-
|
|
1380
|
-
|
|
1381
|
-
|
|
1382
|
-
return j;
|
|
1073
|
+
if (str.charAt(j) === '\n') {
|
|
1074
|
+
this.lines = this.lines + 1;
|
|
1075
|
+
break;
|
|
1076
|
+
}
|
|
1383
1077
|
}
|
|
1078
|
+
;
|
|
1384
1079
|
} else {
|
|
1385
|
-
//
|
|
1386
|
-
// console.log(" skipspace
|
|
1387
|
-
|
|
1388
|
-
|
|
1389
|
-
|
|
1080
|
+
// Not hash - something interesting
|
|
1081
|
+
// console.log(" skipspace 3 ch <" + ch + ">");
|
|
1082
|
+
return j;
|
|
1083
|
+
}
|
|
1084
|
+
} else {
|
|
1085
|
+
// Whitespace
|
|
1086
|
+
// console.log(" skipspace 5 ch <" + ch + ">");
|
|
1087
|
+
if (str.charAt(j) === '\n') {
|
|
1088
|
+
this.lines = this.lines + 1;
|
|
1390
1089
|
}
|
|
1391
|
-
} // next j
|
|
1392
|
-
|
|
1393
|
-
|
|
1394
|
-
return -1; // EOF
|
|
1395
|
-
}
|
|
1396
|
-
}, {
|
|
1397
|
-
key: "variable",
|
|
1398
|
-
value: function variable(str, i, res) {
|
|
1399
|
-
/*
|
|
1400
|
-
?abc -> variable(:abc)
|
|
1401
|
-
*/
|
|
1402
|
-
var j = this.skipSpace(str, i);
|
|
1403
|
-
|
|
1404
|
-
if (j < 0) {
|
|
1405
|
-
return -1;
|
|
1406
1090
|
}
|
|
1091
|
+
} // next j
|
|
1092
|
+
return -1; // EOF
|
|
1093
|
+
}
|
|
1407
1094
|
|
|
1408
|
-
|
|
1409
|
-
|
|
1410
|
-
|
|
1095
|
+
variable(str, i, res) {
|
|
1096
|
+
/*
|
|
1097
|
+
?abc -> variable(:abc)
|
|
1098
|
+
*/
|
|
1411
1099
|
|
|
1412
|
-
|
|
1413
|
-
|
|
1100
|
+
var j = this.skipSpace(str, i);
|
|
1101
|
+
if (j < 0) {
|
|
1102
|
+
return -1;
|
|
1103
|
+
}
|
|
1104
|
+
if (str.slice(j, j + 1) != "?") {
|
|
1105
|
+
return -1;
|
|
1106
|
+
}
|
|
1107
|
+
var j = j + 1;
|
|
1108
|
+
var i = j;
|
|
1109
|
+
if ("0123456789-".indexOf(str.charAt(j)) >= 0) {
|
|
1110
|
+
throw BadSyntax(this._thisDoc, this.lines, str, j, "Varible name can't start with '" + str.charAt(j) + "s'");
|
|
1111
|
+
return -1;
|
|
1112
|
+
}
|
|
1113
|
+
while (i < pyjslib_len(str) && _notNameChars.indexOf(str.charAt(i)) < 0) {
|
|
1114
|
+
var i = i + 1;
|
|
1115
|
+
}
|
|
1116
|
+
if (this._parentContext == null) {
|
|
1117
|
+
throw BadSyntax(this._thisDoc, this.lines, str, j, "Can't use ?xxx syntax for variable in outermost level: " + str.slice(j - 1, i));
|
|
1118
|
+
}
|
|
1119
|
+
res.push(this._store.variable(str.slice(j, i)));
|
|
1120
|
+
return i;
|
|
1121
|
+
}
|
|
1122
|
+
bareWord(str, i, res) {
|
|
1123
|
+
/*
|
|
1124
|
+
abc -> :abc
|
|
1125
|
+
*/
|
|
1414
1126
|
|
|
1415
|
-
|
|
1416
|
-
|
|
1417
|
-
|
|
1418
|
-
|
|
1127
|
+
var j = this.skipSpace(str, i);
|
|
1128
|
+
if (j < 0) {
|
|
1129
|
+
return -1;
|
|
1130
|
+
}
|
|
1131
|
+
var ch = str.charAt(j);
|
|
1132
|
+
if ("0123456789-".indexOf(ch) >= 0) {
|
|
1133
|
+
return -1;
|
|
1134
|
+
}
|
|
1135
|
+
if (_notNameChars.indexOf(ch) >= 0) {
|
|
1136
|
+
return -1;
|
|
1137
|
+
}
|
|
1138
|
+
var i = j;
|
|
1139
|
+
while (i < pyjslib_len(str) && _notNameChars.indexOf(str.charAt(i)) < 0) {
|
|
1140
|
+
var i = i + 1;
|
|
1141
|
+
}
|
|
1142
|
+
res.push(str.slice(j, i));
|
|
1143
|
+
return i;
|
|
1144
|
+
}
|
|
1145
|
+
qname(str, i, res) {
|
|
1146
|
+
/*
|
|
1147
|
+
xyz:def -> ('xyz', 'def')
|
|
1148
|
+
If not in keywords and keywordsSet: def -> ('', 'def')
|
|
1149
|
+
:def -> ('', 'def')
|
|
1150
|
+
*/
|
|
1419
1151
|
|
|
1420
|
-
|
|
1421
|
-
|
|
1152
|
+
var i = this.skipSpace(str, i);
|
|
1153
|
+
if (i < 0) {
|
|
1154
|
+
return -1;
|
|
1155
|
+
}
|
|
1156
|
+
var c = str.charAt(i);
|
|
1157
|
+
if ("0123456789-+".indexOf(c) >= 0) {
|
|
1158
|
+
return -1;
|
|
1159
|
+
}
|
|
1160
|
+
if (_notNameChars.indexOf(c) < 0) {
|
|
1161
|
+
var ln = c;
|
|
1162
|
+
var i = i + 1;
|
|
1163
|
+
while (i < pyjslib_len(str)) {
|
|
1164
|
+
var c = str.charAt(i);
|
|
1165
|
+
if (_notNameChars.indexOf(c) < 0) {
|
|
1166
|
+
var ln = ln + c;
|
|
1167
|
+
var i = i + 1;
|
|
1168
|
+
} else {
|
|
1169
|
+
break;
|
|
1170
|
+
}
|
|
1422
1171
|
}
|
|
1423
|
-
|
|
1424
|
-
|
|
1425
|
-
|
|
1172
|
+
} else {
|
|
1173
|
+
var ln = "";
|
|
1174
|
+
}
|
|
1175
|
+
if (i < pyjslib_len(str) && str.charAt(i) == ":") {
|
|
1176
|
+
var pfx = ln;
|
|
1177
|
+
var i = i + 1;
|
|
1178
|
+
var ln = "";
|
|
1179
|
+
while (i < pyjslib_len(str)) {
|
|
1180
|
+
var c = str.charAt(i);
|
|
1181
|
+
if (_notNameChars.indexOf(c) < 0) {
|
|
1182
|
+
var ln = ln + c;
|
|
1183
|
+
var i = i + 1;
|
|
1184
|
+
} else {
|
|
1185
|
+
break;
|
|
1186
|
+
}
|
|
1426
1187
|
}
|
|
1427
|
-
|
|
1428
|
-
res.push(this._store.variable(str.slice(j, i)));
|
|
1188
|
+
res.push(new pyjslib_Tuple([pfx, ln]));
|
|
1429
1189
|
return i;
|
|
1190
|
+
} else {
|
|
1191
|
+
if (ln && this.keywordsSet && (0, _utils.ArrayIndexOf)(this.keywords, ln) < 0) {
|
|
1192
|
+
res.push(new pyjslib_Tuple(["", ln]));
|
|
1193
|
+
return i;
|
|
1194
|
+
}
|
|
1195
|
+
return -1;
|
|
1430
1196
|
}
|
|
1431
|
-
}
|
|
1432
|
-
|
|
1433
|
-
|
|
1434
|
-
|
|
1435
|
-
|
|
1436
|
-
|
|
1197
|
+
}
|
|
1198
|
+
object(str, i, res) {
|
|
1199
|
+
var j = this.subject(str, i, res);
|
|
1200
|
+
if (j >= 0) {
|
|
1201
|
+
return j;
|
|
1202
|
+
} else {
|
|
1437
1203
|
var j = this.skipSpace(str, i);
|
|
1438
|
-
|
|
1439
1204
|
if (j < 0) {
|
|
1440
1205
|
return -1;
|
|
1206
|
+
} else {
|
|
1207
|
+
var i = j;
|
|
1441
1208
|
}
|
|
1442
|
-
|
|
1443
|
-
|
|
1444
|
-
|
|
1445
|
-
|
|
1446
|
-
|
|
1447
|
-
|
|
1448
|
-
|
|
1449
|
-
|
|
1209
|
+
var delim = null;
|
|
1210
|
+
let ch = str.charAt(i);
|
|
1211
|
+
if (ch == "\"" || ch == "'") {
|
|
1212
|
+
if (str.slice(i, i + 3 == ch + ch)) {
|
|
1213
|
+
delim = ch + ch + ch;
|
|
1214
|
+
} else {
|
|
1215
|
+
delim = ch;
|
|
1216
|
+
}
|
|
1217
|
+
var i = i + pyjslib_len(delim);
|
|
1218
|
+
var pairFudge = this.strconst(str, i, delim);
|
|
1219
|
+
var j = pairFudge[0];
|
|
1220
|
+
var s = pairFudge[1];
|
|
1221
|
+
res.push(this._store.literal(s));
|
|
1222
|
+
diag_progress("New string const ", s, j);
|
|
1223
|
+
return j;
|
|
1224
|
+
} else {
|
|
1450
1225
|
return -1;
|
|
1451
1226
|
}
|
|
1452
|
-
|
|
1453
|
-
var i = j;
|
|
1454
|
-
|
|
1455
|
-
while (i < pyjslib_len(str) && _notNameChars.indexOf(str.charAt(i)) < 0) {
|
|
1456
|
-
var i = i + 1;
|
|
1457
|
-
}
|
|
1458
|
-
|
|
1459
|
-
res.push(str.slice(j, i));
|
|
1460
|
-
return i;
|
|
1461
1227
|
}
|
|
1462
|
-
}
|
|
1463
|
-
|
|
1464
|
-
|
|
1465
|
-
|
|
1466
|
-
|
|
1467
|
-
|
|
1468
|
-
|
|
1469
|
-
|
|
1470
|
-
var i = this.skipSpace(str, i);
|
|
1471
|
-
|
|
1472
|
-
if (i < 0) {
|
|
1473
|
-
return -1;
|
|
1474
|
-
}
|
|
1475
|
-
|
|
1476
|
-
var c = str.charAt(i);
|
|
1477
|
-
|
|
1478
|
-
if ("0123456789-+".indexOf(c) >= 0) {
|
|
1228
|
+
}
|
|
1229
|
+
nodeOrLiteral(str, i, res) {
|
|
1230
|
+
var j = this.node(str, i, res);
|
|
1231
|
+
if (j >= 0) {
|
|
1232
|
+
return j;
|
|
1233
|
+
} else {
|
|
1234
|
+
var j = this.skipSpace(str, i);
|
|
1235
|
+
if (j < 0) {
|
|
1479
1236
|
return -1;
|
|
1480
|
-
}
|
|
1481
|
-
|
|
1482
|
-
if (_notNameChars.indexOf(c) < 0) {
|
|
1483
|
-
var ln = c;
|
|
1484
|
-
var i = i + 1;
|
|
1485
|
-
|
|
1486
|
-
while (i < pyjslib_len(str)) {
|
|
1487
|
-
var c = str.charAt(i);
|
|
1488
|
-
|
|
1489
|
-
if (_notNameChars.indexOf(c) < 0) {
|
|
1490
|
-
var ln = ln + c;
|
|
1491
|
-
var i = i + 1;
|
|
1492
|
-
} else {
|
|
1493
|
-
break;
|
|
1494
|
-
}
|
|
1495
|
-
}
|
|
1496
1237
|
} else {
|
|
1497
|
-
var
|
|
1238
|
+
var i = j;
|
|
1498
1239
|
}
|
|
1499
|
-
|
|
1500
|
-
if (
|
|
1501
|
-
|
|
1502
|
-
var
|
|
1503
|
-
|
|
1504
|
-
|
|
1505
|
-
|
|
1506
|
-
|
|
1507
|
-
|
|
1508
|
-
|
|
1509
|
-
var ln = ln + c;
|
|
1510
|
-
var i = i + 1;
|
|
1240
|
+
var ch = str.charAt(i);
|
|
1241
|
+
if ("-+0987654321".indexOf(ch) >= 0) {
|
|
1242
|
+
datetime_syntax.lastIndex = 0;
|
|
1243
|
+
var m = datetime_syntax.exec(str.slice(i));
|
|
1244
|
+
if (m != null) {
|
|
1245
|
+
// j = ( i + datetime_syntax.lastIndex ) ;
|
|
1246
|
+
var val = m[0];
|
|
1247
|
+
j = i + val.length;
|
|
1248
|
+
if (val.indexOf("T") >= 0) {
|
|
1249
|
+
res.push(this._store.literal(val, this._store.sym(DATETIME_DATATYPE)));
|
|
1511
1250
|
} else {
|
|
1512
|
-
|
|
1251
|
+
res.push(this._store.literal(val, this._store.sym(DATE_DATATYPE)));
|
|
1513
1252
|
}
|
|
1514
|
-
}
|
|
1515
|
-
|
|
1516
|
-
res.push(new pyjslib_Tuple([pfx, ln]));
|
|
1517
|
-
return i;
|
|
1518
|
-
} else {
|
|
1519
|
-
if (ln && this.keywordsSet && (0, _utils.ArrayIndexOf)(this.keywords, ln) < 0) {
|
|
1520
|
-
res.push(new pyjslib_Tuple(["", ln]));
|
|
1521
|
-
return i;
|
|
1522
|
-
}
|
|
1523
|
-
|
|
1524
|
-
return -1;
|
|
1525
|
-
}
|
|
1526
|
-
}
|
|
1527
|
-
}, {
|
|
1528
|
-
key: "object",
|
|
1529
|
-
value: function object(str, i, res) {
|
|
1530
|
-
var j = this.subject(str, i, res);
|
|
1531
|
-
|
|
1532
|
-
if (j >= 0) {
|
|
1533
|
-
return j;
|
|
1534
|
-
} else {
|
|
1535
|
-
var j = this.skipSpace(str, i);
|
|
1536
|
-
|
|
1537
|
-
if (j < 0) {
|
|
1538
|
-
return -1;
|
|
1539
1253
|
} else {
|
|
1540
|
-
|
|
1541
|
-
|
|
1542
|
-
|
|
1543
|
-
|
|
1544
|
-
|
|
1545
|
-
|
|
1546
|
-
|
|
1547
|
-
if (
|
|
1548
|
-
|
|
1254
|
+
number_syntax.lastIndex = 0;
|
|
1255
|
+
var m = number_syntax.exec(str.slice(i));
|
|
1256
|
+
if (m == null) {
|
|
1257
|
+
throw BadSyntax(this._thisDoc, this.lines, str, i, "Bad number or date syntax");
|
|
1258
|
+
}
|
|
1259
|
+
j = i + number_syntax.lastIndex;
|
|
1260
|
+
var val = str.slice(i, j);
|
|
1261
|
+
if (val.indexOf("e") >= 0) {
|
|
1262
|
+
res.push(this._store.literal(parseFloat(val), this._store.sym(FLOAT_DATATYPE)));
|
|
1263
|
+
} else if (str.slice(i, j).indexOf(".") >= 0) {
|
|
1264
|
+
res.push(this._store.literal(parseFloat(val), this._store.sym(DECIMAL_DATATYPE)));
|
|
1549
1265
|
} else {
|
|
1550
|
-
|
|
1266
|
+
res.push(this._store.literal(parseInt(val), this._store.sym(INTEGER_DATATYPE)));
|
|
1551
1267
|
}
|
|
1552
|
-
|
|
1553
|
-
var i = i + pyjslib_len(delim);
|
|
1554
|
-
var pairFudge = this.strconst(str, i, delim);
|
|
1555
|
-
var j = pairFudge[0];
|
|
1556
|
-
var s = pairFudge[1];
|
|
1557
|
-
res.push(this._store.literal(s));
|
|
1558
|
-
diag_progress("New string const ", s, j);
|
|
1559
|
-
return j;
|
|
1560
|
-
} else {
|
|
1561
|
-
return -1;
|
|
1562
1268
|
}
|
|
1269
|
+
;
|
|
1270
|
+
return j; // Where we have got up to
|
|
1563
1271
|
}
|
|
1564
|
-
}
|
|
1565
|
-
}, {
|
|
1566
|
-
key: "nodeOrLiteral",
|
|
1567
|
-
value: function nodeOrLiteral(str, i, res) {
|
|
1568
|
-
var j = this.node(str, i, res);
|
|
1569
1272
|
|
|
1570
|
-
if (
|
|
1571
|
-
|
|
1572
|
-
|
|
1573
|
-
var j = this.skipSpace(str, i);
|
|
1574
|
-
|
|
1575
|
-
if (j < 0) {
|
|
1576
|
-
return -1;
|
|
1273
|
+
if (str.charAt(i) == "\"") {
|
|
1274
|
+
if (str.slice(i, i + 3) == "\"\"\"") {
|
|
1275
|
+
var delim = "\"\"\"";
|
|
1577
1276
|
} else {
|
|
1578
|
-
var
|
|
1579
|
-
}
|
|
1580
|
-
|
|
1581
|
-
var
|
|
1582
|
-
|
|
1583
|
-
|
|
1584
|
-
|
|
1585
|
-
|
|
1586
|
-
|
|
1587
|
-
|
|
1588
|
-
|
|
1589
|
-
|
|
1590
|
-
|
|
1591
|
-
|
|
1592
|
-
if (val.indexOf("T") >= 0) {
|
|
1593
|
-
res.push(this._store.literal(val, this._store.sym(DATETIME_DATATYPE)));
|
|
1594
|
-
} else {
|
|
1595
|
-
res.push(this._store.literal(val, this._store.sym(DATE_DATATYPE)));
|
|
1596
|
-
}
|
|
1597
|
-
} else {
|
|
1598
|
-
number_syntax.lastIndex = 0;
|
|
1599
|
-
var m = number_syntax.exec(str.slice(i));
|
|
1600
|
-
|
|
1601
|
-
if (m == null) {
|
|
1602
|
-
throw BadSyntax(this._thisDoc, this.lines, str, i, "Bad number or date syntax");
|
|
1603
|
-
}
|
|
1604
|
-
|
|
1605
|
-
j = i + number_syntax.lastIndex;
|
|
1606
|
-
var val = str.slice(i, j);
|
|
1607
|
-
|
|
1608
|
-
if (val.indexOf("e") >= 0) {
|
|
1609
|
-
res.push(this._store.literal(parseFloat(val), this._store.sym(FLOAT_DATATYPE)));
|
|
1610
|
-
} else if (str.slice(i, j).indexOf(".") >= 0) {
|
|
1611
|
-
res.push(this._store.literal(parseFloat(val), this._store.sym(DECIMAL_DATATYPE)));
|
|
1612
|
-
} else {
|
|
1613
|
-
res.push(this._store.literal(parseInt(val), this._store.sym(INTEGER_DATATYPE)));
|
|
1614
|
-
}
|
|
1277
|
+
var delim = "\"";
|
|
1278
|
+
}
|
|
1279
|
+
var i = i + pyjslib_len(delim);
|
|
1280
|
+
var dt = null;
|
|
1281
|
+
var pairFudge = this.strconst(str, i, delim);
|
|
1282
|
+
var j = pairFudge[0];
|
|
1283
|
+
var s = pairFudge[1];
|
|
1284
|
+
var lang = null;
|
|
1285
|
+
if (str.slice(j, j + 1) == "@") {
|
|
1286
|
+
langcode.lastIndex = 0;
|
|
1287
|
+
var m = langcode.exec(str.slice(j + 1));
|
|
1288
|
+
if (m == null) {
|
|
1289
|
+
throw BadSyntax(this._thisDoc, startline, str, i, "Bad language code syntax on string literal, after @");
|
|
1615
1290
|
}
|
|
1616
|
-
|
|
1617
|
-
;
|
|
1618
|
-
|
|
1291
|
+
var i = langcode.lastIndex + j + 1;
|
|
1292
|
+
var lang = str.slice(j + 1, i);
|
|
1293
|
+
var j = i;
|
|
1619
1294
|
}
|
|
1620
|
-
|
|
1621
|
-
|
|
1622
|
-
|
|
1623
|
-
|
|
1624
|
-
} else {
|
|
1625
|
-
var delim = "\"";
|
|
1626
|
-
}
|
|
1627
|
-
|
|
1628
|
-
var i = i + pyjslib_len(delim);
|
|
1629
|
-
var dt = null;
|
|
1630
|
-
var pairFudge = this.strconst(str, i, delim);
|
|
1631
|
-
var j = pairFudge[0];
|
|
1632
|
-
var s = pairFudge[1];
|
|
1633
|
-
var lang = null;
|
|
1634
|
-
|
|
1635
|
-
if (str.slice(j, j + 1) == "@") {
|
|
1636
|
-
langcode.lastIndex = 0;
|
|
1637
|
-
var m = langcode.exec(str.slice(j + 1));
|
|
1638
|
-
|
|
1639
|
-
if (m == null) {
|
|
1640
|
-
throw BadSyntax(this._thisDoc, startline, str, i, "Bad language code syntax on string literal, after @");
|
|
1641
|
-
}
|
|
1642
|
-
|
|
1643
|
-
var i = langcode.lastIndex + j + 1;
|
|
1644
|
-
var lang = str.slice(j + 1, i);
|
|
1645
|
-
var j = i;
|
|
1646
|
-
}
|
|
1647
|
-
|
|
1648
|
-
if (str.slice(j, j + 2) == "^^") {
|
|
1649
|
-
var res2 = new pyjslib_List([]);
|
|
1650
|
-
var j = this.uri_ref2(str, j + 2, res2);
|
|
1651
|
-
var dt = res2[0];
|
|
1652
|
-
}
|
|
1653
|
-
|
|
1654
|
-
res.push(this._store.literal(s, lang || dt));
|
|
1655
|
-
return j;
|
|
1656
|
-
} else {
|
|
1657
|
-
return -1;
|
|
1295
|
+
if (str.slice(j, j + 2) == "^^") {
|
|
1296
|
+
var res2 = new pyjslib_List([]);
|
|
1297
|
+
var j = this.uri_ref2(str, j + 2, res2);
|
|
1298
|
+
var dt = res2[0];
|
|
1658
1299
|
}
|
|
1300
|
+
res.push(this._store.literal(s, lang || dt));
|
|
1301
|
+
return j;
|
|
1302
|
+
} else {
|
|
1303
|
+
return -1;
|
|
1659
1304
|
}
|
|
1660
1305
|
}
|
|
1661
|
-
}
|
|
1662
|
-
|
|
1663
|
-
|
|
1664
|
-
|
|
1665
|
-
|
|
1666
|
-
|
|
1667
|
-
|
|
1668
|
-
|
|
1669
|
-
|
|
1670
|
-
|
|
1671
|
-
|
|
1672
|
-
|
|
1673
|
-
|
|
1674
|
-
|
|
1675
|
-
|
|
1676
|
-
|
|
1677
|
-
|
|
1678
|
-
|
|
1679
|
-
|
|
1680
|
-
|
|
1681
|
-
|
|
1682
|
-
|
|
1306
|
+
}
|
|
1307
|
+
strconst(str, i, delim) {
|
|
1308
|
+
/*
|
|
1309
|
+
parse an N3 string constant delimited by delim.
|
|
1310
|
+
return index, val
|
|
1311
|
+
*/
|
|
1312
|
+
|
|
1313
|
+
var j = i;
|
|
1314
|
+
var ustr = "";
|
|
1315
|
+
var startline = this.lines;
|
|
1316
|
+
while (j < pyjslib_len(str)) {
|
|
1317
|
+
var i = j + pyjslib_len(delim);
|
|
1318
|
+
if (str.slice(j, i) == delim) {
|
|
1319
|
+
return new pyjslib_Tuple([i, ustr]);
|
|
1320
|
+
}
|
|
1321
|
+
if (str.charAt(j) == "\"") {
|
|
1322
|
+
var ustr = ustr + "\"";
|
|
1323
|
+
var j = j + 1;
|
|
1324
|
+
continue;
|
|
1325
|
+
}
|
|
1326
|
+
interesting.lastIndex = 0;
|
|
1327
|
+
var m = interesting.exec(str.slice(j));
|
|
1328
|
+
if (!m) {
|
|
1329
|
+
throw BadSyntax(this._thisDoc, startline, str, j, "Closing quote missing in string at ^ in " + str.slice(j - 20, j) + "^" + str.slice(j, j + 20));
|
|
1330
|
+
}
|
|
1331
|
+
var i = j + interesting.lastIndex - 1;
|
|
1332
|
+
var ustr = ustr + str.slice(j, i);
|
|
1333
|
+
var ch = str.charAt(i);
|
|
1334
|
+
if (ch == "\"") {
|
|
1335
|
+
var j = i;
|
|
1336
|
+
continue;
|
|
1337
|
+
} else if (ch == "\r") {
|
|
1338
|
+
var j = i + 1;
|
|
1339
|
+
continue;
|
|
1340
|
+
} else if (ch == "\n") {
|
|
1341
|
+
if (delim == "\"") {
|
|
1342
|
+
throw BadSyntax(this._thisDoc, startline, str, i, "newline found in string literal");
|
|
1683
1343
|
}
|
|
1684
|
-
|
|
1685
|
-
|
|
1686
|
-
var
|
|
1687
|
-
|
|
1688
|
-
|
|
1689
|
-
|
|
1344
|
+
this.lines = this.lines + 1;
|
|
1345
|
+
var ustr = ustr + ch;
|
|
1346
|
+
var j = i + 1;
|
|
1347
|
+
this.previousLine = this.startOfLine;
|
|
1348
|
+
this.startOfLine = j;
|
|
1349
|
+
} else if (ch == "\\") {
|
|
1350
|
+
var j = i + 1;
|
|
1351
|
+
var ch = str.slice(j, j + 1);
|
|
1352
|
+
if (!ch) {
|
|
1353
|
+
throw BadSyntax(this._thisDoc, startline, str, i, "unterminated string literal (2)");
|
|
1690
1354
|
}
|
|
1691
|
-
|
|
1692
|
-
|
|
1693
|
-
|
|
1694
|
-
|
|
1695
|
-
|
|
1696
|
-
if (ch == "
|
|
1697
|
-
var
|
|
1698
|
-
|
|
1699
|
-
|
|
1700
|
-
var j = i + 1;
|
|
1701
|
-
continue;
|
|
1702
|
-
} else if (ch == "\n") {
|
|
1703
|
-
if (delim == "\"") {
|
|
1704
|
-
throw BadSyntax(this._thisDoc, startline, str, i, "newline found in string literal");
|
|
1705
|
-
}
|
|
1706
|
-
|
|
1707
|
-
this.lines = this.lines + 1;
|
|
1355
|
+
var k = string_find("abfrtvn\\\"", ch);
|
|
1356
|
+
if (k >= 0) {
|
|
1357
|
+
var uch = "\a\b\f\r\t\v\n\\\"".charAt(k);
|
|
1358
|
+
var ustr = ustr + uch;
|
|
1359
|
+
var j = j + 1;
|
|
1360
|
+
} else if (ch == "u") {
|
|
1361
|
+
var pairFudge = this.uEscape(str, j + 1, startline);
|
|
1362
|
+
var j = pairFudge[0];
|
|
1363
|
+
var ch = pairFudge[1];
|
|
1708
1364
|
var ustr = ustr + ch;
|
|
1709
|
-
|
|
1710
|
-
|
|
1711
|
-
|
|
1712
|
-
|
|
1713
|
-
var
|
|
1714
|
-
|
|
1715
|
-
|
|
1716
|
-
if (!ch) {
|
|
1717
|
-
throw BadSyntax(this._thisDoc, startline, str, i, "unterminated string literal (2)");
|
|
1718
|
-
}
|
|
1719
|
-
|
|
1720
|
-
var k = string_find("abfrtvn\\\"", ch);
|
|
1721
|
-
|
|
1722
|
-
if (k >= 0) {
|
|
1723
|
-
var uch = "\a\b\f\r\t\v\n\\\"".charAt(k);
|
|
1724
|
-
var ustr = ustr + uch;
|
|
1725
|
-
var j = j + 1;
|
|
1726
|
-
} else if (ch == "u") {
|
|
1727
|
-
var pairFudge = this.uEscape(str, j + 1, startline);
|
|
1728
|
-
var j = pairFudge[0];
|
|
1729
|
-
var ch = pairFudge[1];
|
|
1730
|
-
var ustr = ustr + ch;
|
|
1731
|
-
} else if (ch == "U") {
|
|
1732
|
-
var pairFudge = this.UEscape(str, j + 1, startline);
|
|
1733
|
-
var j = pairFudge[0];
|
|
1734
|
-
var ch = pairFudge[1];
|
|
1735
|
-
var ustr = ustr + ch;
|
|
1736
|
-
} else {
|
|
1737
|
-
throw BadSyntax(this._thisDoc, this.lines, str, i, "bad escape");
|
|
1738
|
-
}
|
|
1365
|
+
} else if (ch == "U") {
|
|
1366
|
+
var pairFudge = this.UEscape(str, j + 1, startline);
|
|
1367
|
+
var j = pairFudge[0];
|
|
1368
|
+
var ch = pairFudge[1];
|
|
1369
|
+
var ustr = ustr + ch;
|
|
1370
|
+
} else {
|
|
1371
|
+
throw BadSyntax(this._thisDoc, this.lines, str, i, "bad escape");
|
|
1739
1372
|
}
|
|
1740
1373
|
}
|
|
1741
|
-
|
|
1742
|
-
|
|
1743
|
-
|
|
1744
|
-
|
|
1745
|
-
|
|
1746
|
-
|
|
1747
|
-
|
|
1748
|
-
|
|
1749
|
-
var
|
|
1750
|
-
|
|
1751
|
-
|
|
1752
|
-
|
|
1753
|
-
|
|
1754
|
-
var j = j + 1;
|
|
1755
|
-
|
|
1756
|
-
if (ch == "") {
|
|
1757
|
-
throw BadSyntax(this._thisDoc, startline, str, i, "unterminated string literal(3)");
|
|
1758
|
-
}
|
|
1759
|
-
|
|
1760
|
-
var k = string_find("0123456789abcdef", ch);
|
|
1761
|
-
|
|
1762
|
-
if (k < 0) {
|
|
1763
|
-
throw BadSyntax(this._thisDoc, startline, str, i, "bad string literal hex escape");
|
|
1764
|
-
}
|
|
1765
|
-
|
|
1766
|
-
var value = value * 16 + k;
|
|
1767
|
-
var count = count + 1;
|
|
1374
|
+
}
|
|
1375
|
+
throw BadSyntax(this._thisDoc, this.lines, str, i, "unterminated string literal");
|
|
1376
|
+
}
|
|
1377
|
+
uEscape(str, i, startline) {
|
|
1378
|
+
var j = i;
|
|
1379
|
+
var count = 0;
|
|
1380
|
+
var value = 0;
|
|
1381
|
+
while (count < 4) {
|
|
1382
|
+
var chFudge = str.slice(j, j + 1);
|
|
1383
|
+
var ch = chFudge.toLowerCase();
|
|
1384
|
+
var j = j + 1;
|
|
1385
|
+
if (ch == "") {
|
|
1386
|
+
throw BadSyntax(this._thisDoc, startline, str, i, "unterminated string literal(3)");
|
|
1768
1387
|
}
|
|
1769
|
-
|
|
1770
|
-
|
|
1771
|
-
|
|
1772
|
-
}
|
|
1773
|
-
}, {
|
|
1774
|
-
key: "UEscape",
|
|
1775
|
-
value: function UEscape(str, i, startline) {
|
|
1776
|
-
var j = i;
|
|
1777
|
-
var count = 0;
|
|
1778
|
-
var value = "\\U";
|
|
1779
|
-
|
|
1780
|
-
while (count < 8) {
|
|
1781
|
-
var chFudge = str.slice(j, j + 1);
|
|
1782
|
-
var ch = chFudge.toLowerCase();
|
|
1783
|
-
var j = j + 1;
|
|
1784
|
-
|
|
1785
|
-
if (ch == "") {
|
|
1786
|
-
throw BadSyntax(this._thisDoc, startline, str, i, "unterminated string literal(3)");
|
|
1787
|
-
}
|
|
1788
|
-
|
|
1789
|
-
var k = string_find("0123456789abcdef", ch);
|
|
1790
|
-
|
|
1791
|
-
if (k < 0) {
|
|
1792
|
-
throw BadSyntax(this._thisDoc, startline, str, i, "bad string literal hex escape");
|
|
1793
|
-
}
|
|
1794
|
-
|
|
1795
|
-
var value = value + ch;
|
|
1796
|
-
var count = count + 1;
|
|
1388
|
+
var k = string_find("0123456789abcdef", ch);
|
|
1389
|
+
if (k < 0) {
|
|
1390
|
+
throw BadSyntax(this._thisDoc, startline, str, i, "bad string literal hex escape");
|
|
1797
1391
|
}
|
|
1798
|
-
|
|
1799
|
-
var
|
|
1800
|
-
return new pyjslib_Tuple([j, uch]);
|
|
1392
|
+
var value = value * 16 + k;
|
|
1393
|
+
var count = count + 1;
|
|
1801
1394
|
}
|
|
1802
|
-
|
|
1803
|
-
|
|
1804
|
-
}
|
|
1805
|
-
|
|
1395
|
+
var uch = String.fromCharCode(value);
|
|
1396
|
+
return new pyjslib_Tuple([j, uch]);
|
|
1397
|
+
}
|
|
1398
|
+
UEscape(str, i, startline) {
|
|
1399
|
+
var j = i;
|
|
1400
|
+
var count = 0;
|
|
1401
|
+
var value = "\\U";
|
|
1402
|
+
while (count < 8) {
|
|
1403
|
+
var chFudge = str.slice(j, j + 1);
|
|
1404
|
+
var ch = chFudge.toLowerCase();
|
|
1405
|
+
var j = j + 1;
|
|
1406
|
+
if (ch == "") {
|
|
1407
|
+
throw BadSyntax(this._thisDoc, startline, str, i, "unterminated string literal(3)");
|
|
1408
|
+
}
|
|
1409
|
+
var k = string_find("0123456789abcdef", ch);
|
|
1410
|
+
if (k < 0) {
|
|
1411
|
+
throw BadSyntax(this._thisDoc, startline, str, i, "bad string literal hex escape");
|
|
1412
|
+
}
|
|
1413
|
+
var value = value + ch;
|
|
1414
|
+
var count = count + 1;
|
|
1415
|
+
}
|
|
1416
|
+
var uch = stringFromCharCode("0x" + pyjslib_slice(value, 2, 10) - 0);
|
|
1417
|
+
return new pyjslib_Tuple([j, uch]);
|
|
1418
|
+
}
|
|
1419
|
+
}
|
|
1806
1420
|
exports.SinkParser = SinkParser;
|
|
1807
|
-
|
|
1808
1421
|
function OLD_BadSyntax(uri, lines, str, i, why) {
|
|
1809
1422
|
return new __OLD_BadSyntax(uri, lines, str, i, why);
|
|
1810
1423
|
}
|
|
1811
|
-
|
|
1812
1424
|
function __OLD_BadSyntax(uri, lines, str, i, why) {
|
|
1813
1425
|
this._str = str.encode("utf-8");
|
|
1814
1426
|
this._str = str;
|
|
@@ -1817,47 +1429,38 @@ function __OLD_BadSyntax(uri, lines, str, i, why) {
|
|
|
1817
1429
|
this.lines = lines;
|
|
1818
1430
|
this._uri = uri;
|
|
1819
1431
|
}
|
|
1820
|
-
|
|
1821
1432
|
__OLD_BadSyntax.prototype.toString = function () {
|
|
1822
1433
|
var str = this._str;
|
|
1823
1434
|
var i = this._i;
|
|
1824
1435
|
var st = 0;
|
|
1825
|
-
|
|
1826
1436
|
if (i > 60) {
|
|
1827
1437
|
var pre = "...";
|
|
1828
1438
|
var st = i - 60;
|
|
1829
1439
|
} else {
|
|
1830
1440
|
var pre = "";
|
|
1831
1441
|
}
|
|
1832
|
-
|
|
1833
1442
|
if (pyjslib_len(str) - i > 60) {
|
|
1834
1443
|
var post = "...";
|
|
1835
1444
|
} else {
|
|
1836
1445
|
var post = "";
|
|
1837
1446
|
}
|
|
1838
|
-
|
|
1839
1447
|
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]);
|
|
1840
1448
|
};
|
|
1841
|
-
|
|
1842
1449
|
function BadSyntax(uri, lines, str, i, why) {
|
|
1843
|
-
|
|
1844
|
-
|
|
1845
|
-
|
|
1450
|
+
let lineNo = lines + 1;
|
|
1451
|
+
let msg = "Line " + lineNo + " of <" + uri + ">: Bad syntax: " + why + "\nat: \"" + str.slice(i, i + 30) + "\"";
|
|
1452
|
+
let e = new SyntaxError(msg, uri, lineNo);
|
|
1846
1453
|
e.lineNo = lineNo;
|
|
1847
1454
|
e.characterInFile = i;
|
|
1848
1455
|
e.syntaxProblem = why;
|
|
1849
1456
|
return e;
|
|
1850
1457
|
}
|
|
1851
|
-
|
|
1852
1458
|
function stripCR(str) {
|
|
1853
1459
|
var res = "";
|
|
1854
|
-
|
|
1855
1460
|
var __ch = new pyjslib_Iterator(str);
|
|
1856
|
-
|
|
1857
1461
|
try {
|
|
1858
1462
|
while (true) {
|
|
1859
1463
|
var ch = __ch.next();
|
|
1860
|
-
|
|
1861
1464
|
if (ch != "\r") {
|
|
1862
1465
|
var res = res + ch;
|
|
1863
1466
|
}
|
|
@@ -1867,8 +1470,6 @@ function stripCR(str) {
|
|
|
1867
1470
|
throw e;
|
|
1868
1471
|
}
|
|
1869
1472
|
}
|
|
1870
|
-
|
|
1871
1473
|
return res;
|
|
1872
1474
|
}
|
|
1873
|
-
|
|
1874
1475
|
function dummyWrite(x) {}
|