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