1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace hanneskod\readmetester\Parser; |
4
|
|
|
|
5
|
|
|
class Parser |
6
|
|
|
{ |
7
|
|
|
protected $string; |
8
|
|
|
protected $position; |
9
|
|
|
protected $value; |
10
|
|
|
protected $cache; |
11
|
|
|
protected $cut; |
12
|
|
|
protected $errors; |
13
|
|
|
protected $warnings; |
14
|
|
|
|
15
|
|
|
protected function parseFILE() |
16
|
|
|
{ |
17
|
|
|
$_position = $this->position; |
18
|
|
|
|
19
|
|
|
if (isset($this->cache['FILE'][$_position])) { |
20
|
|
|
$_success = $this->cache['FILE'][$_position]['success']; |
21
|
|
|
$this->position = $this->cache['FILE'][$_position]['position']; |
22
|
|
|
$this->value = $this->cache['FILE'][$_position]['value']; |
23
|
|
|
|
24
|
|
|
return $_success; |
25
|
|
|
} |
26
|
|
|
|
27
|
|
|
$_value9 = array(); |
28
|
|
|
|
29
|
|
|
$_value4 = array(); |
30
|
|
|
$_cut5 = $this->cut; |
31
|
|
|
|
32
|
|
|
while (true) { |
33
|
|
|
$_position3 = $this->position; |
34
|
|
|
|
35
|
|
|
$this->cut = false; |
36
|
|
|
$_position1 = $this->position; |
37
|
|
|
$_cut2 = $this->cut; |
38
|
|
|
|
39
|
|
|
$this->cut = false; |
40
|
|
|
$_success = $this->parseEXAMPLE(); |
41
|
|
|
|
42
|
|
|
if (!$_success && !$this->cut) { |
43
|
|
|
$this->position = $_position1; |
44
|
|
|
|
45
|
|
|
$_success = $this->parseVOID_LINE(); |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
$this->cut = $_cut2; |
49
|
|
|
|
50
|
|
|
if (!$_success) { |
51
|
|
|
break; |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
$_value4[] = $this->value; |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
if (!$this->cut) { |
58
|
|
|
$_success = true; |
59
|
|
|
$this->position = $_position3; |
|
|
|
|
60
|
|
|
$this->value = $_value4; |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
$this->cut = $_cut5; |
64
|
|
|
|
65
|
|
|
if ($_success) { |
|
|
|
|
66
|
|
|
$examples = $this->value; |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
if ($_success) { |
70
|
|
|
$_value9[] = $this->value; |
71
|
|
|
|
72
|
|
|
$_value7 = array(); |
73
|
|
|
$_cut8 = $this->cut; |
74
|
|
|
|
75
|
|
|
while (true) { |
76
|
|
|
$_position6 = $this->position; |
77
|
|
|
|
78
|
|
|
$this->cut = false; |
79
|
|
|
if ($this->position < strlen($this->string)) { |
80
|
|
|
$_success = true; |
81
|
|
|
$this->value = substr($this->string, $this->position, 1); |
82
|
|
|
$this->position += 1; |
83
|
|
|
} else { |
84
|
|
|
$_success = false; |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
if (!$_success) { |
88
|
|
|
break; |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
$_value7[] = $this->value; |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
if (!$this->cut) { |
95
|
|
|
$_success = true; |
96
|
|
|
$this->position = $_position6; |
|
|
|
|
97
|
|
|
$this->value = $_value7; |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
$this->cut = $_cut8; |
101
|
|
|
} |
102
|
|
|
|
103
|
|
|
if ($_success) { |
104
|
|
|
$_value9[] = $this->value; |
105
|
|
|
|
106
|
|
|
$this->value = $_value9; |
107
|
|
|
} |
108
|
|
|
|
109
|
|
|
if ($_success) { |
110
|
|
|
$this->value = call_user_func(function () use (&$examples) { |
111
|
|
|
return array_values(array_filter($examples)); |
112
|
|
|
}); |
113
|
|
|
} |
114
|
|
|
|
115
|
|
|
$this->cache['FILE'][$_position] = array( |
116
|
|
|
'success' => $_success, |
117
|
|
|
'position' => $this->position, |
118
|
|
|
'value' => $this->value |
119
|
|
|
); |
120
|
|
|
|
121
|
|
|
if (!$_success) { |
122
|
|
|
$this->report($_position, 'FILE'); |
123
|
|
|
} |
124
|
|
|
|
125
|
|
|
return $_success; |
126
|
|
|
} |
127
|
|
|
|
128
|
|
|
protected function parseEXAMPLE() |
129
|
|
|
{ |
130
|
|
|
$_position = $this->position; |
131
|
|
|
|
132
|
|
|
if (isset($this->cache['EXAMPLE'][$_position])) { |
133
|
|
|
$_success = $this->cache['EXAMPLE'][$_position]['success']; |
134
|
|
|
$this->position = $this->cache['EXAMPLE'][$_position]['position']; |
135
|
|
|
$this->value = $this->cache['EXAMPLE'][$_position]['value']; |
136
|
|
|
|
137
|
|
|
return $_success; |
138
|
|
|
} |
139
|
|
|
|
140
|
|
|
$_position10 = $this->position; |
141
|
|
|
$_cut11 = $this->cut; |
142
|
|
|
|
143
|
|
|
$this->cut = false; |
144
|
|
|
$_success = $this->parseVISIBLE_EXAMPLE(); |
145
|
|
|
|
146
|
|
|
if (!$_success && !$this->cut) { |
147
|
|
|
$this->position = $_position10; |
148
|
|
|
|
149
|
|
|
$_success = $this->parseHIDDEN_EXAMPLE(); |
150
|
|
|
} |
151
|
|
|
|
152
|
|
|
$this->cut = $_cut11; |
153
|
|
|
|
154
|
|
|
$this->cache['EXAMPLE'][$_position] = array( |
155
|
|
|
'success' => $_success, |
156
|
|
|
'position' => $this->position, |
157
|
|
|
'value' => $this->value |
158
|
|
|
); |
159
|
|
|
|
160
|
|
|
if (!$_success) { |
161
|
|
|
$this->report($_position, 'EXAMPLE'); |
162
|
|
|
} |
163
|
|
|
|
164
|
|
|
return $_success; |
165
|
|
|
} |
166
|
|
|
|
167
|
|
|
protected function parseVISIBLE_EXAMPLE() |
168
|
|
|
{ |
169
|
|
|
$_position = $this->position; |
170
|
|
|
|
171
|
|
|
if (isset($this->cache['VISIBLE_EXAMPLE'][$_position])) { |
172
|
|
|
$_success = $this->cache['VISIBLE_EXAMPLE'][$_position]['success']; |
173
|
|
|
$this->position = $this->cache['VISIBLE_EXAMPLE'][$_position]['position']; |
174
|
|
|
$this->value = $this->cache['VISIBLE_EXAMPLE'][$_position]['value']; |
175
|
|
|
|
176
|
|
|
return $_success; |
177
|
|
|
} |
178
|
|
|
|
179
|
|
|
$_value17 = array(); |
180
|
|
|
|
181
|
|
|
$_position12 = $this->position; |
182
|
|
|
$_cut13 = $this->cut; |
183
|
|
|
|
184
|
|
|
$this->cut = false; |
185
|
|
|
$_success = $this->parseANNOTATION_GROUP(); |
186
|
|
|
|
187
|
|
|
if (!$_success && !$this->cut) { |
188
|
|
|
$_success = true; |
189
|
|
|
$this->position = $_position12; |
190
|
|
|
$this->value = null; |
191
|
|
|
} |
192
|
|
|
|
193
|
|
|
$this->cut = $_cut13; |
194
|
|
|
|
195
|
|
|
if ($_success) { |
196
|
|
|
$annots = $this->value; |
197
|
|
|
} |
198
|
|
|
|
199
|
|
|
if ($_success) { |
200
|
|
|
$_value17[] = $this->value; |
201
|
|
|
|
202
|
|
|
$_value15 = array(); |
203
|
|
|
$_cut16 = $this->cut; |
204
|
|
|
|
205
|
|
|
while (true) { |
206
|
|
|
$_position14 = $this->position; |
207
|
|
|
|
208
|
|
|
$this->cut = false; |
209
|
|
|
$_success = $this->parseEMPTY_LINE(); |
210
|
|
|
|
211
|
|
|
if (!$_success) { |
212
|
|
|
break; |
213
|
|
|
} |
214
|
|
|
|
215
|
|
|
$_value15[] = $this->value; |
216
|
|
|
} |
217
|
|
|
|
218
|
|
|
if (!$this->cut) { |
219
|
|
|
$_success = true; |
220
|
|
|
$this->position = $_position14; |
|
|
|
|
221
|
|
|
$this->value = $_value15; |
222
|
|
|
} |
223
|
|
|
|
224
|
|
|
$this->cut = $_cut16; |
225
|
|
|
} |
226
|
|
|
|
227
|
|
|
if ($_success) { |
228
|
|
|
$_value17[] = $this->value; |
229
|
|
|
|
230
|
|
|
$_success = $this->parseCODE(); |
231
|
|
|
|
232
|
|
|
if ($_success) { |
233
|
|
|
$code = $this->value; |
234
|
|
|
} |
235
|
|
|
} |
236
|
|
|
|
237
|
|
|
if ($_success) { |
238
|
|
|
$_value17[] = $this->value; |
239
|
|
|
|
240
|
|
|
$this->value = $_value17; |
241
|
|
|
} |
242
|
|
|
|
243
|
|
View Code Duplication |
if ($_success) { |
|
|
|
|
244
|
|
|
$this->value = call_user_func(function () use (&$annots, &$code) { |
245
|
|
|
return new Definition($code, ...(array)$annots); |
246
|
|
|
}); |
247
|
|
|
} |
248
|
|
|
|
249
|
|
|
$this->cache['VISIBLE_EXAMPLE'][$_position] = array( |
250
|
|
|
'success' => $_success, |
251
|
|
|
'position' => $this->position, |
252
|
|
|
'value' => $this->value |
253
|
|
|
); |
254
|
|
|
|
255
|
|
|
if (!$_success) { |
256
|
|
|
$this->report($_position, 'VISIBLE_EXAMPLE'); |
257
|
|
|
} |
258
|
|
|
|
259
|
|
|
return $_success; |
260
|
|
|
} |
261
|
|
|
|
262
|
|
|
protected function parseHIDDEN_EXAMPLE() |
263
|
|
|
{ |
264
|
|
|
$_position = $this->position; |
265
|
|
|
|
266
|
|
|
if (isset($this->cache['HIDDEN_EXAMPLE'][$_position])) { |
267
|
|
|
$_success = $this->cache['HIDDEN_EXAMPLE'][$_position]['success']; |
268
|
|
|
$this->position = $this->cache['HIDDEN_EXAMPLE'][$_position]['position']; |
269
|
|
|
$this->value = $this->cache['HIDDEN_EXAMPLE'][$_position]['value']; |
270
|
|
|
|
271
|
|
|
return $_success; |
272
|
|
|
} |
273
|
|
|
|
274
|
|
|
$_value30 = array(); |
275
|
|
|
|
276
|
|
|
$_success = $this->parseHTML_COMMENT_START(); |
277
|
|
|
|
278
|
|
View Code Duplication |
if ($_success) { |
|
|
|
|
279
|
|
|
$_value30[] = $this->value; |
280
|
|
|
|
281
|
|
|
$_value19 = array(); |
282
|
|
|
$_cut20 = $this->cut; |
283
|
|
|
|
284
|
|
|
while (true) { |
285
|
|
|
$_position18 = $this->position; |
286
|
|
|
|
287
|
|
|
$this->cut = false; |
288
|
|
|
$_success = $this->parseEMPTY_LINE(); |
289
|
|
|
|
290
|
|
|
if (!$_success) { |
291
|
|
|
break; |
292
|
|
|
} |
293
|
|
|
|
294
|
|
|
$_value19[] = $this->value; |
295
|
|
|
} |
296
|
|
|
|
297
|
|
|
if (!$this->cut) { |
298
|
|
|
$_success = true; |
299
|
|
|
$this->position = $_position18; |
|
|
|
|
300
|
|
|
$this->value = $_value19; |
301
|
|
|
} |
302
|
|
|
|
303
|
|
|
$this->cut = $_cut20; |
304
|
|
|
} |
305
|
|
|
|
306
|
|
View Code Duplication |
if ($_success) { |
|
|
|
|
307
|
|
|
$_value30[] = $this->value; |
308
|
|
|
|
309
|
|
|
$_value22 = array(); |
310
|
|
|
$_cut23 = $this->cut; |
311
|
|
|
|
312
|
|
|
while (true) { |
313
|
|
|
$_position21 = $this->position; |
314
|
|
|
|
315
|
|
|
$this->cut = false; |
316
|
|
|
$_success = $this->parseANNOTATION(); |
317
|
|
|
|
318
|
|
|
if (!$_success) { |
319
|
|
|
break; |
320
|
|
|
} |
321
|
|
|
|
322
|
|
|
$_value22[] = $this->value; |
323
|
|
|
} |
324
|
|
|
|
325
|
|
|
if (!$this->cut) { |
326
|
|
|
$_success = true; |
327
|
|
|
$this->position = $_position21; |
|
|
|
|
328
|
|
|
$this->value = $_value22; |
329
|
|
|
} |
330
|
|
|
|
331
|
|
|
$this->cut = $_cut23; |
332
|
|
|
|
333
|
|
|
if ($_success) { |
334
|
|
|
$annots = $this->value; |
335
|
|
|
} |
336
|
|
|
} |
337
|
|
|
|
338
|
|
View Code Duplication |
if ($_success) { |
|
|
|
|
339
|
|
|
$_value30[] = $this->value; |
340
|
|
|
|
341
|
|
|
$_value25 = array(); |
342
|
|
|
$_cut26 = $this->cut; |
343
|
|
|
|
344
|
|
|
while (true) { |
345
|
|
|
$_position24 = $this->position; |
346
|
|
|
|
347
|
|
|
$this->cut = false; |
348
|
|
|
$_success = $this->parseEMPTY_LINE(); |
349
|
|
|
|
350
|
|
|
if (!$_success) { |
351
|
|
|
break; |
352
|
|
|
} |
353
|
|
|
|
354
|
|
|
$_value25[] = $this->value; |
355
|
|
|
} |
356
|
|
|
|
357
|
|
|
if (!$this->cut) { |
358
|
|
|
$_success = true; |
359
|
|
|
$this->position = $_position24; |
|
|
|
|
360
|
|
|
$this->value = $_value25; |
361
|
|
|
} |
362
|
|
|
|
363
|
|
|
$this->cut = $_cut26; |
364
|
|
|
} |
365
|
|
|
|
366
|
|
|
if ($_success) { |
367
|
|
|
$_value30[] = $this->value; |
368
|
|
|
|
369
|
|
|
$_success = $this->parseCODE(); |
370
|
|
|
|
371
|
|
|
if ($_success) { |
372
|
|
|
$code = $this->value; |
373
|
|
|
} |
374
|
|
|
} |
375
|
|
|
|
376
|
|
View Code Duplication |
if ($_success) { |
|
|
|
|
377
|
|
|
$_value30[] = $this->value; |
378
|
|
|
|
379
|
|
|
$_value28 = array(); |
380
|
|
|
$_cut29 = $this->cut; |
381
|
|
|
|
382
|
|
|
while (true) { |
383
|
|
|
$_position27 = $this->position; |
384
|
|
|
|
385
|
|
|
$this->cut = false; |
386
|
|
|
$_success = $this->parseEMPTY_LINE(); |
387
|
|
|
|
388
|
|
|
if (!$_success) { |
389
|
|
|
break; |
390
|
|
|
} |
391
|
|
|
|
392
|
|
|
$_value28[] = $this->value; |
393
|
|
|
} |
394
|
|
|
|
395
|
|
|
if (!$this->cut) { |
396
|
|
|
$_success = true; |
397
|
|
|
$this->position = $_position27; |
|
|
|
|
398
|
|
|
$this->value = $_value28; |
399
|
|
|
} |
400
|
|
|
|
401
|
|
|
$this->cut = $_cut29; |
402
|
|
|
} |
403
|
|
|
|
404
|
|
|
if ($_success) { |
405
|
|
|
$_value30[] = $this->value; |
406
|
|
|
|
407
|
|
|
$_success = $this->parseHTML_COMMENT_END(); |
408
|
|
|
} |
409
|
|
|
|
410
|
|
|
if ($_success) { |
411
|
|
|
$_value30[] = $this->value; |
412
|
|
|
|
413
|
|
|
$this->value = $_value30; |
414
|
|
|
} |
415
|
|
|
|
416
|
|
View Code Duplication |
if ($_success) { |
|
|
|
|
417
|
|
|
$this->value = call_user_func(function () use (&$annots, &$code) { |
418
|
|
|
return new Definition($code, ...(array)$annots); |
419
|
|
|
}); |
420
|
|
|
} |
421
|
|
|
|
422
|
|
|
$this->cache['HIDDEN_EXAMPLE'][$_position] = array( |
423
|
|
|
'success' => $_success, |
424
|
|
|
'position' => $this->position, |
425
|
|
|
'value' => $this->value |
426
|
|
|
); |
427
|
|
|
|
428
|
|
|
if (!$_success) { |
429
|
|
|
$this->report($_position, 'HIDDEN_EXAMPLE'); |
430
|
|
|
} |
431
|
|
|
|
432
|
|
|
return $_success; |
433
|
|
|
} |
434
|
|
|
|
435
|
|
|
protected function parseANNOTATION_GROUP() |
436
|
|
|
{ |
437
|
|
|
$_position = $this->position; |
438
|
|
|
|
439
|
|
|
if (isset($this->cache['ANNOTATION_GROUP'][$_position])) { |
440
|
|
|
$_success = $this->cache['ANNOTATION_GROUP'][$_position]['success']; |
441
|
|
|
$this->position = $this->cache['ANNOTATION_GROUP'][$_position]['position']; |
442
|
|
|
$this->value = $this->cache['ANNOTATION_GROUP'][$_position]['value']; |
443
|
|
|
|
444
|
|
|
return $_success; |
445
|
|
|
} |
446
|
|
|
|
447
|
|
|
$_success = $this->parseANNOTATION_BLOCK(); |
448
|
|
|
|
449
|
|
|
if ($_success) { |
450
|
|
|
$_value32 = array($this->value); |
451
|
|
|
$_cut33 = $this->cut; |
452
|
|
|
|
453
|
|
|
while (true) { |
454
|
|
|
$_position31 = $this->position; |
455
|
|
|
|
456
|
|
|
$this->cut = false; |
457
|
|
|
$_success = $this->parseANNOTATION_BLOCK(); |
458
|
|
|
|
459
|
|
|
if (!$_success) { |
460
|
|
|
break; |
461
|
|
|
} |
462
|
|
|
|
463
|
|
|
$_value32[] = $this->value; |
464
|
|
|
} |
465
|
|
|
|
466
|
|
|
if (!$this->cut) { |
467
|
|
|
$_success = true; |
468
|
|
|
$this->position = $_position31; |
|
|
|
|
469
|
|
|
$this->value = $_value32; |
470
|
|
|
} |
471
|
|
|
|
472
|
|
|
$this->cut = $_cut33; |
473
|
|
|
} |
474
|
|
|
|
475
|
|
|
if ($_success) { |
476
|
|
|
$blocks = $this->value; |
477
|
|
|
} |
478
|
|
|
|
479
|
|
|
if ($_success) { |
480
|
|
|
$this->value = call_user_func(function () use (&$blocks) { |
481
|
|
|
return call_user_func_array('array_merge', $blocks); |
482
|
|
|
}); |
483
|
|
|
} |
484
|
|
|
|
485
|
|
|
$this->cache['ANNOTATION_GROUP'][$_position] = array( |
486
|
|
|
'success' => $_success, |
487
|
|
|
'position' => $this->position, |
488
|
|
|
'value' => $this->value |
489
|
|
|
); |
490
|
|
|
|
491
|
|
|
if (!$_success) { |
492
|
|
|
$this->report($_position, 'ANNOTATION_GROUP'); |
493
|
|
|
} |
494
|
|
|
|
495
|
|
|
return $_success; |
496
|
|
|
} |
497
|
|
|
|
498
|
|
|
protected function parseANNOTATION_BLOCK() |
499
|
|
|
{ |
500
|
|
|
$_position = $this->position; |
501
|
|
|
|
502
|
|
|
if (isset($this->cache['ANNOTATION_BLOCK'][$_position])) { |
503
|
|
|
$_success = $this->cache['ANNOTATION_BLOCK'][$_position]['success']; |
504
|
|
|
$this->position = $this->cache['ANNOTATION_BLOCK'][$_position]['position']; |
505
|
|
|
$this->value = $this->cache['ANNOTATION_BLOCK'][$_position]['value']; |
506
|
|
|
|
507
|
|
|
return $_success; |
508
|
|
|
} |
509
|
|
|
|
510
|
|
|
$_value39 = array(); |
511
|
|
|
|
512
|
|
|
$_success = $this->parseHTML_COMMENT_START(); |
513
|
|
|
|
514
|
|
|
if ($_success) { |
515
|
|
|
$_value39[] = $this->value; |
516
|
|
|
|
517
|
|
|
$_position34 = $this->position; |
518
|
|
|
$_cut35 = $this->cut; |
519
|
|
|
|
520
|
|
|
$this->cut = false; |
521
|
|
|
$_success = $this->parseANNOTATION(); |
522
|
|
|
|
523
|
|
|
if (!$_success && !$this->cut) { |
524
|
|
|
$this->position = $_position34; |
525
|
|
|
|
526
|
|
|
$_success = $this->parseEMPTY_LINE(); |
527
|
|
|
} |
528
|
|
|
|
529
|
|
|
if (!$_success && !$this->cut) { |
530
|
|
|
$this->position = $_position34; |
531
|
|
|
|
532
|
|
|
$_success = $this->parseVOID_LINE_IN_COMMENT(); |
533
|
|
|
} |
534
|
|
|
|
535
|
|
|
$this->cut = $_cut35; |
536
|
|
|
|
537
|
|
|
if ($_success) { |
538
|
|
|
$_value37 = array($this->value); |
539
|
|
|
$_cut38 = $this->cut; |
540
|
|
|
|
541
|
|
|
while (true) { |
542
|
|
|
$_position36 = $this->position; |
543
|
|
|
|
544
|
|
|
$this->cut = false; |
545
|
|
|
$_position34 = $this->position; |
546
|
|
|
$_cut35 = $this->cut; |
547
|
|
|
|
548
|
|
|
$this->cut = false; |
549
|
|
|
$_success = $this->parseANNOTATION(); |
550
|
|
|
|
551
|
|
|
if (!$_success && !$this->cut) { |
552
|
|
|
$this->position = $_position34; |
553
|
|
|
|
554
|
|
|
$_success = $this->parseEMPTY_LINE(); |
555
|
|
|
} |
556
|
|
|
|
557
|
|
|
if (!$_success && !$this->cut) { |
558
|
|
|
$this->position = $_position34; |
559
|
|
|
|
560
|
|
|
$_success = $this->parseVOID_LINE_IN_COMMENT(); |
561
|
|
|
} |
562
|
|
|
|
563
|
|
|
$this->cut = $_cut35; |
564
|
|
|
|
565
|
|
|
if (!$_success) { |
566
|
|
|
break; |
567
|
|
|
} |
568
|
|
|
|
569
|
|
|
$_value37[] = $this->value; |
570
|
|
|
} |
571
|
|
|
|
572
|
|
|
if (!$this->cut) { |
573
|
|
|
$_success = true; |
574
|
|
|
$this->position = $_position36; |
|
|
|
|
575
|
|
|
$this->value = $_value37; |
576
|
|
|
} |
577
|
|
|
|
578
|
|
|
$this->cut = $_cut38; |
579
|
|
|
} |
580
|
|
|
|
581
|
|
|
if ($_success) { |
582
|
|
|
$annots = $this->value; |
583
|
|
|
} |
584
|
|
|
} |
585
|
|
|
|
586
|
|
|
if ($_success) { |
587
|
|
|
$_value39[] = $this->value; |
588
|
|
|
|
589
|
|
|
$_success = $this->parseHTML_COMMENT_END(); |
590
|
|
|
} |
591
|
|
|
|
592
|
|
|
if ($_success) { |
593
|
|
|
$_value39[] = $this->value; |
594
|
|
|
|
595
|
|
|
$this->value = $_value39; |
596
|
|
|
} |
597
|
|
|
|
598
|
|
|
if ($_success) { |
599
|
|
|
$this->value = call_user_func(function () use (&$annots) { |
600
|
|
|
return array_filter($annots); |
601
|
|
|
}); |
602
|
|
|
} |
603
|
|
|
|
604
|
|
|
$this->cache['ANNOTATION_BLOCK'][$_position] = array( |
605
|
|
|
'success' => $_success, |
606
|
|
|
'position' => $this->position, |
607
|
|
|
'value' => $this->value |
608
|
|
|
); |
609
|
|
|
|
610
|
|
|
if (!$_success) { |
611
|
|
|
$this->report($_position, 'ANNOTATION_BLOCK'); |
612
|
|
|
} |
613
|
|
|
|
614
|
|
|
return $_success; |
615
|
|
|
} |
616
|
|
|
|
617
|
|
|
protected function parseANNOTATION() |
618
|
|
|
{ |
619
|
|
|
$_position = $this->position; |
620
|
|
|
|
621
|
|
|
if (isset($this->cache['ANNOTATION'][$_position])) { |
622
|
|
|
$_success = $this->cache['ANNOTATION'][$_position]['success']; |
623
|
|
|
$this->position = $this->cache['ANNOTATION'][$_position]['position']; |
624
|
|
|
$this->value = $this->cache['ANNOTATION'][$_position]['value']; |
625
|
|
|
|
626
|
|
|
return $_success; |
627
|
|
|
} |
628
|
|
|
|
629
|
|
|
$_value45 = array(); |
630
|
|
|
|
631
|
|
|
$_success = $this->parse_(); |
632
|
|
|
|
633
|
|
View Code Duplication |
if ($_success) { |
|
|
|
|
634
|
|
|
$_value45[] = $this->value; |
635
|
|
|
|
636
|
|
|
if (substr($this->string, $this->position, strlen('@')) === '@') { |
637
|
|
|
$_success = true; |
638
|
|
|
$this->value = substr($this->string, $this->position, strlen('@')); |
639
|
|
|
$this->position += strlen('@'); |
640
|
|
|
} else { |
641
|
|
|
$_success = false; |
642
|
|
|
|
643
|
|
|
$this->report($this->position, '\'@\''); |
644
|
|
|
} |
645
|
|
|
} |
646
|
|
|
|
647
|
|
|
if ($_success) { |
648
|
|
|
$_value45[] = $this->value; |
649
|
|
|
|
650
|
|
|
$_success = $this->parseSTRING(); |
651
|
|
|
|
652
|
|
|
if ($_success) { |
653
|
|
|
$name = $this->value; |
654
|
|
|
} |
655
|
|
|
} |
656
|
|
|
|
657
|
|
|
if ($_success) { |
658
|
|
|
$_value45[] = $this->value; |
659
|
|
|
|
660
|
|
|
$_value41 = array(); |
661
|
|
|
$_cut42 = $this->cut; |
662
|
|
|
|
663
|
|
|
while (true) { |
664
|
|
|
$_position40 = $this->position; |
665
|
|
|
|
666
|
|
|
$this->cut = false; |
667
|
|
|
$_success = $this->parseSTRING(); |
668
|
|
|
|
669
|
|
|
if (!$_success) { |
670
|
|
|
break; |
671
|
|
|
} |
672
|
|
|
|
673
|
|
|
$_value41[] = $this->value; |
674
|
|
|
} |
675
|
|
|
|
676
|
|
|
if (!$this->cut) { |
677
|
|
|
$_success = true; |
678
|
|
|
$this->position = $_position40; |
|
|
|
|
679
|
|
|
$this->value = $_value41; |
680
|
|
|
} |
681
|
|
|
|
682
|
|
|
$this->cut = $_cut42; |
683
|
|
|
|
684
|
|
|
if ($_success) { |
685
|
|
|
$args = $this->value; |
686
|
|
|
} |
687
|
|
|
} |
688
|
|
|
|
689
|
|
View Code Duplication |
if ($_success) { |
|
|
|
|
690
|
|
|
$_value45[] = $this->value; |
691
|
|
|
|
692
|
|
|
$_position43 = $this->position; |
693
|
|
|
$_cut44 = $this->cut; |
694
|
|
|
|
695
|
|
|
$this->cut = false; |
696
|
|
|
$_success = $this->parseEOL(); |
697
|
|
|
|
698
|
|
|
if (!$_success && !$this->cut) { |
699
|
|
|
$_success = true; |
700
|
|
|
$this->position = $_position43; |
701
|
|
|
$this->value = null; |
702
|
|
|
} |
703
|
|
|
|
704
|
|
|
$this->cut = $_cut44; |
705
|
|
|
} |
706
|
|
|
|
707
|
|
|
if ($_success) { |
708
|
|
|
$_value45[] = $this->value; |
709
|
|
|
|
710
|
|
|
$this->value = $_value45; |
711
|
|
|
} |
712
|
|
|
|
713
|
|
|
if ($_success) { |
714
|
|
|
$this->value = call_user_func(function () use (&$name, &$args) { |
715
|
|
|
return new Annotation($name, ...$args); |
716
|
|
|
}); |
717
|
|
|
} |
718
|
|
|
|
719
|
|
|
$this->cache['ANNOTATION'][$_position] = array( |
720
|
|
|
'success' => $_success, |
721
|
|
|
'position' => $this->position, |
722
|
|
|
'value' => $this->value |
723
|
|
|
); |
724
|
|
|
|
725
|
|
|
if (!$_success) { |
726
|
|
|
$this->report($_position, 'ANNOTATION'); |
727
|
|
|
} |
728
|
|
|
|
729
|
|
|
return $_success; |
730
|
|
|
} |
731
|
|
|
|
732
|
|
|
protected function parseSTRING() |
733
|
|
|
{ |
734
|
|
|
$_position = $this->position; |
735
|
|
|
|
736
|
|
|
if (isset($this->cache['STRING'][$_position])) { |
737
|
|
|
$_success = $this->cache['STRING'][$_position]['success']; |
738
|
|
|
$this->position = $this->cache['STRING'][$_position]['position']; |
739
|
|
|
$this->value = $this->cache['STRING'][$_position]['value']; |
740
|
|
|
|
741
|
|
|
return $_success; |
742
|
|
|
} |
743
|
|
|
|
744
|
|
|
$_value48 = array(); |
745
|
|
|
|
746
|
|
|
$_success = $this->parse_(); |
747
|
|
|
|
748
|
|
|
if ($_success) { |
749
|
|
|
$_value48[] = $this->value; |
750
|
|
|
|
751
|
|
|
$_position46 = $this->position; |
752
|
|
|
$_cut47 = $this->cut; |
753
|
|
|
|
754
|
|
|
$this->cut = false; |
755
|
|
|
$_success = $this->parseRAW_STRING(); |
756
|
|
|
|
757
|
|
|
if (!$_success && !$this->cut) { |
758
|
|
|
$this->position = $_position46; |
759
|
|
|
|
760
|
|
|
$_success = $this->parseQUOTED_STRING(); |
761
|
|
|
} |
762
|
|
|
|
763
|
|
|
if (!$_success && !$this->cut) { |
764
|
|
|
$this->position = $_position46; |
765
|
|
|
|
766
|
|
|
$_success = $this->parseEMPTY_STRING(); |
767
|
|
|
} |
768
|
|
|
|
769
|
|
|
$this->cut = $_cut47; |
770
|
|
|
|
771
|
|
|
if ($_success) { |
772
|
|
|
$string = $this->value; |
773
|
|
|
} |
774
|
|
|
} |
775
|
|
|
|
776
|
|
|
if ($_success) { |
777
|
|
|
$_value48[] = $this->value; |
778
|
|
|
|
779
|
|
|
$_success = $this->parse_(); |
780
|
|
|
} |
781
|
|
|
|
782
|
|
|
if ($_success) { |
783
|
|
|
$_value48[] = $this->value; |
784
|
|
|
|
785
|
|
|
$this->value = $_value48; |
786
|
|
|
} |
787
|
|
|
|
788
|
|
|
if ($_success) { |
789
|
|
|
$this->value = call_user_func(function () use (&$string) { |
790
|
|
|
return $string; |
791
|
|
|
}); |
792
|
|
|
} |
793
|
|
|
|
794
|
|
|
$this->cache['STRING'][$_position] = array( |
795
|
|
|
'success' => $_success, |
796
|
|
|
'position' => $this->position, |
797
|
|
|
'value' => $this->value |
798
|
|
|
); |
799
|
|
|
|
800
|
|
|
if (!$_success) { |
801
|
|
|
$this->report($_position, 'STRING'); |
802
|
|
|
} |
803
|
|
|
|
804
|
|
|
return $_success; |
805
|
|
|
} |
806
|
|
|
|
807
|
|
View Code Duplication |
protected function parseEMPTY_STRING() |
|
|
|
|
808
|
|
|
{ |
809
|
|
|
$_position = $this->position; |
810
|
|
|
|
811
|
|
|
if (isset($this->cache['EMPTY_STRING'][$_position])) { |
812
|
|
|
$_success = $this->cache['EMPTY_STRING'][$_position]['success']; |
813
|
|
|
$this->position = $this->cache['EMPTY_STRING'][$_position]['position']; |
814
|
|
|
$this->value = $this->cache['EMPTY_STRING'][$_position]['value']; |
815
|
|
|
|
816
|
|
|
return $_success; |
817
|
|
|
} |
818
|
|
|
|
819
|
|
|
if (substr($this->string, $this->position, strlen('""')) === '""') { |
820
|
|
|
$_success = true; |
821
|
|
|
$this->value = substr($this->string, $this->position, strlen('""')); |
822
|
|
|
$this->position += strlen('""'); |
823
|
|
|
} else { |
824
|
|
|
$_success = false; |
825
|
|
|
|
826
|
|
|
$this->report($this->position, '\'""\''); |
827
|
|
|
} |
828
|
|
|
|
829
|
|
|
if ($_success) { |
830
|
|
|
$this->value = call_user_func(function () { |
831
|
|
|
return ''; |
832
|
|
|
}); |
833
|
|
|
} |
834
|
|
|
|
835
|
|
|
$this->cache['EMPTY_STRING'][$_position] = array( |
836
|
|
|
'success' => $_success, |
837
|
|
|
'position' => $this->position, |
838
|
|
|
'value' => $this->value |
839
|
|
|
); |
840
|
|
|
|
841
|
|
|
if (!$_success) { |
842
|
|
|
$this->report($_position, 'EMPTY_STRING'); |
843
|
|
|
} |
844
|
|
|
|
845
|
|
|
return $_success; |
846
|
|
|
} |
847
|
|
|
|
848
|
|
|
protected function parseQUOTED_STRING() |
849
|
|
|
{ |
850
|
|
|
$_position = $this->position; |
851
|
|
|
|
852
|
|
|
if (isset($this->cache['QUOTED_STRING'][$_position])) { |
853
|
|
|
$_success = $this->cache['QUOTED_STRING'][$_position]['success']; |
854
|
|
|
$this->position = $this->cache['QUOTED_STRING'][$_position]['position']; |
855
|
|
|
$this->value = $this->cache['QUOTED_STRING'][$_position]['value']; |
856
|
|
|
|
857
|
|
|
return $_success; |
858
|
|
|
} |
859
|
|
|
|
860
|
|
|
$_value54 = array(); |
861
|
|
|
|
862
|
|
|
if (substr($this->string, $this->position, strlen('"')) === '"') { |
863
|
|
|
$_success = true; |
864
|
|
|
$this->value = substr($this->string, $this->position, strlen('"')); |
865
|
|
|
$this->position += strlen('"'); |
866
|
|
|
} else { |
867
|
|
|
$_success = false; |
868
|
|
|
|
869
|
|
|
$this->report($this->position, '\'"\''); |
870
|
|
|
} |
871
|
|
|
|
872
|
|
|
if ($_success) { |
873
|
|
|
$_value54[] = $this->value; |
874
|
|
|
|
875
|
|
|
$_value52 = array(); |
876
|
|
|
$_cut53 = $this->cut; |
877
|
|
|
|
878
|
|
|
while (true) { |
879
|
|
|
$_position51 = $this->position; |
880
|
|
|
|
881
|
|
|
$this->cut = false; |
882
|
|
|
$_position49 = $this->position; |
883
|
|
|
$_cut50 = $this->cut; |
884
|
|
|
|
885
|
|
|
$this->cut = false; |
886
|
|
|
$_success = $this->parseESCAPED_QUOTE(); |
887
|
|
|
|
888
|
|
View Code Duplication |
if (!$_success && !$this->cut) { |
|
|
|
|
889
|
|
|
$this->position = $_position49; |
890
|
|
|
|
891
|
|
|
if (substr($this->string, $this->position, strlen(' ')) === ' ') { |
892
|
|
|
$_success = true; |
893
|
|
|
$this->value = substr($this->string, $this->position, strlen(' ')); |
894
|
|
|
$this->position += strlen(' '); |
895
|
|
|
} else { |
896
|
|
|
$_success = false; |
897
|
|
|
|
898
|
|
|
$this->report($this->position, '\' \''); |
899
|
|
|
} |
900
|
|
|
} |
901
|
|
|
|
902
|
|
|
if (!$_success && !$this->cut) { |
903
|
|
|
$this->position = $_position49; |
904
|
|
|
|
905
|
|
|
$_success = $this->parseRAW_STRING(); |
906
|
|
|
} |
907
|
|
|
|
908
|
|
|
$this->cut = $_cut50; |
909
|
|
|
|
910
|
|
|
if (!$_success) { |
911
|
|
|
break; |
912
|
|
|
} |
913
|
|
|
|
914
|
|
|
$_value52[] = $this->value; |
915
|
|
|
} |
916
|
|
|
|
917
|
|
|
if (!$this->cut) { |
918
|
|
|
$_success = true; |
919
|
|
|
$this->position = $_position51; |
|
|
|
|
920
|
|
|
$this->value = $_value52; |
921
|
|
|
} |
922
|
|
|
|
923
|
|
|
$this->cut = $_cut53; |
924
|
|
|
|
925
|
|
|
if ($_success) { |
926
|
|
|
$string = $this->value; |
927
|
|
|
} |
928
|
|
|
} |
929
|
|
|
|
930
|
|
View Code Duplication |
if ($_success) { |
|
|
|
|
931
|
|
|
$_value54[] = $this->value; |
932
|
|
|
|
933
|
|
|
if (substr($this->string, $this->position, strlen('"')) === '"') { |
934
|
|
|
$_success = true; |
935
|
|
|
$this->value = substr($this->string, $this->position, strlen('"')); |
936
|
|
|
$this->position += strlen('"'); |
937
|
|
|
} else { |
938
|
|
|
$_success = false; |
939
|
|
|
|
940
|
|
|
$this->report($this->position, '\'"\''); |
941
|
|
|
} |
942
|
|
|
} |
943
|
|
|
|
944
|
|
|
if ($_success) { |
945
|
|
|
$_value54[] = $this->value; |
946
|
|
|
|
947
|
|
|
$this->value = $_value54; |
948
|
|
|
} |
949
|
|
|
|
950
|
|
|
if ($_success) { |
951
|
|
|
$this->value = call_user_func(function () use (&$string) { |
952
|
|
|
return implode($string); |
953
|
|
|
}); |
954
|
|
|
} |
955
|
|
|
|
956
|
|
|
$this->cache['QUOTED_STRING'][$_position] = array( |
957
|
|
|
'success' => $_success, |
958
|
|
|
'position' => $this->position, |
959
|
|
|
'value' => $this->value |
960
|
|
|
); |
961
|
|
|
|
962
|
|
|
if (!$_success) { |
963
|
|
|
$this->report($_position, 'QUOTED_STRING'); |
964
|
|
|
} |
965
|
|
|
|
966
|
|
|
return $_success; |
967
|
|
|
} |
968
|
|
|
|
969
|
|
View Code Duplication |
protected function parseESCAPED_QUOTE() |
|
|
|
|
970
|
|
|
{ |
971
|
|
|
$_position = $this->position; |
972
|
|
|
|
973
|
|
|
if (isset($this->cache['ESCAPED_QUOTE'][$_position])) { |
974
|
|
|
$_success = $this->cache['ESCAPED_QUOTE'][$_position]['success']; |
975
|
|
|
$this->position = $this->cache['ESCAPED_QUOTE'][$_position]['position']; |
976
|
|
|
$this->value = $this->cache['ESCAPED_QUOTE'][$_position]['value']; |
977
|
|
|
|
978
|
|
|
return $_success; |
979
|
|
|
} |
980
|
|
|
|
981
|
|
|
if (substr($this->string, $this->position, strlen('\"')) === '\"') { |
982
|
|
|
$_success = true; |
983
|
|
|
$this->value = substr($this->string, $this->position, strlen('\"')); |
984
|
|
|
$this->position += strlen('\"'); |
985
|
|
|
} else { |
986
|
|
|
$_success = false; |
987
|
|
|
|
988
|
|
|
$this->report($this->position, '\'\\"\''); |
989
|
|
|
} |
990
|
|
|
|
991
|
|
|
if ($_success) { |
992
|
|
|
$this->value = call_user_func(function () { |
993
|
|
|
return '"'; |
994
|
|
|
}); |
995
|
|
|
} |
996
|
|
|
|
997
|
|
|
$this->cache['ESCAPED_QUOTE'][$_position] = array( |
998
|
|
|
'success' => $_success, |
999
|
|
|
'position' => $this->position, |
1000
|
|
|
'value' => $this->value |
1001
|
|
|
); |
1002
|
|
|
|
1003
|
|
|
if (!$_success) { |
1004
|
|
|
$this->report($_position, 'ESCAPED_QUOTE'); |
1005
|
|
|
} |
1006
|
|
|
|
1007
|
|
|
return $_success; |
1008
|
|
|
} |
1009
|
|
|
|
1010
|
|
|
protected function parseRAW_STRING() |
1011
|
|
|
{ |
1012
|
|
|
$_position = $this->position; |
1013
|
|
|
|
1014
|
|
|
if (isset($this->cache['RAW_STRING'][$_position])) { |
1015
|
|
|
$_success = $this->cache['RAW_STRING'][$_position]['success']; |
1016
|
|
|
$this->position = $this->cache['RAW_STRING'][$_position]['position']; |
1017
|
|
|
$this->value = $this->cache['RAW_STRING'][$_position]['value']; |
1018
|
|
|
|
1019
|
|
|
return $_success; |
1020
|
|
|
} |
1021
|
|
|
|
1022
|
|
|
$_position63 = $this->position; |
1023
|
|
|
|
1024
|
|
|
$_value59 = array(); |
1025
|
|
|
|
1026
|
|
|
$_position57 = $this->position; |
1027
|
|
|
$_cut58 = $this->cut; |
1028
|
|
|
|
1029
|
|
|
$this->cut = false; |
1030
|
|
|
$_position55 = $this->position; |
1031
|
|
|
$_cut56 = $this->cut; |
1032
|
|
|
|
1033
|
|
|
$this->cut = false; |
1034
|
|
|
if (substr($this->string, $this->position, strlen(' ')) === ' ') { |
1035
|
|
|
$_success = true; |
1036
|
|
|
$this->value = substr($this->string, $this->position, strlen(' ')); |
1037
|
|
|
$this->position += strlen(' '); |
1038
|
|
|
} else { |
1039
|
|
|
$_success = false; |
1040
|
|
|
|
1041
|
|
|
$this->report($this->position, '\' \''); |
1042
|
|
|
} |
1043
|
|
|
|
1044
|
|
View Code Duplication |
if (!$_success && !$this->cut) { |
|
|
|
|
1045
|
|
|
$this->position = $_position55; |
1046
|
|
|
|
1047
|
|
|
if (substr($this->string, $this->position, strlen("\r")) === "\r") { |
1048
|
|
|
$_success = true; |
1049
|
|
|
$this->value = substr($this->string, $this->position, strlen("\r")); |
1050
|
|
|
$this->position += strlen("\r"); |
1051
|
|
|
} else { |
1052
|
|
|
$_success = false; |
1053
|
|
|
|
1054
|
|
|
$this->report($this->position, '"\\r"'); |
1055
|
|
|
} |
1056
|
|
|
} |
1057
|
|
|
|
1058
|
|
View Code Duplication |
if (!$_success && !$this->cut) { |
|
|
|
|
1059
|
|
|
$this->position = $_position55; |
1060
|
|
|
|
1061
|
|
|
if (substr($this->string, $this->position, strlen("\n")) === "\n") { |
1062
|
|
|
$_success = true; |
1063
|
|
|
$this->value = substr($this->string, $this->position, strlen("\n")); |
1064
|
|
|
$this->position += strlen("\n"); |
1065
|
|
|
} else { |
1066
|
|
|
$_success = false; |
1067
|
|
|
|
1068
|
|
|
$this->report($this->position, '"\\n"'); |
1069
|
|
|
} |
1070
|
|
|
} |
1071
|
|
|
|
1072
|
|
View Code Duplication |
if (!$_success && !$this->cut) { |
|
|
|
|
1073
|
|
|
$this->position = $_position55; |
1074
|
|
|
|
1075
|
|
|
if (substr($this->string, $this->position, strlen("\t")) === "\t") { |
1076
|
|
|
$_success = true; |
1077
|
|
|
$this->value = substr($this->string, $this->position, strlen("\t")); |
1078
|
|
|
$this->position += strlen("\t"); |
1079
|
|
|
} else { |
1080
|
|
|
$_success = false; |
1081
|
|
|
|
1082
|
|
|
$this->report($this->position, '"\\t"'); |
1083
|
|
|
} |
1084
|
|
|
} |
1085
|
|
|
|
1086
|
|
View Code Duplication |
if (!$_success && !$this->cut) { |
|
|
|
|
1087
|
|
|
$this->position = $_position55; |
1088
|
|
|
|
1089
|
|
|
if (substr($this->string, $this->position, strlen('-->')) === '-->') { |
1090
|
|
|
$_success = true; |
1091
|
|
|
$this->value = substr($this->string, $this->position, strlen('-->')); |
1092
|
|
|
$this->position += strlen('-->'); |
1093
|
|
|
} else { |
1094
|
|
|
$_success = false; |
1095
|
|
|
|
1096
|
|
|
$this->report($this->position, '\'-->\''); |
1097
|
|
|
} |
1098
|
|
|
} |
1099
|
|
|
|
1100
|
|
View Code Duplication |
if (!$_success && !$this->cut) { |
|
|
|
|
1101
|
|
|
$this->position = $_position55; |
1102
|
|
|
|
1103
|
|
|
if (substr($this->string, $this->position, strlen('"')) === '"') { |
1104
|
|
|
$_success = true; |
1105
|
|
|
$this->value = substr($this->string, $this->position, strlen('"')); |
1106
|
|
|
$this->position += strlen('"'); |
1107
|
|
|
} else { |
1108
|
|
|
$_success = false; |
1109
|
|
|
|
1110
|
|
|
$this->report($this->position, '\'"\''); |
1111
|
|
|
} |
1112
|
|
|
} |
1113
|
|
|
|
1114
|
|
|
$this->cut = $_cut56; |
1115
|
|
|
|
1116
|
|
|
if (!$_success) { |
1117
|
|
|
$_success = true; |
1118
|
|
|
$this->value = null; |
1119
|
|
|
} else { |
1120
|
|
|
$_success = false; |
1121
|
|
|
} |
1122
|
|
|
|
1123
|
|
|
$this->position = $_position57; |
1124
|
|
|
$this->cut = $_cut58; |
1125
|
|
|
|
1126
|
|
|
if ($_success) { |
1127
|
|
|
$_value59[] = $this->value; |
1128
|
|
|
|
1129
|
|
|
if ($this->position < strlen($this->string)) { |
1130
|
|
|
$_success = true; |
1131
|
|
|
$this->value = substr($this->string, $this->position, 1); |
1132
|
|
|
$this->position += 1; |
1133
|
|
|
} else { |
1134
|
|
|
$_success = false; |
1135
|
|
|
} |
1136
|
|
|
} |
1137
|
|
|
|
1138
|
|
|
if ($_success) { |
1139
|
|
|
$_value59[] = $this->value; |
1140
|
|
|
|
1141
|
|
|
$this->value = $_value59; |
1142
|
|
|
} |
1143
|
|
|
|
1144
|
|
|
if ($_success) { |
1145
|
|
|
$_value61 = array($this->value); |
1146
|
|
|
$_cut62 = $this->cut; |
1147
|
|
|
|
1148
|
|
|
while (true) { |
1149
|
|
|
$_position60 = $this->position; |
1150
|
|
|
|
1151
|
|
|
$this->cut = false; |
1152
|
|
|
$_value59 = array(); |
1153
|
|
|
|
1154
|
|
|
$_position57 = $this->position; |
1155
|
|
|
$_cut58 = $this->cut; |
1156
|
|
|
|
1157
|
|
|
$this->cut = false; |
1158
|
|
|
$_position55 = $this->position; |
1159
|
|
|
$_cut56 = $this->cut; |
1160
|
|
|
|
1161
|
|
|
$this->cut = false; |
1162
|
|
|
if (substr($this->string, $this->position, strlen(' ')) === ' ') { |
1163
|
|
|
$_success = true; |
1164
|
|
|
$this->value = substr($this->string, $this->position, strlen(' ')); |
1165
|
|
|
$this->position += strlen(' '); |
1166
|
|
|
} else { |
1167
|
|
|
$_success = false; |
1168
|
|
|
|
1169
|
|
|
$this->report($this->position, '\' \''); |
1170
|
|
|
} |
1171
|
|
|
|
1172
|
|
View Code Duplication |
if (!$_success && !$this->cut) { |
|
|
|
|
1173
|
|
|
$this->position = $_position55; |
1174
|
|
|
|
1175
|
|
|
if (substr($this->string, $this->position, strlen("\r")) === "\r") { |
1176
|
|
|
$_success = true; |
1177
|
|
|
$this->value = substr($this->string, $this->position, strlen("\r")); |
1178
|
|
|
$this->position += strlen("\r"); |
1179
|
|
|
} else { |
1180
|
|
|
$_success = false; |
1181
|
|
|
|
1182
|
|
|
$this->report($this->position, '"\\r"'); |
1183
|
|
|
} |
1184
|
|
|
} |
1185
|
|
|
|
1186
|
|
View Code Duplication |
if (!$_success && !$this->cut) { |
|
|
|
|
1187
|
|
|
$this->position = $_position55; |
1188
|
|
|
|
1189
|
|
|
if (substr($this->string, $this->position, strlen("\n")) === "\n") { |
1190
|
|
|
$_success = true; |
1191
|
|
|
$this->value = substr($this->string, $this->position, strlen("\n")); |
1192
|
|
|
$this->position += strlen("\n"); |
1193
|
|
|
} else { |
1194
|
|
|
$_success = false; |
1195
|
|
|
|
1196
|
|
|
$this->report($this->position, '"\\n"'); |
1197
|
|
|
} |
1198
|
|
|
} |
1199
|
|
|
|
1200
|
|
View Code Duplication |
if (!$_success && !$this->cut) { |
|
|
|
|
1201
|
|
|
$this->position = $_position55; |
1202
|
|
|
|
1203
|
|
|
if (substr($this->string, $this->position, strlen("\t")) === "\t") { |
1204
|
|
|
$_success = true; |
1205
|
|
|
$this->value = substr($this->string, $this->position, strlen("\t")); |
1206
|
|
|
$this->position += strlen("\t"); |
1207
|
|
|
} else { |
1208
|
|
|
$_success = false; |
1209
|
|
|
|
1210
|
|
|
$this->report($this->position, '"\\t"'); |
1211
|
|
|
} |
1212
|
|
|
} |
1213
|
|
|
|
1214
|
|
View Code Duplication |
if (!$_success && !$this->cut) { |
|
|
|
|
1215
|
|
|
$this->position = $_position55; |
1216
|
|
|
|
1217
|
|
|
if (substr($this->string, $this->position, strlen('-->')) === '-->') { |
1218
|
|
|
$_success = true; |
1219
|
|
|
$this->value = substr($this->string, $this->position, strlen('-->')); |
1220
|
|
|
$this->position += strlen('-->'); |
1221
|
|
|
} else { |
1222
|
|
|
$_success = false; |
1223
|
|
|
|
1224
|
|
|
$this->report($this->position, '\'-->\''); |
1225
|
|
|
} |
1226
|
|
|
} |
1227
|
|
|
|
1228
|
|
View Code Duplication |
if (!$_success && !$this->cut) { |
|
|
|
|
1229
|
|
|
$this->position = $_position55; |
1230
|
|
|
|
1231
|
|
|
if (substr($this->string, $this->position, strlen('"')) === '"') { |
1232
|
|
|
$_success = true; |
1233
|
|
|
$this->value = substr($this->string, $this->position, strlen('"')); |
1234
|
|
|
$this->position += strlen('"'); |
1235
|
|
|
} else { |
1236
|
|
|
$_success = false; |
1237
|
|
|
|
1238
|
|
|
$this->report($this->position, '\'"\''); |
1239
|
|
|
} |
1240
|
|
|
} |
1241
|
|
|
|
1242
|
|
|
$this->cut = $_cut56; |
1243
|
|
|
|
1244
|
|
|
if (!$_success) { |
1245
|
|
|
$_success = true; |
1246
|
|
|
$this->value = null; |
1247
|
|
|
} else { |
1248
|
|
|
$_success = false; |
1249
|
|
|
} |
1250
|
|
|
|
1251
|
|
|
$this->position = $_position57; |
1252
|
|
|
$this->cut = $_cut58; |
1253
|
|
|
|
1254
|
|
|
if ($_success) { |
1255
|
|
|
$_value59[] = $this->value; |
1256
|
|
|
|
1257
|
|
|
if ($this->position < strlen($this->string)) { |
1258
|
|
|
$_success = true; |
1259
|
|
|
$this->value = substr($this->string, $this->position, 1); |
1260
|
|
|
$this->position += 1; |
1261
|
|
|
} else { |
1262
|
|
|
$_success = false; |
1263
|
|
|
} |
1264
|
|
|
} |
1265
|
|
|
|
1266
|
|
|
if ($_success) { |
1267
|
|
|
$_value59[] = $this->value; |
1268
|
|
|
|
1269
|
|
|
$this->value = $_value59; |
1270
|
|
|
} |
1271
|
|
|
|
1272
|
|
|
if (!$_success) { |
1273
|
|
|
break; |
1274
|
|
|
} |
1275
|
|
|
|
1276
|
|
|
$_value61[] = $this->value; |
1277
|
|
|
} |
1278
|
|
|
|
1279
|
|
|
if (!$this->cut) { |
1280
|
|
|
$_success = true; |
1281
|
|
|
$this->position = $_position60; |
|
|
|
|
1282
|
|
|
$this->value = $_value61; |
1283
|
|
|
} |
1284
|
|
|
|
1285
|
|
|
$this->cut = $_cut62; |
1286
|
|
|
} |
1287
|
|
|
|
1288
|
|
View Code Duplication |
if ($_success) { |
|
|
|
|
1289
|
|
|
$this->value = strval(substr($this->string, $_position63, $this->position - $_position63)); |
1290
|
|
|
} |
1291
|
|
|
|
1292
|
|
|
$this->cache['RAW_STRING'][$_position] = array( |
1293
|
|
|
'success' => $_success, |
1294
|
|
|
'position' => $this->position, |
1295
|
|
|
'value' => $this->value |
1296
|
|
|
); |
1297
|
|
|
|
1298
|
|
|
if (!$_success) { |
1299
|
|
|
$this->report($_position, 'RAW_STRING'); |
1300
|
|
|
} |
1301
|
|
|
|
1302
|
|
|
return $_success; |
1303
|
|
|
} |
1304
|
|
|
|
1305
|
|
|
protected function parseCODE() |
1306
|
|
|
{ |
1307
|
|
|
$_position = $this->position; |
1308
|
|
|
|
1309
|
|
|
if (isset($this->cache['CODE'][$_position])) { |
1310
|
|
|
$_success = $this->cache['CODE'][$_position]['success']; |
1311
|
|
|
$this->position = $this->cache['CODE'][$_position]['position']; |
1312
|
|
|
$this->value = $this->cache['CODE'][$_position]['value']; |
1313
|
|
|
|
1314
|
|
|
return $_success; |
1315
|
|
|
} |
1316
|
|
|
|
1317
|
|
|
$_value71 = array(); |
1318
|
|
|
|
1319
|
|
|
$_success = $this->parseCODE_START(); |
1320
|
|
|
|
1321
|
|
|
if ($_success) { |
1322
|
|
|
$_value71[] = $this->value; |
1323
|
|
|
|
1324
|
|
|
$_position70 = $this->position; |
1325
|
|
|
|
1326
|
|
|
$_value68 = array(); |
1327
|
|
|
$_cut69 = $this->cut; |
1328
|
|
|
|
1329
|
|
View Code Duplication |
while (true) { |
|
|
|
|
1330
|
|
|
$_position67 = $this->position; |
1331
|
|
|
|
1332
|
|
|
$this->cut = false; |
1333
|
|
|
$_value66 = array(); |
1334
|
|
|
|
1335
|
|
|
$_position64 = $this->position; |
1336
|
|
|
$_cut65 = $this->cut; |
1337
|
|
|
|
1338
|
|
|
$this->cut = false; |
1339
|
|
|
$_success = $this->parseCODE_END(); |
1340
|
|
|
|
1341
|
|
|
if (!$_success) { |
1342
|
|
|
$_success = true; |
1343
|
|
|
$this->value = null; |
1344
|
|
|
} else { |
1345
|
|
|
$_success = false; |
1346
|
|
|
} |
1347
|
|
|
|
1348
|
|
|
$this->position = $_position64; |
1349
|
|
|
$this->cut = $_cut65; |
1350
|
|
|
|
1351
|
|
|
if ($_success) { |
1352
|
|
|
$_value66[] = $this->value; |
1353
|
|
|
|
1354
|
|
|
if ($this->position < strlen($this->string)) { |
1355
|
|
|
$_success = true; |
1356
|
|
|
$this->value = substr($this->string, $this->position, 1); |
1357
|
|
|
$this->position += 1; |
1358
|
|
|
} else { |
1359
|
|
|
$_success = false; |
1360
|
|
|
} |
1361
|
|
|
} |
1362
|
|
|
|
1363
|
|
|
if ($_success) { |
1364
|
|
|
$_value66[] = $this->value; |
1365
|
|
|
|
1366
|
|
|
$this->value = $_value66; |
1367
|
|
|
} |
1368
|
|
|
|
1369
|
|
|
if (!$_success) { |
1370
|
|
|
break; |
1371
|
|
|
} |
1372
|
|
|
|
1373
|
|
|
$_value68[] = $this->value; |
1374
|
|
|
} |
1375
|
|
|
|
1376
|
|
|
if (!$this->cut) { |
1377
|
|
|
$_success = true; |
1378
|
|
|
$this->position = $_position67; |
|
|
|
|
1379
|
|
|
$this->value = $_value68; |
1380
|
|
|
} |
1381
|
|
|
|
1382
|
|
|
$this->cut = $_cut69; |
1383
|
|
|
|
1384
|
|
View Code Duplication |
if ($_success) { |
|
|
|
|
1385
|
|
|
$this->value = strval(substr($this->string, $_position70, $this->position - $_position70)); |
1386
|
|
|
} |
1387
|
|
|
|
1388
|
|
|
if ($_success) { |
1389
|
|
|
$code = $this->value; |
1390
|
|
|
} |
1391
|
|
|
} |
1392
|
|
|
|
1393
|
|
|
if ($_success) { |
1394
|
|
|
$_value71[] = $this->value; |
1395
|
|
|
|
1396
|
|
|
$_success = $this->parseCODE_END(); |
1397
|
|
|
} |
1398
|
|
|
|
1399
|
|
|
if ($_success) { |
1400
|
|
|
$_value71[] = $this->value; |
1401
|
|
|
|
1402
|
|
|
$this->value = $_value71; |
1403
|
|
|
} |
1404
|
|
|
|
1405
|
|
|
if ($_success) { |
1406
|
|
|
$this->value = call_user_func(function () use (&$code) { |
1407
|
|
|
return new CodeBlock($code); |
1408
|
|
|
}); |
1409
|
|
|
} |
1410
|
|
|
|
1411
|
|
|
$this->cache['CODE'][$_position] = array( |
1412
|
|
|
'success' => $_success, |
1413
|
|
|
'position' => $this->position, |
1414
|
|
|
'value' => $this->value |
1415
|
|
|
); |
1416
|
|
|
|
1417
|
|
|
if (!$_success) { |
1418
|
|
|
$this->report($_position, 'CODE'); |
1419
|
|
|
} |
1420
|
|
|
|
1421
|
|
|
return $_success; |
1422
|
|
|
} |
1423
|
|
|
|
1424
|
|
|
protected function parseCODE_START() |
1425
|
|
|
{ |
1426
|
|
|
$_position = $this->position; |
1427
|
|
|
|
1428
|
|
|
if (isset($this->cache['CODE_START'][$_position])) { |
1429
|
|
|
$_success = $this->cache['CODE_START'][$_position]['success']; |
1430
|
|
|
$this->position = $this->cache['CODE_START'][$_position]['position']; |
1431
|
|
|
$this->value = $this->cache['CODE_START'][$_position]['value']; |
1432
|
|
|
|
1433
|
|
|
return $_success; |
1434
|
|
|
} |
1435
|
|
|
|
1436
|
|
|
$_value72 = array(); |
1437
|
|
|
|
1438
|
|
|
if (strtolower(substr($this->string, $this->position, strlen('```php'))) === strtolower('```php')) { |
1439
|
|
|
$_success = true; |
1440
|
|
|
$this->value = substr($this->string, $this->position, strlen('```php')); |
1441
|
|
|
$this->position += strlen('```php'); |
1442
|
|
|
} else { |
1443
|
|
|
$_success = false; |
1444
|
|
|
|
1445
|
|
|
$this->report($this->position, '\'```php\''); |
1446
|
|
|
} |
1447
|
|
|
|
1448
|
|
|
if ($_success) { |
1449
|
|
|
$_value72[] = $this->value; |
1450
|
|
|
|
1451
|
|
|
$_success = $this->parseEOL(); |
1452
|
|
|
} |
1453
|
|
|
|
1454
|
|
|
if ($_success) { |
1455
|
|
|
$_value72[] = $this->value; |
1456
|
|
|
|
1457
|
|
|
$this->value = $_value72; |
1458
|
|
|
} |
1459
|
|
|
|
1460
|
|
|
$this->cache['CODE_START'][$_position] = array( |
1461
|
|
|
'success' => $_success, |
1462
|
|
|
'position' => $this->position, |
1463
|
|
|
'value' => $this->value |
1464
|
|
|
); |
1465
|
|
|
|
1466
|
|
|
if (!$_success) { |
1467
|
|
|
$this->report($_position, 'CODE_START'); |
1468
|
|
|
} |
1469
|
|
|
|
1470
|
|
|
return $_success; |
1471
|
|
|
} |
1472
|
|
|
|
1473
|
|
|
protected function parseCODE_END() |
1474
|
|
|
{ |
1475
|
|
|
$_position = $this->position; |
1476
|
|
|
|
1477
|
|
|
if (isset($this->cache['CODE_END'][$_position])) { |
1478
|
|
|
$_success = $this->cache['CODE_END'][$_position]['success']; |
1479
|
|
|
$this->position = $this->cache['CODE_END'][$_position]['position']; |
1480
|
|
|
$this->value = $this->cache['CODE_END'][$_position]['value']; |
1481
|
|
|
|
1482
|
|
|
return $_success; |
1483
|
|
|
} |
1484
|
|
|
|
1485
|
|
|
$_value75 = array(); |
1486
|
|
|
|
1487
|
|
|
if (substr($this->string, $this->position, strlen('```')) === '```') { |
1488
|
|
|
$_success = true; |
1489
|
|
|
$this->value = substr($this->string, $this->position, strlen('```')); |
1490
|
|
|
$this->position += strlen('```'); |
1491
|
|
|
} else { |
1492
|
|
|
$_success = false; |
1493
|
|
|
|
1494
|
|
|
$this->report($this->position, '\'```\''); |
1495
|
|
|
} |
1496
|
|
|
|
1497
|
|
|
if ($_success) { |
1498
|
|
|
$_value75[] = $this->value; |
1499
|
|
|
|
1500
|
|
|
$_position73 = $this->position; |
1501
|
|
|
$_cut74 = $this->cut; |
1502
|
|
|
|
1503
|
|
|
$this->cut = false; |
1504
|
|
|
$_success = $this->parseEOL(); |
1505
|
|
|
|
1506
|
|
|
if (!$_success && !$this->cut) { |
1507
|
|
|
$this->position = $_position73; |
1508
|
|
|
|
1509
|
|
|
$_success = $this->parseEOF(); |
1510
|
|
|
} |
1511
|
|
|
|
1512
|
|
|
$this->cut = $_cut74; |
1513
|
|
|
} |
1514
|
|
|
|
1515
|
|
|
if ($_success) { |
1516
|
|
|
$_value75[] = $this->value; |
1517
|
|
|
|
1518
|
|
|
$this->value = $_value75; |
1519
|
|
|
} |
1520
|
|
|
|
1521
|
|
|
$this->cache['CODE_END'][$_position] = array( |
1522
|
|
|
'success' => $_success, |
1523
|
|
|
'position' => $this->position, |
1524
|
|
|
'value' => $this->value |
1525
|
|
|
); |
1526
|
|
|
|
1527
|
|
|
if (!$_success) { |
1528
|
|
|
$this->report($_position, 'CODE_END'); |
1529
|
|
|
} |
1530
|
|
|
|
1531
|
|
|
return $_success; |
1532
|
|
|
} |
1533
|
|
|
|
1534
|
|
|
protected function parseVOID_LINE_IN_COMMENT() |
1535
|
|
|
{ |
1536
|
|
|
$_position = $this->position; |
1537
|
|
|
|
1538
|
|
|
if (isset($this->cache['VOID_LINE_IN_COMMENT'][$_position])) { |
1539
|
|
|
$_success = $this->cache['VOID_LINE_IN_COMMENT'][$_position]['success']; |
1540
|
|
|
$this->position = $this->cache['VOID_LINE_IN_COMMENT'][$_position]['position']; |
1541
|
|
|
$this->value = $this->cache['VOID_LINE_IN_COMMENT'][$_position]['value']; |
1542
|
|
|
|
1543
|
|
|
return $_success; |
1544
|
|
|
} |
1545
|
|
|
|
1546
|
|
|
$_value78 = array(); |
1547
|
|
|
|
1548
|
|
|
$_position76 = $this->position; |
1549
|
|
|
$_cut77 = $this->cut; |
1550
|
|
|
|
1551
|
|
|
$this->cut = false; |
1552
|
|
|
$_success = $this->parseHTML_COMMENT_END(); |
1553
|
|
|
|
1554
|
|
|
if (!$_success) { |
1555
|
|
|
$_success = true; |
1556
|
|
|
$this->value = null; |
1557
|
|
|
} else { |
1558
|
|
|
$_success = false; |
1559
|
|
|
} |
1560
|
|
|
|
1561
|
|
|
$this->position = $_position76; |
1562
|
|
|
$this->cut = $_cut77; |
1563
|
|
|
|
1564
|
|
|
if ($_success) { |
1565
|
|
|
$_value78[] = $this->value; |
1566
|
|
|
|
1567
|
|
|
$_success = $this->parseVOID_LINE(); |
1568
|
|
|
} |
1569
|
|
|
|
1570
|
|
|
if ($_success) { |
1571
|
|
|
$_value78[] = $this->value; |
1572
|
|
|
|
1573
|
|
|
$this->value = $_value78; |
1574
|
|
|
} |
1575
|
|
|
|
1576
|
|
|
if ($_success) { |
1577
|
|
|
$this->value = call_user_func(function () { |
1578
|
|
|
|
1579
|
|
|
}); |
1580
|
|
|
} |
1581
|
|
|
|
1582
|
|
|
$this->cache['VOID_LINE_IN_COMMENT'][$_position] = array( |
1583
|
|
|
'success' => $_success, |
1584
|
|
|
'position' => $this->position, |
1585
|
|
|
'value' => $this->value |
1586
|
|
|
); |
1587
|
|
|
|
1588
|
|
|
if (!$_success) { |
1589
|
|
|
$this->report($_position, 'VOID_LINE_IN_COMMENT'); |
1590
|
|
|
} |
1591
|
|
|
|
1592
|
|
|
return $_success; |
1593
|
|
|
} |
1594
|
|
|
|
1595
|
|
|
protected function parseVOID_LINE() |
1596
|
|
|
{ |
1597
|
|
|
$_position = $this->position; |
1598
|
|
|
|
1599
|
|
|
if (isset($this->cache['VOID_LINE'][$_position])) { |
1600
|
|
|
$_success = $this->cache['VOID_LINE'][$_position]['success']; |
1601
|
|
|
$this->position = $this->cache['VOID_LINE'][$_position]['position']; |
1602
|
|
|
$this->value = $this->cache['VOID_LINE'][$_position]['value']; |
1603
|
|
|
|
1604
|
|
|
return $_success; |
1605
|
|
|
} |
1606
|
|
|
|
1607
|
|
|
$_value85 = array(); |
1608
|
|
|
|
1609
|
|
|
$_value83 = array(); |
1610
|
|
|
$_cut84 = $this->cut; |
1611
|
|
|
|
1612
|
|
View Code Duplication |
while (true) { |
|
|
|
|
1613
|
|
|
$_position82 = $this->position; |
1614
|
|
|
|
1615
|
|
|
$this->cut = false; |
1616
|
|
|
$_value81 = array(); |
1617
|
|
|
|
1618
|
|
|
$_position79 = $this->position; |
1619
|
|
|
$_cut80 = $this->cut; |
1620
|
|
|
|
1621
|
|
|
$this->cut = false; |
1622
|
|
|
$_success = $this->parseEOL(); |
1623
|
|
|
|
1624
|
|
|
if (!$_success) { |
1625
|
|
|
$_success = true; |
1626
|
|
|
$this->value = null; |
1627
|
|
|
} else { |
1628
|
|
|
$_success = false; |
1629
|
|
|
} |
1630
|
|
|
|
1631
|
|
|
$this->position = $_position79; |
1632
|
|
|
$this->cut = $_cut80; |
1633
|
|
|
|
1634
|
|
|
if ($_success) { |
1635
|
|
|
$_value81[] = $this->value; |
1636
|
|
|
|
1637
|
|
|
if ($this->position < strlen($this->string)) { |
1638
|
|
|
$_success = true; |
1639
|
|
|
$this->value = substr($this->string, $this->position, 1); |
1640
|
|
|
$this->position += 1; |
1641
|
|
|
} else { |
1642
|
|
|
$_success = false; |
1643
|
|
|
} |
1644
|
|
|
} |
1645
|
|
|
|
1646
|
|
|
if ($_success) { |
1647
|
|
|
$_value81[] = $this->value; |
1648
|
|
|
|
1649
|
|
|
$this->value = $_value81; |
1650
|
|
|
} |
1651
|
|
|
|
1652
|
|
|
if (!$_success) { |
1653
|
|
|
break; |
1654
|
|
|
} |
1655
|
|
|
|
1656
|
|
|
$_value83[] = $this->value; |
1657
|
|
|
} |
1658
|
|
|
|
1659
|
|
|
if (!$this->cut) { |
1660
|
|
|
$_success = true; |
1661
|
|
|
$this->position = $_position82; |
|
|
|
|
1662
|
|
|
$this->value = $_value83; |
1663
|
|
|
} |
1664
|
|
|
|
1665
|
|
|
$this->cut = $_cut84; |
1666
|
|
|
|
1667
|
|
|
if ($_success) { |
|
|
|
|
1668
|
|
|
$_value85[] = $this->value; |
1669
|
|
|
|
1670
|
|
|
$_success = $this->parseEOL(); |
1671
|
|
|
} |
1672
|
|
|
|
1673
|
|
|
if ($_success) { |
1674
|
|
|
$_value85[] = $this->value; |
1675
|
|
|
|
1676
|
|
|
$this->value = $_value85; |
1677
|
|
|
} |
1678
|
|
|
|
1679
|
|
|
if ($_success) { |
1680
|
|
|
$this->value = call_user_func(function () { |
1681
|
|
|
|
1682
|
|
|
}); |
1683
|
|
|
} |
1684
|
|
|
|
1685
|
|
|
$this->cache['VOID_LINE'][$_position] = array( |
1686
|
|
|
'success' => $_success, |
1687
|
|
|
'position' => $this->position, |
1688
|
|
|
'value' => $this->value |
1689
|
|
|
); |
1690
|
|
|
|
1691
|
|
|
if (!$_success) { |
1692
|
|
|
$this->report($_position, 'VOID_LINE'); |
1693
|
|
|
} |
1694
|
|
|
|
1695
|
|
|
return $_success; |
1696
|
|
|
} |
1697
|
|
|
|
1698
|
|
|
protected function parseEMPTY_LINE() |
1699
|
|
|
{ |
1700
|
|
|
$_position = $this->position; |
1701
|
|
|
|
1702
|
|
|
if (isset($this->cache['EMPTY_LINE'][$_position])) { |
1703
|
|
|
$_success = $this->cache['EMPTY_LINE'][$_position]['success']; |
1704
|
|
|
$this->position = $this->cache['EMPTY_LINE'][$_position]['position']; |
1705
|
|
|
$this->value = $this->cache['EMPTY_LINE'][$_position]['value']; |
1706
|
|
|
|
1707
|
|
|
return $_success; |
1708
|
|
|
} |
1709
|
|
|
|
1710
|
|
|
$_value86 = array(); |
1711
|
|
|
|
1712
|
|
|
$_success = $this->parse_(); |
1713
|
|
|
|
1714
|
|
|
if ($_success) { |
1715
|
|
|
$_value86[] = $this->value; |
1716
|
|
|
|
1717
|
|
|
$_success = $this->parseEOL(); |
1718
|
|
|
} |
1719
|
|
|
|
1720
|
|
|
if ($_success) { |
1721
|
|
|
$_value86[] = $this->value; |
1722
|
|
|
|
1723
|
|
|
$this->value = $_value86; |
1724
|
|
|
} |
1725
|
|
|
|
1726
|
|
|
if ($_success) { |
1727
|
|
|
$this->value = call_user_func(function () { |
1728
|
|
|
|
1729
|
|
|
}); |
1730
|
|
|
} |
1731
|
|
|
|
1732
|
|
|
$this->cache['EMPTY_LINE'][$_position] = array( |
1733
|
|
|
'success' => $_success, |
1734
|
|
|
'position' => $this->position, |
1735
|
|
|
'value' => $this->value |
1736
|
|
|
); |
1737
|
|
|
|
1738
|
|
|
if (!$_success) { |
1739
|
|
|
$this->report($_position, 'EMPTY_LINE'); |
1740
|
|
|
} |
1741
|
|
|
|
1742
|
|
|
return $_success; |
1743
|
|
|
} |
1744
|
|
|
|
1745
|
|
|
protected function parseHTML_COMMENT_START() |
1746
|
|
|
{ |
1747
|
|
|
$_position = $this->position; |
1748
|
|
|
|
1749
|
|
|
if (isset($this->cache['HTML_COMMENT_START'][$_position])) { |
1750
|
|
|
$_success = $this->cache['HTML_COMMENT_START'][$_position]['success']; |
1751
|
|
|
$this->position = $this->cache['HTML_COMMENT_START'][$_position]['position']; |
1752
|
|
|
$this->value = $this->cache['HTML_COMMENT_START'][$_position]['value']; |
1753
|
|
|
|
1754
|
|
|
return $_success; |
1755
|
|
|
} |
1756
|
|
|
|
1757
|
|
|
$_value91 = array(); |
1758
|
|
|
|
1759
|
|
|
$_success = $this->parse_(); |
1760
|
|
|
|
1761
|
|
View Code Duplication |
if ($_success) { |
|
|
|
|
1762
|
|
|
$_value91[] = $this->value; |
1763
|
|
|
|
1764
|
|
|
if (substr($this->string, $this->position, strlen('<!--')) === '<!--') { |
1765
|
|
|
$_success = true; |
1766
|
|
|
$this->value = substr($this->string, $this->position, strlen('<!--')); |
1767
|
|
|
$this->position += strlen('<!--'); |
1768
|
|
|
} else { |
1769
|
|
|
$_success = false; |
1770
|
|
|
|
1771
|
|
|
$this->report($this->position, '\'<!--\''); |
1772
|
|
|
} |
1773
|
|
|
} |
1774
|
|
|
|
1775
|
|
View Code Duplication |
if ($_success) { |
|
|
|
|
1776
|
|
|
$_value91[] = $this->value; |
1777
|
|
|
|
1778
|
|
|
$_position87 = $this->position; |
1779
|
|
|
$_cut88 = $this->cut; |
1780
|
|
|
|
1781
|
|
|
$this->cut = false; |
1782
|
|
|
if (substr($this->string, $this->position, strlen('-')) === '-') { |
1783
|
|
|
$_success = true; |
1784
|
|
|
$this->value = substr($this->string, $this->position, strlen('-')); |
1785
|
|
|
$this->position += strlen('-'); |
1786
|
|
|
} else { |
1787
|
|
|
$_success = false; |
1788
|
|
|
|
1789
|
|
|
$this->report($this->position, '\'-\''); |
1790
|
|
|
} |
1791
|
|
|
|
1792
|
|
|
if (!$_success && !$this->cut) { |
1793
|
|
|
$_success = true; |
1794
|
|
|
$this->position = $_position87; |
1795
|
|
|
$this->value = null; |
1796
|
|
|
} |
1797
|
|
|
|
1798
|
|
|
$this->cut = $_cut88; |
1799
|
|
|
} |
1800
|
|
|
|
1801
|
|
View Code Duplication |
if ($_success) { |
|
|
|
|
1802
|
|
|
$_value91[] = $this->value; |
1803
|
|
|
|
1804
|
|
|
$_position89 = $this->position; |
1805
|
|
|
$_cut90 = $this->cut; |
1806
|
|
|
|
1807
|
|
|
$this->cut = false; |
1808
|
|
|
$_success = $this->parseEOL(); |
1809
|
|
|
|
1810
|
|
|
if (!$_success && !$this->cut) { |
1811
|
|
|
$_success = true; |
1812
|
|
|
$this->position = $_position89; |
1813
|
|
|
$this->value = null; |
1814
|
|
|
} |
1815
|
|
|
|
1816
|
|
|
$this->cut = $_cut90; |
1817
|
|
|
} |
1818
|
|
|
|
1819
|
|
|
if ($_success) { |
1820
|
|
|
$_value91[] = $this->value; |
1821
|
|
|
|
1822
|
|
|
$this->value = $_value91; |
1823
|
|
|
} |
1824
|
|
|
|
1825
|
|
|
$this->cache['HTML_COMMENT_START'][$_position] = array( |
1826
|
|
|
'success' => $_success, |
1827
|
|
|
'position' => $this->position, |
1828
|
|
|
'value' => $this->value |
1829
|
|
|
); |
1830
|
|
|
|
1831
|
|
|
if (!$_success) { |
1832
|
|
|
$this->report($_position, 'HTML_COMMENT_START'); |
1833
|
|
|
} |
1834
|
|
|
|
1835
|
|
|
return $_success; |
1836
|
|
|
} |
1837
|
|
|
|
1838
|
|
|
protected function parseHTML_COMMENT_END() |
1839
|
|
|
{ |
1840
|
|
|
$_position = $this->position; |
1841
|
|
|
|
1842
|
|
|
if (isset($this->cache['HTML_COMMENT_END'][$_position])) { |
1843
|
|
|
$_success = $this->cache['HTML_COMMENT_END'][$_position]['success']; |
1844
|
|
|
$this->position = $this->cache['HTML_COMMENT_END'][$_position]['position']; |
1845
|
|
|
$this->value = $this->cache['HTML_COMMENT_END'][$_position]['value']; |
1846
|
|
|
|
1847
|
|
|
return $_success; |
1848
|
|
|
} |
1849
|
|
|
|
1850
|
|
|
$_value94 = array(); |
1851
|
|
|
|
1852
|
|
|
$_success = $this->parse_(); |
1853
|
|
|
|
1854
|
|
View Code Duplication |
if ($_success) { |
|
|
|
|
1855
|
|
|
$_value94[] = $this->value; |
1856
|
|
|
|
1857
|
|
|
if (substr($this->string, $this->position, strlen('-->')) === '-->') { |
1858
|
|
|
$_success = true; |
1859
|
|
|
$this->value = substr($this->string, $this->position, strlen('-->')); |
1860
|
|
|
$this->position += strlen('-->'); |
1861
|
|
|
} else { |
1862
|
|
|
$_success = false; |
1863
|
|
|
|
1864
|
|
|
$this->report($this->position, '\'-->\''); |
1865
|
|
|
} |
1866
|
|
|
} |
1867
|
|
|
|
1868
|
|
View Code Duplication |
if ($_success) { |
|
|
|
|
1869
|
|
|
$_value94[] = $this->value; |
1870
|
|
|
|
1871
|
|
|
$_position92 = $this->position; |
1872
|
|
|
$_cut93 = $this->cut; |
1873
|
|
|
|
1874
|
|
|
$this->cut = false; |
1875
|
|
|
$_success = $this->parseEOL(); |
1876
|
|
|
|
1877
|
|
|
if (!$_success && !$this->cut) { |
1878
|
|
|
$_success = true; |
1879
|
|
|
$this->position = $_position92; |
1880
|
|
|
$this->value = null; |
1881
|
|
|
} |
1882
|
|
|
|
1883
|
|
|
$this->cut = $_cut93; |
1884
|
|
|
} |
1885
|
|
|
|
1886
|
|
|
if ($_success) { |
1887
|
|
|
$_value94[] = $this->value; |
1888
|
|
|
|
1889
|
|
|
$this->value = $_value94; |
1890
|
|
|
} |
1891
|
|
|
|
1892
|
|
|
$this->cache['HTML_COMMENT_END'][$_position] = array( |
1893
|
|
|
'success' => $_success, |
1894
|
|
|
'position' => $this->position, |
1895
|
|
|
'value' => $this->value |
1896
|
|
|
); |
1897
|
|
|
|
1898
|
|
|
if (!$_success) { |
1899
|
|
|
$this->report($_position, 'HTML_COMMENT_END'); |
1900
|
|
|
} |
1901
|
|
|
|
1902
|
|
|
return $_success; |
1903
|
|
|
} |
1904
|
|
|
|
1905
|
|
|
protected function parseEOL() |
1906
|
|
|
{ |
1907
|
|
|
$_position = $this->position; |
1908
|
|
|
|
1909
|
|
|
if (isset($this->cache['EOL'][$_position])) { |
1910
|
|
|
$_success = $this->cache['EOL'][$_position]['success']; |
1911
|
|
|
$this->position = $this->cache['EOL'][$_position]['position']; |
1912
|
|
|
$this->value = $this->cache['EOL'][$_position]['value']; |
1913
|
|
|
|
1914
|
|
|
return $_success; |
1915
|
|
|
} |
1916
|
|
|
|
1917
|
|
|
$_value97 = array(); |
1918
|
|
|
|
1919
|
|
|
$_success = $this->parse_(); |
1920
|
|
|
|
1921
|
|
View Code Duplication |
if ($_success) { |
|
|
|
|
1922
|
|
|
$_value97[] = $this->value; |
1923
|
|
|
|
1924
|
|
|
$_position95 = $this->position; |
1925
|
|
|
$_cut96 = $this->cut; |
1926
|
|
|
|
1927
|
|
|
$this->cut = false; |
1928
|
|
|
if (substr($this->string, $this->position, strlen("\r")) === "\r") { |
1929
|
|
|
$_success = true; |
1930
|
|
|
$this->value = substr($this->string, $this->position, strlen("\r")); |
1931
|
|
|
$this->position += strlen("\r"); |
1932
|
|
|
} else { |
1933
|
|
|
$_success = false; |
1934
|
|
|
|
1935
|
|
|
$this->report($this->position, '"\\r"'); |
1936
|
|
|
} |
1937
|
|
|
|
1938
|
|
|
if (!$_success && !$this->cut) { |
1939
|
|
|
$_success = true; |
1940
|
|
|
$this->position = $_position95; |
1941
|
|
|
$this->value = null; |
1942
|
|
|
} |
1943
|
|
|
|
1944
|
|
|
$this->cut = $_cut96; |
1945
|
|
|
} |
1946
|
|
|
|
1947
|
|
View Code Duplication |
if ($_success) { |
|
|
|
|
1948
|
|
|
$_value97[] = $this->value; |
1949
|
|
|
|
1950
|
|
|
if (substr($this->string, $this->position, strlen("\n")) === "\n") { |
1951
|
|
|
$_success = true; |
1952
|
|
|
$this->value = substr($this->string, $this->position, strlen("\n")); |
1953
|
|
|
$this->position += strlen("\n"); |
1954
|
|
|
} else { |
1955
|
|
|
$_success = false; |
1956
|
|
|
|
1957
|
|
|
$this->report($this->position, '"\\n"'); |
1958
|
|
|
} |
1959
|
|
|
} |
1960
|
|
|
|
1961
|
|
|
if ($_success) { |
1962
|
|
|
$_value97[] = $this->value; |
1963
|
|
|
|
1964
|
|
|
$this->value = $_value97; |
1965
|
|
|
} |
1966
|
|
|
|
1967
|
|
|
$this->cache['EOL'][$_position] = array( |
1968
|
|
|
'success' => $_success, |
1969
|
|
|
'position' => $this->position, |
1970
|
|
|
'value' => $this->value |
1971
|
|
|
); |
1972
|
|
|
|
1973
|
|
|
if (!$_success) { |
1974
|
|
|
$this->report($_position, "END_OF_LINE"); |
1975
|
|
|
} |
1976
|
|
|
|
1977
|
|
|
return $_success; |
1978
|
|
|
} |
1979
|
|
|
|
1980
|
|
|
protected function parseEOF() |
1981
|
|
|
{ |
1982
|
|
|
$_position = $this->position; |
1983
|
|
|
|
1984
|
|
|
if (isset($this->cache['EOF'][$_position])) { |
1985
|
|
|
$_success = $this->cache['EOF'][$_position]['success']; |
1986
|
|
|
$this->position = $this->cache['EOF'][$_position]['position']; |
1987
|
|
|
$this->value = $this->cache['EOF'][$_position]['value']; |
1988
|
|
|
|
1989
|
|
|
return $_success; |
1990
|
|
|
} |
1991
|
|
|
|
1992
|
|
|
$_position98 = $this->position; |
1993
|
|
|
$_cut99 = $this->cut; |
1994
|
|
|
|
1995
|
|
|
$this->cut = false; |
1996
|
|
|
if ($this->position < strlen($this->string)) { |
1997
|
|
|
$_success = true; |
1998
|
|
|
$this->value = substr($this->string, $this->position, 1); |
1999
|
|
|
$this->position += 1; |
2000
|
|
|
} else { |
2001
|
|
|
$_success = false; |
2002
|
|
|
} |
2003
|
|
|
|
2004
|
|
|
if (!$_success) { |
2005
|
|
|
$_success = true; |
2006
|
|
|
$this->value = null; |
2007
|
|
|
} else { |
2008
|
|
|
$_success = false; |
2009
|
|
|
} |
2010
|
|
|
|
2011
|
|
|
$this->position = $_position98; |
2012
|
|
|
$this->cut = $_cut99; |
2013
|
|
|
|
2014
|
|
|
$this->cache['EOF'][$_position] = array( |
2015
|
|
|
'success' => $_success, |
2016
|
|
|
'position' => $this->position, |
2017
|
|
|
'value' => $this->value |
2018
|
|
|
); |
2019
|
|
|
|
2020
|
|
|
if (!$_success) { |
2021
|
|
|
$this->report($_position, "END_OF_FILE"); |
2022
|
|
|
} |
2023
|
|
|
|
2024
|
|
|
return $_success; |
2025
|
|
|
} |
2026
|
|
|
|
2027
|
|
|
protected function parse_() |
2028
|
|
|
{ |
2029
|
|
|
$_position = $this->position; |
2030
|
|
|
|
2031
|
|
|
if (isset($this->cache['_'][$_position])) { |
2032
|
|
|
$_success = $this->cache['_'][$_position]['success']; |
2033
|
|
|
$this->position = $this->cache['_'][$_position]['position']; |
2034
|
|
|
$this->value = $this->cache['_'][$_position]['value']; |
2035
|
|
|
|
2036
|
|
|
return $_success; |
2037
|
|
|
} |
2038
|
|
|
|
2039
|
|
|
$_value103 = array(); |
2040
|
|
|
$_cut104 = $this->cut; |
2041
|
|
|
|
2042
|
|
|
while (true) { |
2043
|
|
|
$_position102 = $this->position; |
2044
|
|
|
|
2045
|
|
|
$this->cut = false; |
2046
|
|
|
$_position100 = $this->position; |
2047
|
|
|
$_cut101 = $this->cut; |
2048
|
|
|
|
2049
|
|
|
$this->cut = false; |
2050
|
|
|
if (substr($this->string, $this->position, strlen(" ")) === " ") { |
2051
|
|
|
$_success = true; |
2052
|
|
|
$this->value = substr($this->string, $this->position, strlen(" ")); |
2053
|
|
|
$this->position += strlen(" "); |
2054
|
|
|
} else { |
2055
|
|
|
$_success = false; |
2056
|
|
|
|
2057
|
|
|
$this->report($this->position, '" "'); |
2058
|
|
|
} |
2059
|
|
|
|
2060
|
|
View Code Duplication |
if (!$_success && !$this->cut) { |
|
|
|
|
2061
|
|
|
$this->position = $_position100; |
2062
|
|
|
|
2063
|
|
|
if (substr($this->string, $this->position, strlen("\t")) === "\t") { |
2064
|
|
|
$_success = true; |
2065
|
|
|
$this->value = substr($this->string, $this->position, strlen("\t")); |
2066
|
|
|
$this->position += strlen("\t"); |
2067
|
|
|
} else { |
2068
|
|
|
$_success = false; |
2069
|
|
|
|
2070
|
|
|
$this->report($this->position, '"\\t"'); |
2071
|
|
|
} |
2072
|
|
|
} |
2073
|
|
|
|
2074
|
|
|
$this->cut = $_cut101; |
2075
|
|
|
|
2076
|
|
|
if (!$_success) { |
2077
|
|
|
break; |
2078
|
|
|
} |
2079
|
|
|
|
2080
|
|
|
$_value103[] = $this->value; |
2081
|
|
|
} |
2082
|
|
|
|
2083
|
|
|
if (!$this->cut) { |
2084
|
|
|
$_success = true; |
2085
|
|
|
$this->position = $_position102; |
|
|
|
|
2086
|
|
|
$this->value = $_value103; |
2087
|
|
|
} |
2088
|
|
|
|
2089
|
|
|
$this->cut = $_cut104; |
2090
|
|
|
|
2091
|
|
|
$this->cache['_'][$_position] = array( |
2092
|
|
|
'success' => $_success, |
|
|
|
|
2093
|
|
|
'position' => $this->position, |
2094
|
|
|
'value' => $this->value |
2095
|
|
|
); |
2096
|
|
|
|
2097
|
|
|
if (!$_success) { |
2098
|
|
|
$this->report($_position, '_'); |
2099
|
|
|
} |
2100
|
|
|
|
2101
|
|
|
return $_success; |
2102
|
|
|
} |
2103
|
|
|
|
2104
|
|
|
private function line() |
2105
|
|
|
{ |
2106
|
|
|
if (!empty($this->errors)) { |
2107
|
|
|
$positions = array_keys($this->errors); |
2108
|
|
|
} else { |
2109
|
|
|
$positions = array_keys($this->warnings); |
2110
|
|
|
} |
2111
|
|
|
|
2112
|
|
|
return count(explode("\n", substr($this->string, 0, max($positions)))); |
2113
|
|
|
} |
2114
|
|
|
|
2115
|
|
|
private function rest() |
2116
|
|
|
{ |
2117
|
|
|
return '"' . substr($this->string, $this->position) . '"'; |
2118
|
|
|
} |
2119
|
|
|
|
2120
|
|
|
protected function report($position, $expecting) |
2121
|
|
|
{ |
2122
|
|
|
if ($this->cut) { |
2123
|
|
|
$this->errors[$position][] = $expecting; |
2124
|
|
|
} else { |
2125
|
|
|
$this->warnings[$position][] = $expecting; |
2126
|
|
|
} |
2127
|
|
|
} |
2128
|
|
|
|
2129
|
|
|
private function expecting() |
2130
|
|
|
{ |
2131
|
|
|
if (!empty($this->errors)) { |
2132
|
|
|
ksort($this->errors); |
2133
|
|
|
|
2134
|
|
|
return end($this->errors)[0]; |
2135
|
|
|
} |
2136
|
|
|
|
2137
|
|
|
ksort($this->warnings); |
2138
|
|
|
|
2139
|
|
|
return implode(', ', end($this->warnings)); |
2140
|
|
|
} |
2141
|
|
|
|
2142
|
|
|
public function parse($_string) |
2143
|
|
|
{ |
2144
|
|
|
$this->string = $_string; |
2145
|
|
|
$this->position = 0; |
2146
|
|
|
$this->value = null; |
2147
|
|
|
$this->cache = array(); |
2148
|
|
|
$this->cut = false; |
2149
|
|
|
$this->errors = array(); |
2150
|
|
|
$this->warnings = array(); |
2151
|
|
|
|
2152
|
|
|
$_success = $this->parseFILE(); |
2153
|
|
|
|
2154
|
|
|
if ($_success && $this->position < strlen($this->string)) { |
2155
|
|
|
$_success = false; |
2156
|
|
|
|
2157
|
|
|
$this->report($this->position, "end of file"); |
2158
|
|
|
} |
2159
|
|
|
|
2160
|
|
|
if (!$_success) { |
2161
|
|
|
throw new \InvalidArgumentException("Syntax error, expecting {$this->expecting()} on line {$this->line()}"); |
2162
|
|
|
} |
2163
|
|
|
|
2164
|
|
|
return $this->value; |
2165
|
|
|
} |
2166
|
|
|
} |
If you define a variable conditionally, it can happen that it is not defined for all execution paths.
Let’s take a look at an example:
In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.
Available Fixes
Check for existence of the variable explicitly:
Define a default value for the variable:
Add a value for the missing path: