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