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