@steedos/odata-v4-parser 2.5.3-beta.2 → 2.5.3-beta.21

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/src/json.ts CHANGED
@@ -1,372 +1,372 @@
1
- import Utils from "./utils";
2
- import Lexer from "./lexer";
3
- import PrimitiveLiteral from "./primitiveLiteral";
4
- import NameOrIdentifier from "./nameOrIdentifier";
5
- import Expressions from "./expressions";
6
-
7
- export namespace ArrayOrObject {
8
- export function complexColInUri(value: Utils.SourceArray, index: number): Lexer.Token {
9
- let begin = Lexer.beginArray(value, index);
10
- if (begin === index) return;
11
- let start = index;
12
- index = begin;
13
-
14
- let items = [];
15
- let token = ArrayOrObject.complexInUri(value, index);
16
- if (token) {
17
- while (token) {
18
- items.push(token);
19
- index = token.next;
20
-
21
- let end = Lexer.endArray(value, index);
22
- if (end > index) {
23
- index = end;
24
- break;
25
- } else {
26
- let separator = Lexer.valueSeparator(value, index);
27
- if (separator === index) return;
28
- index = separator;
29
-
30
- token = ArrayOrObject.complexInUri(value, index);
31
- if (!token) return;
32
- }
33
- }
34
- } else {
35
- let end = Lexer.endArray(value, index);
36
- if (end === index) return;
37
- index = end;
38
- }
39
-
40
- return Lexer.tokenize(value, start, index, { items }, Lexer.TokenType.Array);
41
- }
42
-
43
- export function complexInUri(value: Utils.SourceArray, index: number): Lexer.Token {
44
- let begin = Lexer.beginObject(value, index);
45
- if (begin === index) return;
46
- let start = index;
47
- index = begin;
48
-
49
- let items = [];
50
- let token = ArrayOrObject.annotationInUri(value, index) ||
51
- ArrayOrObject.primitivePropertyInUri(value, index) ||
52
- ArrayOrObject.complexPropertyInUri(value, index) ||
53
- ArrayOrObject.collectionPropertyInUri(value, index) ||
54
- ArrayOrObject.navigationPropertyInUri(value, index);
55
- if (token) {
56
- while (token) {
57
- items.push(token);
58
- index = token.next;
59
-
60
- let end = Lexer.endObject(value, index);
61
- if (end > index) {
62
- index = end;
63
- break;
64
- } else {
65
- let separator = Lexer.valueSeparator(value, index);
66
- if (separator === index) return;
67
- index = separator;
68
-
69
- token = ArrayOrObject.annotationInUri(value, index) ||
70
- ArrayOrObject.primitivePropertyInUri(value, index) ||
71
- ArrayOrObject.complexPropertyInUri(value, index) ||
72
- ArrayOrObject.collectionPropertyInUri(value, index) ||
73
- ArrayOrObject.navigationPropertyInUri(value, index);
74
- if (!token) return;
75
- }
76
- }
77
- } else {
78
- let end = Lexer.endObject(value, index);
79
- if (end === index) return;
80
- index = end;
81
- }
82
-
83
- return Lexer.tokenize(value, start, index, { items }, Lexer.TokenType.Object);
84
- }
85
-
86
- export function collectionPropertyInUri(value: Utils.SourceArray, index: number): Lexer.Token {
87
- let mark = Lexer.quotationMark(value, index);
88
- if (mark === index) return;
89
- let start = index;
90
- index = mark;
91
-
92
- let prop = NameOrIdentifier.primitiveColProperty(value, index) ||
93
- NameOrIdentifier.complexColProperty(value, index);
94
-
95
- if (!prop) return;
96
- index = prop.next;
97
-
98
- mark = Lexer.quotationMark(value, index);
99
- if (mark === index) return;
100
- index = mark;
101
-
102
- let separator = Lexer.nameSeparator(value, index);
103
- if (separator === index) return;
104
- index = separator;
105
-
106
- let propValue = prop.type === Lexer.TokenType.PrimitiveCollectionProperty
107
- ? ArrayOrObject.primitiveColInUri(value, index)
108
- : ArrayOrObject.complexColInUri(value, index);
109
-
110
- if (!propValue) return;
111
- index = propValue.next;
112
-
113
- return Lexer.tokenize(value, start, index, { key: prop, value: propValue }, Lexer.TokenType.Property);
114
- }
115
-
116
- export function primitiveColInUri(value: Utils.SourceArray, index: number): Lexer.Token {
117
- let begin = Lexer.beginArray(value, index);
118
- if (begin === index) return;
119
- let start = index;
120
- index = begin;
121
-
122
- let items = [];
123
- let token = ArrayOrObject.primitiveLiteralInJSON(value, index);
124
- if (token) {
125
- while (token) {
126
- items.push(token);
127
- index = token.next;
128
-
129
- let end = Lexer.endArray(value, index);
130
- if (end > index) {
131
- index = end;
132
- break;
133
- } else {
134
- let separator = Lexer.valueSeparator(value, index);
135
- if (separator === index) return;
136
- index = separator;
137
-
138
- token = ArrayOrObject.primitiveLiteralInJSON(value, index);
139
- if (!token) return;
140
- }
141
- }
142
- } else {
143
- let end = Lexer.endArray(value, index);
144
- if (end === index) return;
145
- index = end;
146
- }
147
-
148
- return Lexer.tokenize(value, start, index, { items }, Lexer.TokenType.Array);
149
- }
150
-
151
- export function complexPropertyInUri(value: Utils.SourceArray, index: number): Lexer.Token {
152
- let mark = Lexer.quotationMark(value, index);
153
- if (mark === index) return;
154
- let start = index;
155
- index = mark;
156
-
157
- let prop = NameOrIdentifier.complexProperty(value, index);
158
- if (!prop) return;
159
- index = prop.next;
160
-
161
- mark = Lexer.quotationMark(value, index);
162
- if (mark === index) return;
163
- index = mark;
164
-
165
- let separator = Lexer.nameSeparator(value, index);
166
- if (separator === index) return;
167
- index = separator;
168
-
169
- let propValue = ArrayOrObject.complexInUri(value, index);
170
- if (!propValue) return;
171
- index = propValue.next;
172
-
173
- return Lexer.tokenize(value, start, index, { key: prop, value: propValue }, Lexer.TokenType.Property);
174
- }
175
-
176
- export function annotationInUri(value: Utils.SourceArray, index: number): Lexer.Token {
177
- let mark = Lexer.quotationMark(value, index);
178
- if (mark === index) return;
179
- let start = index;
180
- index = mark;
181
-
182
- let at = Lexer.AT(value, index);
183
- if (!at) return;
184
- index = at;
185
-
186
- let namespaceNext = NameOrIdentifier.namespace(value, index);
187
- if (namespaceNext === index) return;
188
- let namespaceStart = index;
189
- index = namespaceNext;
190
-
191
- if (value[index] !== 0x2e) return;
192
- index++;
193
-
194
- let term = NameOrIdentifier.termName(value, index);
195
- if (!term) return;
196
- index = term.next;
197
-
198
- mark = Lexer.quotationMark(value, index);
199
- if (mark === index) return;
200
- index = mark;
201
-
202
- let separator = Lexer.nameSeparator(value, index);
203
- if (separator === index) return;
204
- index = separator;
205
-
206
- let token = ArrayOrObject.complexInUri(value, index) ||
207
- ArrayOrObject.complexColInUri(value, index) ||
208
- ArrayOrObject.primitiveLiteralInJSON(value, index) ||
209
- ArrayOrObject.primitiveColInUri(value, index);
210
- if (!token) return;
211
- index = token.next;
212
-
213
- return Lexer.tokenize(value, start, index, {
214
- key: "@" + Utils.stringify(value, namespaceStart, namespaceNext) + "." + term.raw,
215
- value: token
216
- }, Lexer.TokenType.Annotation);
217
- }
218
-
219
- export function keyValuePairInUri(value: Utils.SourceArray, index: number, keyFn: Function, valueFn: Function): Lexer.Token {
220
- let mark = Lexer.quotationMark(value, index);
221
- if (mark === index) return;
222
- let start = index;
223
- index = mark;
224
-
225
- let prop = keyFn(value, index);
226
- if (!prop) return;
227
- index = prop.next;
228
-
229
- mark = Lexer.quotationMark(value, index);
230
- if (mark === index) return;
231
- index = mark;
232
-
233
- let separator = Lexer.nameSeparator(value, index);
234
- if (separator === index) return;
235
- index = separator;
236
-
237
- let propValue = valueFn(value, index);
238
- if (!propValue) return;
239
- index = propValue.next;
240
-
241
- return Lexer.tokenize(value, start, index, { key: prop, value: propValue }, Lexer.TokenType.Property);
242
- }
243
-
244
- export function primitivePropertyInUri(value: Utils.SourceArray, index: number): Lexer.Token {
245
- return ArrayOrObject.keyValuePairInUri(value, index, NameOrIdentifier.primitiveProperty, primitiveLiteralInJSON);
246
- }
247
-
248
- export function navigationPropertyInUri(value: Utils.SourceArray, index: number): Lexer.Token {
249
- return ArrayOrObject.singleNavPropInJSON(value, index) ||
250
- ArrayOrObject.collectionNavPropInJSON(value, index);
251
- }
252
-
253
- export function singleNavPropInJSON(value: Utils.SourceArray, index: number): Lexer.Token {
254
- return ArrayOrObject.keyValuePairInUri(value, index, NameOrIdentifier.entityNavigationProperty, Expressions.rootExpr);
255
- }
256
-
257
- export function collectionNavPropInJSON(value: Utils.SourceArray, index: number): Lexer.Token {
258
- return ArrayOrObject.keyValuePairInUri(value, index, NameOrIdentifier.entityColNavigationProperty, rootExprCol);
259
- }
260
-
261
- export function rootExprCol(value: Utils.SourceArray, index: number): Lexer.Token {
262
- let begin = Lexer.beginArray(value, index);
263
- if (begin === index) return;
264
- let start = index;
265
- index = begin;
266
-
267
- let items = [];
268
- let token = Expressions.rootExpr(value, index);
269
- if (token) {
270
- while (token) {
271
- items.push(token);
272
- index = token.next;
273
-
274
- let end = Lexer.endArray(value, index);
275
- if (end > index) {
276
- index = end;
277
- break;
278
- } else {
279
- let separator = Lexer.valueSeparator(value, index);
280
- if (separator === index) return;
281
- index = separator;
282
-
283
- token = Expressions.rootExpr(value, index);
284
- if (!token) return;
285
- }
286
- }
287
- } else {
288
- let end = Lexer.endArray(value, index);
289
- if (end === index) return;
290
- index = end;
291
- }
292
-
293
- return Lexer.tokenize(value, start, index, { items }, Lexer.TokenType.Array);
294
- }
295
-
296
- export function primitiveLiteralInJSON(value: Utils.SourceArray, index: number): Lexer.Token {
297
- return ArrayOrObject.stringInJSON(value, index) ||
298
- ArrayOrObject.numberInJSON(value, index) ||
299
- ArrayOrObject.booleanInJSON(value, index) ||
300
- ArrayOrObject.nullInJSON(value, index);
301
- }
302
-
303
- export function stringInJSON(value: Utils.SourceArray, index: number): Lexer.Token {
304
- let mark = Lexer.quotationMark(value, index);
305
- if (mark === index) return;
306
- let start = index;
307
- index = mark;
308
-
309
- let char = ArrayOrObject.charInJSON(value, index);
310
- while (char > index) {
311
- index = char;
312
- char = ArrayOrObject.charInJSON(value, index);
313
- }
314
-
315
- mark = Lexer.quotationMark(value, index);
316
- if (mark === index) return;
317
- index = mark;
318
-
319
- return Lexer.tokenize(value, start, index, "string", Lexer.TokenType.Literal);
320
- }
321
-
322
- export function charInJSON(value: Utils.SourceArray, index: number): number {
323
- let escape = Lexer.escape(value, index);
324
- if (escape > index) {
325
- if (Utils.equals(value, escape, "%2F")) return escape + 3;
326
- if (Utils.equals(value, escape, "/") ||
327
- Utils.equals(value, escape, "b") ||
328
- Utils.equals(value, escape, "f") ||
329
- Utils.equals(value, escape, "n") ||
330
- Utils.equals(value, escape, "r") ||
331
- Utils.equals(value, escape, "t")) return escape + 1;
332
- if (Utils.equals(value, escape, "u") &&
333
- Utils.required(value, escape + 1, Lexer.HEXDIG, 4, 4)) return escape + 5;
334
- let escapeNext = Lexer.escape(value, escape);
335
- if (escapeNext > escape) return escapeNext;
336
- let mark = Lexer.quotationMark(value, escape);
337
- if (mark > escape) return mark;
338
- } else {
339
- let mark = Lexer.quotationMark(value, index);
340
- if (mark === index) return index + 1;
341
- }
342
- }
343
-
344
- export function numberInJSON(value: Utils.SourceArray, index: number): Lexer.Token {
345
- let token = PrimitiveLiteral.doubleValue(value, index) ||
346
- PrimitiveLiteral.int64Value(value, index);
347
- if (token) {
348
- token.value = "number";
349
- return token;
350
- }
351
- }
352
-
353
- export function booleanInJSON(value: Utils.SourceArray, index: number): Lexer.Token {
354
- if (Utils.equals(value, index, "true")) return Lexer.tokenize(value, index, index + 4, "boolean", Lexer.TokenType.Literal);
355
- if (Utils.equals(value, index, "false")) return Lexer.tokenize(value, index, index + 5, "boolean", Lexer.TokenType.Literal);
356
- }
357
-
358
- export function nullInJSON(value: Utils.SourceArray, index: number): Lexer.Token {
359
- if (Utils.equals(value, index, "null")) return Lexer.tokenize(value, index, index + 4, "null", Lexer.TokenType.Literal);
360
- }
361
-
362
- export function arrayOrObject(value: Utils.SourceArray, index: number): Lexer.Token {
363
- let token = ArrayOrObject.complexColInUri(value, index) ||
364
- ArrayOrObject.complexInUri(value, index) ||
365
- ArrayOrObject.rootExprCol(value, index) ||
366
- ArrayOrObject.primitiveColInUri(value, index);
367
-
368
- if (token) return Lexer.tokenize(value, index, token.next, token, Lexer.TokenType.ArrayOrObject);
369
- }
370
- }
371
-
1
+ import Utils from "./utils";
2
+ import Lexer from "./lexer";
3
+ import PrimitiveLiteral from "./primitiveLiteral";
4
+ import NameOrIdentifier from "./nameOrIdentifier";
5
+ import Expressions from "./expressions";
6
+
7
+ export namespace ArrayOrObject {
8
+ export function complexColInUri(value: Utils.SourceArray, index: number): Lexer.Token {
9
+ let begin = Lexer.beginArray(value, index);
10
+ if (begin === index) return;
11
+ let start = index;
12
+ index = begin;
13
+
14
+ let items = [];
15
+ let token = ArrayOrObject.complexInUri(value, index);
16
+ if (token) {
17
+ while (token) {
18
+ items.push(token);
19
+ index = token.next;
20
+
21
+ let end = Lexer.endArray(value, index);
22
+ if (end > index) {
23
+ index = end;
24
+ break;
25
+ } else {
26
+ let separator = Lexer.valueSeparator(value, index);
27
+ if (separator === index) return;
28
+ index = separator;
29
+
30
+ token = ArrayOrObject.complexInUri(value, index);
31
+ if (!token) return;
32
+ }
33
+ }
34
+ } else {
35
+ let end = Lexer.endArray(value, index);
36
+ if (end === index) return;
37
+ index = end;
38
+ }
39
+
40
+ return Lexer.tokenize(value, start, index, { items }, Lexer.TokenType.Array);
41
+ }
42
+
43
+ export function complexInUri(value: Utils.SourceArray, index: number): Lexer.Token {
44
+ let begin = Lexer.beginObject(value, index);
45
+ if (begin === index) return;
46
+ let start = index;
47
+ index = begin;
48
+
49
+ let items = [];
50
+ let token = ArrayOrObject.annotationInUri(value, index) ||
51
+ ArrayOrObject.primitivePropertyInUri(value, index) ||
52
+ ArrayOrObject.complexPropertyInUri(value, index) ||
53
+ ArrayOrObject.collectionPropertyInUri(value, index) ||
54
+ ArrayOrObject.navigationPropertyInUri(value, index);
55
+ if (token) {
56
+ while (token) {
57
+ items.push(token);
58
+ index = token.next;
59
+
60
+ let end = Lexer.endObject(value, index);
61
+ if (end > index) {
62
+ index = end;
63
+ break;
64
+ } else {
65
+ let separator = Lexer.valueSeparator(value, index);
66
+ if (separator === index) return;
67
+ index = separator;
68
+
69
+ token = ArrayOrObject.annotationInUri(value, index) ||
70
+ ArrayOrObject.primitivePropertyInUri(value, index) ||
71
+ ArrayOrObject.complexPropertyInUri(value, index) ||
72
+ ArrayOrObject.collectionPropertyInUri(value, index) ||
73
+ ArrayOrObject.navigationPropertyInUri(value, index);
74
+ if (!token) return;
75
+ }
76
+ }
77
+ } else {
78
+ let end = Lexer.endObject(value, index);
79
+ if (end === index) return;
80
+ index = end;
81
+ }
82
+
83
+ return Lexer.tokenize(value, start, index, { items }, Lexer.TokenType.Object);
84
+ }
85
+
86
+ export function collectionPropertyInUri(value: Utils.SourceArray, index: number): Lexer.Token {
87
+ let mark = Lexer.quotationMark(value, index);
88
+ if (mark === index) return;
89
+ let start = index;
90
+ index = mark;
91
+
92
+ let prop = NameOrIdentifier.primitiveColProperty(value, index) ||
93
+ NameOrIdentifier.complexColProperty(value, index);
94
+
95
+ if (!prop) return;
96
+ index = prop.next;
97
+
98
+ mark = Lexer.quotationMark(value, index);
99
+ if (mark === index) return;
100
+ index = mark;
101
+
102
+ let separator = Lexer.nameSeparator(value, index);
103
+ if (separator === index) return;
104
+ index = separator;
105
+
106
+ let propValue = prop.type === Lexer.TokenType.PrimitiveCollectionProperty
107
+ ? ArrayOrObject.primitiveColInUri(value, index)
108
+ : ArrayOrObject.complexColInUri(value, index);
109
+
110
+ if (!propValue) return;
111
+ index = propValue.next;
112
+
113
+ return Lexer.tokenize(value, start, index, { key: prop, value: propValue }, Lexer.TokenType.Property);
114
+ }
115
+
116
+ export function primitiveColInUri(value: Utils.SourceArray, index: number): Lexer.Token {
117
+ let begin = Lexer.beginArray(value, index);
118
+ if (begin === index) return;
119
+ let start = index;
120
+ index = begin;
121
+
122
+ let items = [];
123
+ let token = ArrayOrObject.primitiveLiteralInJSON(value, index);
124
+ if (token) {
125
+ while (token) {
126
+ items.push(token);
127
+ index = token.next;
128
+
129
+ let end = Lexer.endArray(value, index);
130
+ if (end > index) {
131
+ index = end;
132
+ break;
133
+ } else {
134
+ let separator = Lexer.valueSeparator(value, index);
135
+ if (separator === index) return;
136
+ index = separator;
137
+
138
+ token = ArrayOrObject.primitiveLiteralInJSON(value, index);
139
+ if (!token) return;
140
+ }
141
+ }
142
+ } else {
143
+ let end = Lexer.endArray(value, index);
144
+ if (end === index) return;
145
+ index = end;
146
+ }
147
+
148
+ return Lexer.tokenize(value, start, index, { items }, Lexer.TokenType.Array);
149
+ }
150
+
151
+ export function complexPropertyInUri(value: Utils.SourceArray, index: number): Lexer.Token {
152
+ let mark = Lexer.quotationMark(value, index);
153
+ if (mark === index) return;
154
+ let start = index;
155
+ index = mark;
156
+
157
+ let prop = NameOrIdentifier.complexProperty(value, index);
158
+ if (!prop) return;
159
+ index = prop.next;
160
+
161
+ mark = Lexer.quotationMark(value, index);
162
+ if (mark === index) return;
163
+ index = mark;
164
+
165
+ let separator = Lexer.nameSeparator(value, index);
166
+ if (separator === index) return;
167
+ index = separator;
168
+
169
+ let propValue = ArrayOrObject.complexInUri(value, index);
170
+ if (!propValue) return;
171
+ index = propValue.next;
172
+
173
+ return Lexer.tokenize(value, start, index, { key: prop, value: propValue }, Lexer.TokenType.Property);
174
+ }
175
+
176
+ export function annotationInUri(value: Utils.SourceArray, index: number): Lexer.Token {
177
+ let mark = Lexer.quotationMark(value, index);
178
+ if (mark === index) return;
179
+ let start = index;
180
+ index = mark;
181
+
182
+ let at = Lexer.AT(value, index);
183
+ if (!at) return;
184
+ index = at;
185
+
186
+ let namespaceNext = NameOrIdentifier.namespace(value, index);
187
+ if (namespaceNext === index) return;
188
+ let namespaceStart = index;
189
+ index = namespaceNext;
190
+
191
+ if (value[index] !== 0x2e) return;
192
+ index++;
193
+
194
+ let term = NameOrIdentifier.termName(value, index);
195
+ if (!term) return;
196
+ index = term.next;
197
+
198
+ mark = Lexer.quotationMark(value, index);
199
+ if (mark === index) return;
200
+ index = mark;
201
+
202
+ let separator = Lexer.nameSeparator(value, index);
203
+ if (separator === index) return;
204
+ index = separator;
205
+
206
+ let token = ArrayOrObject.complexInUri(value, index) ||
207
+ ArrayOrObject.complexColInUri(value, index) ||
208
+ ArrayOrObject.primitiveLiteralInJSON(value, index) ||
209
+ ArrayOrObject.primitiveColInUri(value, index);
210
+ if (!token) return;
211
+ index = token.next;
212
+
213
+ return Lexer.tokenize(value, start, index, {
214
+ key: "@" + Utils.stringify(value, namespaceStart, namespaceNext) + "." + term.raw,
215
+ value: token
216
+ }, Lexer.TokenType.Annotation);
217
+ }
218
+
219
+ export function keyValuePairInUri(value: Utils.SourceArray, index: number, keyFn: Function, valueFn: Function): Lexer.Token {
220
+ let mark = Lexer.quotationMark(value, index);
221
+ if (mark === index) return;
222
+ let start = index;
223
+ index = mark;
224
+
225
+ let prop = keyFn(value, index);
226
+ if (!prop) return;
227
+ index = prop.next;
228
+
229
+ mark = Lexer.quotationMark(value, index);
230
+ if (mark === index) return;
231
+ index = mark;
232
+
233
+ let separator = Lexer.nameSeparator(value, index);
234
+ if (separator === index) return;
235
+ index = separator;
236
+
237
+ let propValue = valueFn(value, index);
238
+ if (!propValue) return;
239
+ index = propValue.next;
240
+
241
+ return Lexer.tokenize(value, start, index, { key: prop, value: propValue }, Lexer.TokenType.Property);
242
+ }
243
+
244
+ export function primitivePropertyInUri(value: Utils.SourceArray, index: number): Lexer.Token {
245
+ return ArrayOrObject.keyValuePairInUri(value, index, NameOrIdentifier.primitiveProperty, primitiveLiteralInJSON);
246
+ }
247
+
248
+ export function navigationPropertyInUri(value: Utils.SourceArray, index: number): Lexer.Token {
249
+ return ArrayOrObject.singleNavPropInJSON(value, index) ||
250
+ ArrayOrObject.collectionNavPropInJSON(value, index);
251
+ }
252
+
253
+ export function singleNavPropInJSON(value: Utils.SourceArray, index: number): Lexer.Token {
254
+ return ArrayOrObject.keyValuePairInUri(value, index, NameOrIdentifier.entityNavigationProperty, Expressions.rootExpr);
255
+ }
256
+
257
+ export function collectionNavPropInJSON(value: Utils.SourceArray, index: number): Lexer.Token {
258
+ return ArrayOrObject.keyValuePairInUri(value, index, NameOrIdentifier.entityColNavigationProperty, rootExprCol);
259
+ }
260
+
261
+ export function rootExprCol(value: Utils.SourceArray, index: number): Lexer.Token {
262
+ let begin = Lexer.beginArray(value, index);
263
+ if (begin === index) return;
264
+ let start = index;
265
+ index = begin;
266
+
267
+ let items = [];
268
+ let token = Expressions.rootExpr(value, index);
269
+ if (token) {
270
+ while (token) {
271
+ items.push(token);
272
+ index = token.next;
273
+
274
+ let end = Lexer.endArray(value, index);
275
+ if (end > index) {
276
+ index = end;
277
+ break;
278
+ } else {
279
+ let separator = Lexer.valueSeparator(value, index);
280
+ if (separator === index) return;
281
+ index = separator;
282
+
283
+ token = Expressions.rootExpr(value, index);
284
+ if (!token) return;
285
+ }
286
+ }
287
+ } else {
288
+ let end = Lexer.endArray(value, index);
289
+ if (end === index) return;
290
+ index = end;
291
+ }
292
+
293
+ return Lexer.tokenize(value, start, index, { items }, Lexer.TokenType.Array);
294
+ }
295
+
296
+ export function primitiveLiteralInJSON(value: Utils.SourceArray, index: number): Lexer.Token {
297
+ return ArrayOrObject.stringInJSON(value, index) ||
298
+ ArrayOrObject.numberInJSON(value, index) ||
299
+ ArrayOrObject.booleanInJSON(value, index) ||
300
+ ArrayOrObject.nullInJSON(value, index);
301
+ }
302
+
303
+ export function stringInJSON(value: Utils.SourceArray, index: number): Lexer.Token {
304
+ let mark = Lexer.quotationMark(value, index);
305
+ if (mark === index) return;
306
+ let start = index;
307
+ index = mark;
308
+
309
+ let char = ArrayOrObject.charInJSON(value, index);
310
+ while (char > index) {
311
+ index = char;
312
+ char = ArrayOrObject.charInJSON(value, index);
313
+ }
314
+
315
+ mark = Lexer.quotationMark(value, index);
316
+ if (mark === index) return;
317
+ index = mark;
318
+
319
+ return Lexer.tokenize(value, start, index, "string", Lexer.TokenType.Literal);
320
+ }
321
+
322
+ export function charInJSON(value: Utils.SourceArray, index: number): number {
323
+ let escape = Lexer.escape(value, index);
324
+ if (escape > index) {
325
+ if (Utils.equals(value, escape, "%2F")) return escape + 3;
326
+ if (Utils.equals(value, escape, "/") ||
327
+ Utils.equals(value, escape, "b") ||
328
+ Utils.equals(value, escape, "f") ||
329
+ Utils.equals(value, escape, "n") ||
330
+ Utils.equals(value, escape, "r") ||
331
+ Utils.equals(value, escape, "t")) return escape + 1;
332
+ if (Utils.equals(value, escape, "u") &&
333
+ Utils.required(value, escape + 1, Lexer.HEXDIG, 4, 4)) return escape + 5;
334
+ let escapeNext = Lexer.escape(value, escape);
335
+ if (escapeNext > escape) return escapeNext;
336
+ let mark = Lexer.quotationMark(value, escape);
337
+ if (mark > escape) return mark;
338
+ } else {
339
+ let mark = Lexer.quotationMark(value, index);
340
+ if (mark === index) return index + 1;
341
+ }
342
+ }
343
+
344
+ export function numberInJSON(value: Utils.SourceArray, index: number): Lexer.Token {
345
+ let token = PrimitiveLiteral.doubleValue(value, index) ||
346
+ PrimitiveLiteral.int64Value(value, index);
347
+ if (token) {
348
+ token.value = "number";
349
+ return token;
350
+ }
351
+ }
352
+
353
+ export function booleanInJSON(value: Utils.SourceArray, index: number): Lexer.Token {
354
+ if (Utils.equals(value, index, "true")) return Lexer.tokenize(value, index, index + 4, "boolean", Lexer.TokenType.Literal);
355
+ if (Utils.equals(value, index, "false")) return Lexer.tokenize(value, index, index + 5, "boolean", Lexer.TokenType.Literal);
356
+ }
357
+
358
+ export function nullInJSON(value: Utils.SourceArray, index: number): Lexer.Token {
359
+ if (Utils.equals(value, index, "null")) return Lexer.tokenize(value, index, index + 4, "null", Lexer.TokenType.Literal);
360
+ }
361
+
362
+ export function arrayOrObject(value: Utils.SourceArray, index: number): Lexer.Token {
363
+ let token = ArrayOrObject.complexColInUri(value, index) ||
364
+ ArrayOrObject.complexInUri(value, index) ||
365
+ ArrayOrObject.rootExprCol(value, index) ||
366
+ ArrayOrObject.primitiveColInUri(value, index);
367
+
368
+ if (token) return Lexer.tokenize(value, index, token.next, token, Lexer.TokenType.ArrayOrObject);
369
+ }
370
+ }
371
+
372
372
  export default ArrayOrObject;