This repository has been archived by the owner on Mar 25, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 4
/
scanner.rs
2660 lines (2611 loc) · 104 KB
/
scanner.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
use crate::api::{
yaml_free, yaml_malloc, yaml_queue_extend, yaml_stack_extend, yaml_string_extend,
yaml_string_join,
};
use crate::externs::{memcpy, memmove, memset, strcmp, strlen};
use crate::reader::yaml_parser_update_buffer;
use crate::success::{Success, FAIL, OK};
use crate::yaml::{ptrdiff_t, size_t, yaml_char_t, yaml_string_t, NULL_STRING};
use crate::{
libc, yaml_mark_t, yaml_parser_t, yaml_simple_key_t, yaml_token_t, yaml_token_type_t,
PointerExt, YAML_ALIAS_TOKEN, YAML_ANCHOR_TOKEN, YAML_BLOCK_END_TOKEN, YAML_BLOCK_ENTRY_TOKEN,
YAML_BLOCK_MAPPING_START_TOKEN, YAML_BLOCK_SEQUENCE_START_TOKEN, YAML_DOCUMENT_END_TOKEN,
YAML_DOCUMENT_START_TOKEN, YAML_DOUBLE_QUOTED_SCALAR_STYLE, YAML_FLOW_ENTRY_TOKEN,
YAML_FLOW_MAPPING_END_TOKEN, YAML_FLOW_MAPPING_START_TOKEN, YAML_FLOW_SEQUENCE_END_TOKEN,
YAML_FLOW_SEQUENCE_START_TOKEN, YAML_FOLDED_SCALAR_STYLE, YAML_KEY_TOKEN,
YAML_LITERAL_SCALAR_STYLE, YAML_MEMORY_ERROR, YAML_NO_ERROR, YAML_PLAIN_SCALAR_STYLE,
YAML_SCALAR_TOKEN, YAML_SCANNER_ERROR, YAML_SINGLE_QUOTED_SCALAR_STYLE, YAML_STREAM_END_TOKEN,
YAML_STREAM_START_TOKEN, YAML_TAG_DIRECTIVE_TOKEN, YAML_TAG_TOKEN, YAML_VALUE_TOKEN,
YAML_VERSION_DIRECTIVE_TOKEN,
};
use core::mem::{size_of, MaybeUninit};
use core::ptr::{self, addr_of_mut};
unsafe fn CACHE(parser: *mut yaml_parser_t, length: size_t) -> Success {
if (*parser).unread >= length {
OK
} else {
yaml_parser_update_buffer(parser, length)
}
}
unsafe fn SKIP(parser: *mut yaml_parser_t) {
let width = WIDTH!((*parser).buffer);
(*parser).mark.index = (*parser).mark.index.wrapping_add(width as u64);
(*parser).mark.column = (*parser).mark.column.wrapping_add(1);
(*parser).unread = (*parser).unread.wrapping_sub(1);
(*parser).buffer.pointer = (*parser).buffer.pointer.wrapping_offset(width as isize);
}
unsafe fn SKIP_LINE(parser: *mut yaml_parser_t) {
if IS_CRLF!((*parser).buffer) {
(*parser).mark.index = (*parser).mark.index.wrapping_add(2);
(*parser).mark.column = 0;
(*parser).mark.line = (*parser).mark.line.wrapping_add(1);
(*parser).unread = (*parser).unread.wrapping_sub(2);
(*parser).buffer.pointer = (*parser).buffer.pointer.wrapping_offset(2);
} else if IS_BREAK!((*parser).buffer) {
let width = WIDTH!((*parser).buffer);
(*parser).mark.index = (*parser).mark.index.wrapping_add(width as u64);
(*parser).mark.column = 0;
(*parser).mark.line = (*parser).mark.line.wrapping_add(1);
(*parser).unread = (*parser).unread.wrapping_sub(1);
(*parser).buffer.pointer = (*parser).buffer.pointer.wrapping_offset(width as isize);
};
}
unsafe fn READ(parser: *mut yaml_parser_t, string: *mut yaml_string_t) {
STRING_EXTEND!(*string);
let width = WIDTH!((*parser).buffer);
COPY!(*string, (*parser).buffer);
(*parser).mark.index = (*parser).mark.index.wrapping_add(width as u64);
(*parser).mark.column = (*parser).mark.column.wrapping_add(1);
(*parser).unread = (*parser).unread.wrapping_sub(1);
}
unsafe fn READ_LINE(parser: *mut yaml_parser_t, string: *mut yaml_string_t) {
STRING_EXTEND!(*string);
if CHECK_AT!((*parser).buffer, b'\r', 0) && CHECK_AT!((*parser).buffer, b'\n', 1) {
*(*string).pointer = b'\n';
(*string).pointer = (*string).pointer.wrapping_offset(1);
(*parser).buffer.pointer = (*parser).buffer.pointer.wrapping_offset(2);
(*parser).mark.index = (*parser).mark.index.wrapping_add(2);
(*parser).mark.column = 0;
(*parser).mark.line = (*parser).mark.line.wrapping_add(1);
(*parser).unread = (*parser).unread.wrapping_sub(2);
} else if CHECK_AT!((*parser).buffer, b'\r', 0) || CHECK_AT!((*parser).buffer, b'\n', 0) {
*(*string).pointer = b'\n';
(*string).pointer = (*string).pointer.wrapping_offset(1);
(*parser).buffer.pointer = (*parser).buffer.pointer.wrapping_offset(1);
(*parser).mark.index = (*parser).mark.index.wrapping_add(1);
(*parser).mark.column = 0;
(*parser).mark.line = (*parser).mark.line.wrapping_add(1);
(*parser).unread = (*parser).unread.wrapping_sub(1);
} else if CHECK_AT!((*parser).buffer, b'\xC2', 0) && CHECK_AT!((*parser).buffer, b'\x85', 1) {
*(*string).pointer = b'\n';
(*string).pointer = (*string).pointer.wrapping_offset(1);
(*parser).buffer.pointer = (*parser).buffer.pointer.wrapping_offset(2);
(*parser).mark.index = (*parser).mark.index.wrapping_add(2);
(*parser).mark.column = 0;
(*parser).mark.line = (*parser).mark.line.wrapping_add(1);
(*parser).unread = (*parser).unread.wrapping_sub(1);
} else if CHECK_AT!((*parser).buffer, b'\xE2', 0)
&& CHECK_AT!((*parser).buffer, b'\x80', 1)
&& (CHECK_AT!((*parser).buffer, b'\xA8', 2) || CHECK_AT!((*parser).buffer, b'\xA9', 2))
{
*(*string).pointer = *(*parser).buffer.pointer;
(*string).pointer = (*string).pointer.wrapping_offset(1);
(*parser).buffer.pointer = (*parser).buffer.pointer.wrapping_offset(1);
*(*string).pointer = *(*parser).buffer.pointer;
(*string).pointer = (*string).pointer.wrapping_offset(1);
(*parser).buffer.pointer = (*parser).buffer.pointer.wrapping_offset(1);
*(*string).pointer = *(*parser).buffer.pointer;
(*string).pointer = (*string).pointer.wrapping_offset(1);
(*parser).buffer.pointer = (*parser).buffer.pointer.wrapping_offset(1);
(*parser).mark.index = (*parser).mark.index.wrapping_add(3);
(*parser).mark.column = 0;
(*parser).mark.line = (*parser).mark.line.wrapping_add(1);
(*parser).unread = (*parser).unread.wrapping_sub(1);
};
}
macro_rules! READ {
($parser:expr, $string:expr) => {
READ($parser, addr_of_mut!($string))
};
}
macro_rules! READ_LINE {
($parser:expr, $string:expr) => {
READ_LINE($parser, addr_of_mut!($string))
};
}
/// Scan the input stream and produce the next token.
///
/// Call the function subsequently to produce a sequence of tokens corresponding
/// to the input stream. The initial token has the type YAML_STREAM_START_TOKEN
/// while the ending token has the type YAML_STREAM_END_TOKEN.
///
/// An application is responsible for freeing any buffers associated with the
/// produced token object using the yaml_token_delete function.
///
/// An application must not alternate the calls of yaml_parser_scan() with the
/// calls of yaml_parser_parse() or yaml_parser_load(). Doing this will break
/// the parser.
pub unsafe fn yaml_parser_scan(parser: *mut yaml_parser_t, token: *mut yaml_token_t) -> Success {
__assert!(!parser.is_null());
__assert!(!token.is_null());
memset(
token as *mut libc::c_void,
0,
size_of::<yaml_token_t>() as libc::c_ulong,
);
if (*parser).stream_end_produced || (*parser).error != YAML_NO_ERROR {
return OK;
}
if !(*parser).token_available {
if yaml_parser_fetch_more_tokens(parser).fail {
return FAIL;
}
}
*token = DEQUEUE!((*parser).tokens);
(*parser).token_available = false;
let fresh2 = addr_of_mut!((*parser).tokens_parsed);
*fresh2 = (*fresh2).wrapping_add(1);
if (*token).type_ == YAML_STREAM_END_TOKEN {
(*parser).stream_end_produced = true;
}
OK
}
unsafe fn yaml_parser_set_scanner_error(
parser: *mut yaml_parser_t,
context: *const libc::c_char,
context_mark: yaml_mark_t,
problem: *const libc::c_char,
) {
(*parser).error = YAML_SCANNER_ERROR;
let fresh3 = addr_of_mut!((*parser).context);
*fresh3 = context;
(*parser).context_mark = context_mark;
let fresh4 = addr_of_mut!((*parser).problem);
*fresh4 = problem;
(*parser).problem_mark = (*parser).mark;
}
pub(crate) unsafe fn yaml_parser_fetch_more_tokens(parser: *mut yaml_parser_t) -> Success {
let mut need_more_tokens;
loop {
need_more_tokens = false;
if (*parser).tokens.head == (*parser).tokens.tail {
need_more_tokens = true;
} else {
let mut simple_key: *mut yaml_simple_key_t;
if yaml_parser_stale_simple_keys(parser).fail {
return FAIL;
}
simple_key = (*parser).simple_keys.start;
while simple_key != (*parser).simple_keys.top {
if (*simple_key).possible && (*simple_key).token_number == (*parser).tokens_parsed {
need_more_tokens = true;
break;
} else {
simple_key = simple_key.wrapping_offset(1);
}
}
}
if !need_more_tokens {
break;
}
if yaml_parser_fetch_next_token(parser).fail {
return FAIL;
}
}
(*parser).token_available = true;
OK
}
unsafe fn yaml_parser_fetch_next_token(parser: *mut yaml_parser_t) -> Success {
if CACHE(parser, 1_u64).fail {
return FAIL;
}
if !(*parser).stream_start_produced {
yaml_parser_fetch_stream_start(parser);
return OK;
}
if yaml_parser_scan_to_next_token(parser).fail {
return FAIL;
}
if yaml_parser_stale_simple_keys(parser).fail {
return FAIL;
}
yaml_parser_unroll_indent(parser, (*parser).mark.column as ptrdiff_t);
if CACHE(parser, 4_u64).fail {
return FAIL;
}
if IS_Z!((*parser).buffer) {
return yaml_parser_fetch_stream_end(parser);
}
if (*parser).mark.column == 0_u64 && CHECK!((*parser).buffer, b'%') {
return yaml_parser_fetch_directive(parser);
}
if (*parser).mark.column == 0_u64
&& CHECK_AT!((*parser).buffer, b'-', 0)
&& CHECK_AT!((*parser).buffer, b'-', 1)
&& CHECK_AT!((*parser).buffer, b'-', 2)
&& IS_BLANKZ_AT!((*parser).buffer, 3)
{
return yaml_parser_fetch_document_indicator(parser, YAML_DOCUMENT_START_TOKEN);
}
if (*parser).mark.column == 0_u64
&& CHECK_AT!((*parser).buffer, b'.', 0)
&& CHECK_AT!((*parser).buffer, b'.', 1)
&& CHECK_AT!((*parser).buffer, b'.', 2)
&& IS_BLANKZ_AT!((*parser).buffer, 3)
{
return yaml_parser_fetch_document_indicator(parser, YAML_DOCUMENT_END_TOKEN);
}
if CHECK!((*parser).buffer, b'[') {
return yaml_parser_fetch_flow_collection_start(parser, YAML_FLOW_SEQUENCE_START_TOKEN);
}
if CHECK!((*parser).buffer, b'{') {
return yaml_parser_fetch_flow_collection_start(parser, YAML_FLOW_MAPPING_START_TOKEN);
}
if CHECK!((*parser).buffer, b']') {
return yaml_parser_fetch_flow_collection_end(parser, YAML_FLOW_SEQUENCE_END_TOKEN);
}
if CHECK!((*parser).buffer, b'}') {
return yaml_parser_fetch_flow_collection_end(parser, YAML_FLOW_MAPPING_END_TOKEN);
}
if CHECK!((*parser).buffer, b',') {
return yaml_parser_fetch_flow_entry(parser);
}
if CHECK!((*parser).buffer, b'-') && IS_BLANKZ_AT!((*parser).buffer, 1) {
return yaml_parser_fetch_block_entry(parser);
}
if CHECK!((*parser).buffer, b'?')
&& ((*parser).flow_level != 0 || IS_BLANKZ_AT!((*parser).buffer, 1))
{
return yaml_parser_fetch_key(parser);
}
if CHECK!((*parser).buffer, b':')
&& ((*parser).flow_level != 0 || IS_BLANKZ_AT!((*parser).buffer, 1))
{
return yaml_parser_fetch_value(parser);
}
if CHECK!((*parser).buffer, b'*') {
return yaml_parser_fetch_anchor(parser, YAML_ALIAS_TOKEN);
}
if CHECK!((*parser).buffer, b'&') {
return yaml_parser_fetch_anchor(parser, YAML_ANCHOR_TOKEN);
}
if CHECK!((*parser).buffer, b'!') {
return yaml_parser_fetch_tag(parser);
}
if CHECK!((*parser).buffer, b'|') && (*parser).flow_level == 0 {
return yaml_parser_fetch_block_scalar(parser, true);
}
if CHECK!((*parser).buffer, b'>') && (*parser).flow_level == 0 {
return yaml_parser_fetch_block_scalar(parser, false);
}
if CHECK!((*parser).buffer, b'\'') {
return yaml_parser_fetch_flow_scalar(parser, true);
}
if CHECK!((*parser).buffer, b'"') {
return yaml_parser_fetch_flow_scalar(parser, false);
}
if !(IS_BLANKZ!((*parser).buffer)
|| CHECK!((*parser).buffer, b'-')
|| CHECK!((*parser).buffer, b'?')
|| CHECK!((*parser).buffer, b':')
|| CHECK!((*parser).buffer, b',')
|| CHECK!((*parser).buffer, b'[')
|| CHECK!((*parser).buffer, b']')
|| CHECK!((*parser).buffer, b'{')
|| CHECK!((*parser).buffer, b'}')
|| CHECK!((*parser).buffer, b'#')
|| CHECK!((*parser).buffer, b'&')
|| CHECK!((*parser).buffer, b'*')
|| CHECK!((*parser).buffer, b'!')
|| CHECK!((*parser).buffer, b'|')
|| CHECK!((*parser).buffer, b'>')
|| CHECK!((*parser).buffer, b'\'')
|| CHECK!((*parser).buffer, b'"')
|| CHECK!((*parser).buffer, b'%')
|| CHECK!((*parser).buffer, b'@')
|| CHECK!((*parser).buffer, b'`'))
|| CHECK!((*parser).buffer, b'-') && !IS_BLANK_AT!((*parser).buffer, 1)
|| (*parser).flow_level == 0
&& (CHECK!((*parser).buffer, b'?') || CHECK!((*parser).buffer, b':'))
&& !IS_BLANKZ_AT!((*parser).buffer, 1)
{
return yaml_parser_fetch_plain_scalar(parser);
}
yaml_parser_set_scanner_error(
parser,
b"while scanning for the next token\0" as *const u8 as *const libc::c_char,
(*parser).mark,
b"found character that cannot start any token\0" as *const u8 as *const libc::c_char,
);
FAIL
}
unsafe fn yaml_parser_stale_simple_keys(parser: *mut yaml_parser_t) -> Success {
let mut simple_key: *mut yaml_simple_key_t;
simple_key = (*parser).simple_keys.start;
while simple_key != (*parser).simple_keys.top {
if (*simple_key).possible
&& ((*simple_key).mark.line < (*parser).mark.line
|| (*simple_key).mark.index.wrapping_add(1024_u64) < (*parser).mark.index)
{
if (*simple_key).required {
yaml_parser_set_scanner_error(
parser,
b"while scanning a simple key\0" as *const u8 as *const libc::c_char,
(*simple_key).mark,
b"could not find expected ':'\0" as *const u8 as *const libc::c_char,
);
return FAIL;
}
(*simple_key).possible = false;
}
simple_key = simple_key.wrapping_offset(1);
}
OK
}
unsafe fn yaml_parser_save_simple_key(parser: *mut yaml_parser_t) -> Success {
let required = (*parser).flow_level == 0
&& (*parser).indent as libc::c_long == (*parser).mark.column as ptrdiff_t;
if (*parser).simple_key_allowed {
let simple_key = yaml_simple_key_t {
possible: true,
required,
token_number: (*parser)
.tokens_parsed
.wrapping_add((*parser).tokens.tail.c_offset_from((*parser).tokens.head)
as libc::c_long as libc::c_ulong),
mark: (*parser).mark,
};
if yaml_parser_remove_simple_key(parser).fail {
return FAIL;
}
*(*parser).simple_keys.top.wrapping_offset(-1_isize) = simple_key;
}
OK
}
unsafe fn yaml_parser_remove_simple_key(parser: *mut yaml_parser_t) -> Success {
let simple_key: *mut yaml_simple_key_t = (*parser).simple_keys.top.wrapping_offset(-1_isize);
if (*simple_key).possible {
if (*simple_key).required {
yaml_parser_set_scanner_error(
parser,
b"while scanning a simple key\0" as *const u8 as *const libc::c_char,
(*simple_key).mark,
b"could not find expected ':'\0" as *const u8 as *const libc::c_char,
);
return FAIL;
}
}
(*simple_key).possible = false;
OK
}
unsafe fn yaml_parser_increase_flow_level(parser: *mut yaml_parser_t) -> Success {
let empty_simple_key = yaml_simple_key_t {
possible: false,
required: false,
token_number: 0_u64,
mark: yaml_mark_t {
index: 0_u64,
line: 0_u64,
column: 0_u64,
},
};
PUSH!((*parser).simple_keys, empty_simple_key);
if (*parser).flow_level == libc::c_int::MAX {
(*parser).error = YAML_MEMORY_ERROR;
return FAIL;
}
let fresh7 = addr_of_mut!((*parser).flow_level);
*fresh7 += 1;
OK
}
unsafe fn yaml_parser_decrease_flow_level(parser: *mut yaml_parser_t) {
if (*parser).flow_level != 0 {
let fresh8 = addr_of_mut!((*parser).flow_level);
*fresh8 -= 1;
let _ = POP!((*parser).simple_keys);
}
}
unsafe fn yaml_parser_roll_indent(
parser: *mut yaml_parser_t,
column: ptrdiff_t,
number: ptrdiff_t,
type_: yaml_token_type_t,
mark: yaml_mark_t,
) -> Success {
let mut token = MaybeUninit::<yaml_token_t>::uninit();
let token = token.as_mut_ptr();
if (*parser).flow_level != 0 {
return OK;
}
if ((*parser).indent as libc::c_long) < column {
PUSH!((*parser).indents, (*parser).indent);
if column > ptrdiff_t::from(libc::c_int::MAX) {
(*parser).error = YAML_MEMORY_ERROR;
return FAIL;
}
(*parser).indent = column as libc::c_int;
memset(
token as *mut libc::c_void,
0,
size_of::<yaml_token_t>() as libc::c_ulong,
);
(*token).type_ = type_;
(*token).start_mark = mark;
(*token).end_mark = mark;
if number == -1_i64 {
ENQUEUE!((*parser).tokens, *token);
} else {
QUEUE_INSERT!(
(*parser).tokens,
(number as libc::c_ulong).wrapping_sub((*parser).tokens_parsed),
*token
);
}
}
OK
}
unsafe fn yaml_parser_unroll_indent(parser: *mut yaml_parser_t, column: ptrdiff_t) {
let mut token = MaybeUninit::<yaml_token_t>::uninit();
let token = token.as_mut_ptr();
if (*parser).flow_level != 0 {
return;
}
while (*parser).indent as libc::c_long > column {
memset(
token as *mut libc::c_void,
0,
size_of::<yaml_token_t>() as libc::c_ulong,
);
(*token).type_ = YAML_BLOCK_END_TOKEN;
(*token).start_mark = (*parser).mark;
(*token).end_mark = (*parser).mark;
ENQUEUE!((*parser).tokens, *token);
(*parser).indent = POP!((*parser).indents);
}
}
unsafe fn yaml_parser_fetch_stream_start(parser: *mut yaml_parser_t) {
let simple_key = yaml_simple_key_t {
possible: false,
required: false,
token_number: 0_u64,
mark: yaml_mark_t {
index: 0_u64,
line: 0_u64,
column: 0_u64,
},
};
let mut token = MaybeUninit::<yaml_token_t>::uninit();
let token = token.as_mut_ptr();
(*parser).indent = -1;
PUSH!((*parser).simple_keys, simple_key);
(*parser).simple_key_allowed = true;
(*parser).stream_start_produced = true;
memset(
token as *mut libc::c_void,
0,
size_of::<yaml_token_t>() as libc::c_ulong,
);
(*token).type_ = YAML_STREAM_START_TOKEN;
(*token).start_mark = (*parser).mark;
(*token).end_mark = (*parser).mark;
(*token).data.stream_start.encoding = (*parser).encoding;
ENQUEUE!((*parser).tokens, *token);
}
unsafe fn yaml_parser_fetch_stream_end(parser: *mut yaml_parser_t) -> Success {
let mut token = MaybeUninit::<yaml_token_t>::uninit();
let token = token.as_mut_ptr();
if (*parser).mark.column != 0_u64 {
(*parser).mark.column = 0_u64;
let fresh22 = addr_of_mut!((*parser).mark.line);
*fresh22 = (*fresh22).wrapping_add(1);
}
yaml_parser_unroll_indent(parser, -1_i64);
if yaml_parser_remove_simple_key(parser).fail {
return FAIL;
}
(*parser).simple_key_allowed = false;
memset(
token as *mut libc::c_void,
0,
size_of::<yaml_token_t>() as libc::c_ulong,
);
(*token).type_ = YAML_STREAM_END_TOKEN;
(*token).start_mark = (*parser).mark;
(*token).end_mark = (*parser).mark;
ENQUEUE!((*parser).tokens, *token);
OK
}
unsafe fn yaml_parser_fetch_directive(parser: *mut yaml_parser_t) -> Success {
let mut token = MaybeUninit::<yaml_token_t>::uninit();
let token = token.as_mut_ptr();
yaml_parser_unroll_indent(parser, -1_i64);
if yaml_parser_remove_simple_key(parser).fail {
return FAIL;
}
(*parser).simple_key_allowed = false;
if yaml_parser_scan_directive(parser, token).fail {
return FAIL;
}
ENQUEUE!((*parser).tokens, *token);
OK
}
unsafe fn yaml_parser_fetch_document_indicator(
parser: *mut yaml_parser_t,
type_: yaml_token_type_t,
) -> Success {
let mut token = MaybeUninit::<yaml_token_t>::uninit();
let token = token.as_mut_ptr();
yaml_parser_unroll_indent(parser, -1_i64);
if yaml_parser_remove_simple_key(parser).fail {
return FAIL;
}
(*parser).simple_key_allowed = false;
let start_mark: yaml_mark_t = (*parser).mark;
SKIP(parser);
SKIP(parser);
SKIP(parser);
let end_mark: yaml_mark_t = (*parser).mark;
memset(
token as *mut libc::c_void,
0,
size_of::<yaml_token_t>() as libc::c_ulong,
);
(*token).type_ = type_;
(*token).start_mark = start_mark;
(*token).end_mark = end_mark;
ENQUEUE!((*parser).tokens, *token);
OK
}
unsafe fn yaml_parser_fetch_flow_collection_start(
parser: *mut yaml_parser_t,
type_: yaml_token_type_t,
) -> Success {
let mut token = MaybeUninit::<yaml_token_t>::uninit();
let token = token.as_mut_ptr();
if yaml_parser_save_simple_key(parser).fail {
return FAIL;
}
if yaml_parser_increase_flow_level(parser).fail {
return FAIL;
}
(*parser).simple_key_allowed = true;
let start_mark: yaml_mark_t = (*parser).mark;
SKIP(parser);
let end_mark: yaml_mark_t = (*parser).mark;
memset(
token as *mut libc::c_void,
0,
size_of::<yaml_token_t>() as libc::c_ulong,
);
(*token).type_ = type_;
(*token).start_mark = start_mark;
(*token).end_mark = end_mark;
ENQUEUE!((*parser).tokens, *token);
OK
}
unsafe fn yaml_parser_fetch_flow_collection_end(
parser: *mut yaml_parser_t,
type_: yaml_token_type_t,
) -> Success {
let mut token = MaybeUninit::<yaml_token_t>::uninit();
let token = token.as_mut_ptr();
if yaml_parser_remove_simple_key(parser).fail {
return FAIL;
}
yaml_parser_decrease_flow_level(parser);
(*parser).simple_key_allowed = false;
let start_mark: yaml_mark_t = (*parser).mark;
SKIP(parser);
let end_mark: yaml_mark_t = (*parser).mark;
memset(
token as *mut libc::c_void,
0,
size_of::<yaml_token_t>() as libc::c_ulong,
);
(*token).type_ = type_;
(*token).start_mark = start_mark;
(*token).end_mark = end_mark;
ENQUEUE!((*parser).tokens, *token);
OK
}
unsafe fn yaml_parser_fetch_flow_entry(parser: *mut yaml_parser_t) -> Success {
let mut token = MaybeUninit::<yaml_token_t>::uninit();
let token = token.as_mut_ptr();
if yaml_parser_remove_simple_key(parser).fail {
return FAIL;
}
(*parser).simple_key_allowed = true;
let start_mark: yaml_mark_t = (*parser).mark;
SKIP(parser);
let end_mark: yaml_mark_t = (*parser).mark;
memset(
token as *mut libc::c_void,
0,
size_of::<yaml_token_t>() as libc::c_ulong,
);
(*token).type_ = YAML_FLOW_ENTRY_TOKEN;
(*token).start_mark = start_mark;
(*token).end_mark = end_mark;
ENQUEUE!((*parser).tokens, *token);
OK
}
unsafe fn yaml_parser_fetch_block_entry(parser: *mut yaml_parser_t) -> Success {
let mut token = MaybeUninit::<yaml_token_t>::uninit();
let token = token.as_mut_ptr();
if (*parser).flow_level == 0 {
if !(*parser).simple_key_allowed {
yaml_parser_set_scanner_error(
parser,
ptr::null::<libc::c_char>(),
(*parser).mark,
b"block sequence entries are not allowed in this context\0" as *const u8
as *const libc::c_char,
);
return FAIL;
}
if yaml_parser_roll_indent(
parser,
(*parser).mark.column as ptrdiff_t,
-1_i64,
YAML_BLOCK_SEQUENCE_START_TOKEN,
(*parser).mark,
)
.fail
{
return FAIL;
}
}
if yaml_parser_remove_simple_key(parser).fail {
return FAIL;
}
(*parser).simple_key_allowed = true;
let start_mark: yaml_mark_t = (*parser).mark;
SKIP(parser);
let end_mark: yaml_mark_t = (*parser).mark;
memset(
token as *mut libc::c_void,
0,
size_of::<yaml_token_t>() as libc::c_ulong,
);
(*token).type_ = YAML_BLOCK_ENTRY_TOKEN;
(*token).start_mark = start_mark;
(*token).end_mark = end_mark;
ENQUEUE!((*parser).tokens, *token);
OK
}
unsafe fn yaml_parser_fetch_key(parser: *mut yaml_parser_t) -> Success {
let mut token = MaybeUninit::<yaml_token_t>::uninit();
let token = token.as_mut_ptr();
if (*parser).flow_level == 0 {
if !(*parser).simple_key_allowed {
yaml_parser_set_scanner_error(
parser,
ptr::null::<libc::c_char>(),
(*parser).mark,
b"mapping keys are not allowed in this context\0" as *const u8
as *const libc::c_char,
);
return FAIL;
}
if yaml_parser_roll_indent(
parser,
(*parser).mark.column as ptrdiff_t,
-1_i64,
YAML_BLOCK_MAPPING_START_TOKEN,
(*parser).mark,
)
.fail
{
return FAIL;
}
}
if yaml_parser_remove_simple_key(parser).fail {
return FAIL;
}
(*parser).simple_key_allowed = (*parser).flow_level == 0;
let start_mark: yaml_mark_t = (*parser).mark;
SKIP(parser);
let end_mark: yaml_mark_t = (*parser).mark;
memset(
token as *mut libc::c_void,
0,
size_of::<yaml_token_t>() as libc::c_ulong,
);
(*token).type_ = YAML_KEY_TOKEN;
(*token).start_mark = start_mark;
(*token).end_mark = end_mark;
ENQUEUE!((*parser).tokens, *token);
OK
}
unsafe fn yaml_parser_fetch_value(parser: *mut yaml_parser_t) -> Success {
let mut token = MaybeUninit::<yaml_token_t>::uninit();
let token = token.as_mut_ptr();
let simple_key: *mut yaml_simple_key_t = (*parser).simple_keys.top.wrapping_offset(-1_isize);
if (*simple_key).possible {
memset(
token as *mut libc::c_void,
0,
size_of::<yaml_token_t>() as libc::c_ulong,
);
(*token).type_ = YAML_KEY_TOKEN;
(*token).start_mark = (*simple_key).mark;
(*token).end_mark = (*simple_key).mark;
QUEUE_INSERT!(
(*parser).tokens,
((*simple_key).token_number).wrapping_sub((*parser).tokens_parsed),
*token
);
if yaml_parser_roll_indent(
parser,
(*simple_key).mark.column as ptrdiff_t,
(*simple_key).token_number as ptrdiff_t,
YAML_BLOCK_MAPPING_START_TOKEN,
(*simple_key).mark,
)
.fail
{
return FAIL;
}
(*simple_key).possible = false;
(*parser).simple_key_allowed = false;
} else {
if (*parser).flow_level == 0 {
if !(*parser).simple_key_allowed {
yaml_parser_set_scanner_error(
parser,
ptr::null::<libc::c_char>(),
(*parser).mark,
b"mapping values are not allowed in this context\0" as *const u8
as *const libc::c_char,
);
return FAIL;
}
if yaml_parser_roll_indent(
parser,
(*parser).mark.column as ptrdiff_t,
-1_i64,
YAML_BLOCK_MAPPING_START_TOKEN,
(*parser).mark,
)
.fail
{
return FAIL;
}
}
(*parser).simple_key_allowed = (*parser).flow_level == 0;
}
let start_mark: yaml_mark_t = (*parser).mark;
SKIP(parser);
let end_mark: yaml_mark_t = (*parser).mark;
memset(
token as *mut libc::c_void,
0,
size_of::<yaml_token_t>() as libc::c_ulong,
);
(*token).type_ = YAML_VALUE_TOKEN;
(*token).start_mark = start_mark;
(*token).end_mark = end_mark;
ENQUEUE!((*parser).tokens, *token);
OK
}
unsafe fn yaml_parser_fetch_anchor(
parser: *mut yaml_parser_t,
type_: yaml_token_type_t,
) -> Success {
let mut token = MaybeUninit::<yaml_token_t>::uninit();
let token = token.as_mut_ptr();
if yaml_parser_save_simple_key(parser).fail {
return FAIL;
}
(*parser).simple_key_allowed = false;
if yaml_parser_scan_anchor(parser, token, type_).fail {
return FAIL;
}
ENQUEUE!((*parser).tokens, *token);
OK
}
unsafe fn yaml_parser_fetch_tag(parser: *mut yaml_parser_t) -> Success {
let mut token = MaybeUninit::<yaml_token_t>::uninit();
let token = token.as_mut_ptr();
if yaml_parser_save_simple_key(parser).fail {
return FAIL;
}
(*parser).simple_key_allowed = false;
if yaml_parser_scan_tag(parser, token).fail {
return FAIL;
}
ENQUEUE!((*parser).tokens, *token);
OK
}
unsafe fn yaml_parser_fetch_block_scalar(parser: *mut yaml_parser_t, literal: bool) -> Success {
let mut token = MaybeUninit::<yaml_token_t>::uninit();
let token = token.as_mut_ptr();
if yaml_parser_remove_simple_key(parser).fail {
return FAIL;
}
(*parser).simple_key_allowed = true;
if yaml_parser_scan_block_scalar(parser, token, literal).fail {
return FAIL;
}
ENQUEUE!((*parser).tokens, *token);
OK
}
unsafe fn yaml_parser_fetch_flow_scalar(parser: *mut yaml_parser_t, single: bool) -> Success {
let mut token = MaybeUninit::<yaml_token_t>::uninit();
let token = token.as_mut_ptr();
if yaml_parser_save_simple_key(parser).fail {
return FAIL;
}
(*parser).simple_key_allowed = false;
if yaml_parser_scan_flow_scalar(parser, token, single).fail {
return FAIL;
}
ENQUEUE!((*parser).tokens, *token);
OK
}
unsafe fn yaml_parser_fetch_plain_scalar(parser: *mut yaml_parser_t) -> Success {
let mut token = MaybeUninit::<yaml_token_t>::uninit();
let token = token.as_mut_ptr();
if yaml_parser_save_simple_key(parser).fail {
return FAIL;
}
(*parser).simple_key_allowed = false;
if yaml_parser_scan_plain_scalar(parser, token).fail {
return FAIL;
}
ENQUEUE!((*parser).tokens, *token);
OK
}
unsafe fn yaml_parser_scan_to_next_token(parser: *mut yaml_parser_t) -> Success {
loop {
if CACHE(parser, 1_u64).fail {
return FAIL;
}
if (*parser).mark.column == 0_u64 && IS_BOM!((*parser).buffer) {
SKIP(parser);
}
if CACHE(parser, 1_u64).fail {
return FAIL;
}
while CHECK!((*parser).buffer, b' ')
|| ((*parser).flow_level != 0 || !(*parser).simple_key_allowed)
&& CHECK!((*parser).buffer, b'\t')
{
SKIP(parser);
if CACHE(parser, 1_u64).fail {
return FAIL;
}
}
if CHECK!((*parser).buffer, b'#') {
while !IS_BREAKZ!((*parser).buffer) {
SKIP(parser);
if CACHE(parser, 1_u64).fail {
return FAIL;
}
}
}
if !IS_BREAK!((*parser).buffer) {
break;
}
if CACHE(parser, 2_u64).fail {
return FAIL;
}
SKIP_LINE(parser);
if (*parser).flow_level == 0 {
(*parser).simple_key_allowed = true;
}
}
OK
}
unsafe fn yaml_parser_scan_directive(
parser: *mut yaml_parser_t,
token: *mut yaml_token_t,
) -> Success {
let mut current_block: u64;
let end_mark: yaml_mark_t;
let mut name: *mut yaml_char_t = ptr::null_mut::<yaml_char_t>();
let mut major: libc::c_int = 0;
let mut minor: libc::c_int = 0;
let mut handle: *mut yaml_char_t = ptr::null_mut::<yaml_char_t>();
let mut prefix: *mut yaml_char_t = ptr::null_mut::<yaml_char_t>();
let start_mark: yaml_mark_t = (*parser).mark;
SKIP(parser);
if yaml_parser_scan_directive_name(parser, start_mark, addr_of_mut!(name)).ok {
if strcmp(
name as *mut libc::c_char,
b"YAML\0" as *const u8 as *const libc::c_char,
) == 0
{
if yaml_parser_scan_version_directive_value(
parser,
start_mark,
addr_of_mut!(major),
addr_of_mut!(minor),
)
.fail
{
current_block = 11397968426844348457;
} else {
end_mark = (*parser).mark;
memset(
token as *mut libc::c_void,
0,
size_of::<yaml_token_t>() as libc::c_ulong,
);
(*token).type_ = YAML_VERSION_DIRECTIVE_TOKEN;
(*token).start_mark = start_mark;
(*token).end_mark = end_mark;
(*token).data.version_directive.major = major;
(*token).data.version_directive.minor = minor;
current_block = 17407779659766490442;
}
} else if strcmp(
name as *mut libc::c_char,
b"TAG\0" as *const u8 as *const libc::c_char,
) == 0
{
if yaml_parser_scan_tag_directive_value(
parser,
start_mark,
addr_of_mut!(handle),
addr_of_mut!(prefix),
)
.fail
{
current_block = 11397968426844348457;
} else {
end_mark = (*parser).mark;
memset(
token as *mut libc::c_void,
0,
size_of::<yaml_token_t>() as libc::c_ulong,
);
(*token).type_ = YAML_TAG_DIRECTIVE_TOKEN;
(*token).start_mark = start_mark;
(*token).end_mark = end_mark;