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