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