Coverage Report

Created: 2025-12-28 06:31

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/rust/registry/src/index.crates.io-1949cf8c6b5b557f/unsafe-libyaml-0.2.11/src/parser.rs
Line
Count
Source
1
use crate::api::{yaml_free, yaml_malloc, yaml_stack_extend, yaml_strdup};
2
use crate::externs::{memcpy, memset, strcmp, strlen};
3
use crate::ops::ForceAdd as _;
4
use crate::scanner::yaml_parser_fetch_more_tokens;
5
use crate::success::{Success, FAIL, OK};
6
use crate::yaml::{size_t, yaml_char_t};
7
use crate::{
8
    libc, yaml_event_t, yaml_mark_t, yaml_parser_t, yaml_tag_directive_t, yaml_token_t,
9
    yaml_version_directive_t, YAML_ALIAS_EVENT, YAML_ALIAS_TOKEN, YAML_ANCHOR_TOKEN,
10
    YAML_BLOCK_END_TOKEN, YAML_BLOCK_ENTRY_TOKEN, YAML_BLOCK_MAPPING_START_TOKEN,
11
    YAML_BLOCK_MAPPING_STYLE, YAML_BLOCK_SEQUENCE_START_TOKEN, YAML_BLOCK_SEQUENCE_STYLE,
12
    YAML_DOCUMENT_END_EVENT, YAML_DOCUMENT_END_TOKEN, YAML_DOCUMENT_START_EVENT,
13
    YAML_DOCUMENT_START_TOKEN, YAML_FLOW_ENTRY_TOKEN, YAML_FLOW_MAPPING_END_TOKEN,
14
    YAML_FLOW_MAPPING_START_TOKEN, YAML_FLOW_MAPPING_STYLE, YAML_FLOW_SEQUENCE_END_TOKEN,
15
    YAML_FLOW_SEQUENCE_START_TOKEN, YAML_FLOW_SEQUENCE_STYLE, YAML_KEY_TOKEN,
16
    YAML_MAPPING_END_EVENT, YAML_MAPPING_START_EVENT, YAML_NO_ERROR, YAML_PARSER_ERROR,
17
    YAML_PARSE_BLOCK_MAPPING_FIRST_KEY_STATE, YAML_PARSE_BLOCK_MAPPING_KEY_STATE,
18
    YAML_PARSE_BLOCK_MAPPING_VALUE_STATE, YAML_PARSE_BLOCK_NODE_OR_INDENTLESS_SEQUENCE_STATE,
19
    YAML_PARSE_BLOCK_NODE_STATE, YAML_PARSE_BLOCK_SEQUENCE_ENTRY_STATE,
20
    YAML_PARSE_BLOCK_SEQUENCE_FIRST_ENTRY_STATE, YAML_PARSE_DOCUMENT_CONTENT_STATE,
21
    YAML_PARSE_DOCUMENT_END_STATE, YAML_PARSE_DOCUMENT_START_STATE, YAML_PARSE_END_STATE,
22
    YAML_PARSE_FLOW_MAPPING_EMPTY_VALUE_STATE, YAML_PARSE_FLOW_MAPPING_FIRST_KEY_STATE,
23
    YAML_PARSE_FLOW_MAPPING_KEY_STATE, YAML_PARSE_FLOW_MAPPING_VALUE_STATE,
24
    YAML_PARSE_FLOW_NODE_STATE, YAML_PARSE_FLOW_SEQUENCE_ENTRY_MAPPING_END_STATE,
25
    YAML_PARSE_FLOW_SEQUENCE_ENTRY_MAPPING_KEY_STATE,
26
    YAML_PARSE_FLOW_SEQUENCE_ENTRY_MAPPING_VALUE_STATE, YAML_PARSE_FLOW_SEQUENCE_ENTRY_STATE,
27
    YAML_PARSE_FLOW_SEQUENCE_FIRST_ENTRY_STATE, YAML_PARSE_IMPLICIT_DOCUMENT_START_STATE,
28
    YAML_PARSE_INDENTLESS_SEQUENCE_ENTRY_STATE, YAML_PARSE_STREAM_START_STATE,
29
    YAML_PLAIN_SCALAR_STYLE, YAML_SCALAR_EVENT, YAML_SCALAR_TOKEN, YAML_SEQUENCE_END_EVENT,
30
    YAML_SEQUENCE_START_EVENT, YAML_STREAM_END_EVENT, YAML_STREAM_END_TOKEN,
31
    YAML_STREAM_START_EVENT, YAML_STREAM_START_TOKEN, YAML_TAG_DIRECTIVE_TOKEN, YAML_TAG_TOKEN,
32
    YAML_VALUE_TOKEN, YAML_VERSION_DIRECTIVE_TOKEN,
33
};
34
use core::mem::size_of;
35
use core::ptr::{self, addr_of_mut};
36
37
0
unsafe fn PEEK_TOKEN(parser: *mut yaml_parser_t) -> *mut yaml_token_t {
38
0
    if (*parser).token_available || yaml_parser_fetch_more_tokens(parser).ok {
39
0
        (*parser).tokens.head
40
    } else {
41
0
        ptr::null_mut::<yaml_token_t>()
42
    }
43
0
}
44
45
0
unsafe fn SKIP_TOKEN(parser: *mut yaml_parser_t) {
46
0
    (*parser).token_available = false;
47
0
    let fresh3 = addr_of_mut!((*parser).tokens_parsed);
48
0
    *fresh3 = (*fresh3).wrapping_add(1);
49
0
    (*parser).stream_end_produced = (*(*parser).tokens.head).type_ == YAML_STREAM_END_TOKEN;
50
0
    let fresh4 = addr_of_mut!((*parser).tokens.head);
51
0
    *fresh4 = (*fresh4).wrapping_offset(1);
52
0
}
53
54
/// Parse the input stream and produce the next parsing event.
55
///
56
/// Call the function subsequently to produce a sequence of events corresponding
57
/// to the input stream. The initial event has the type YAML_STREAM_START_EVENT
58
/// while the ending event has the type YAML_STREAM_END_EVENT.
59
///
60
/// An application is responsible for freeing any buffers associated with the
61
/// produced event object using the yaml_event_delete() function.
62
///
63
/// An application must not alternate the calls of yaml_parser_parse() with the
64
/// calls of yaml_parser_scan() or yaml_parser_load(). Doing this will break the
65
/// parser.
66
0
pub unsafe fn yaml_parser_parse(parser: *mut yaml_parser_t, event: *mut yaml_event_t) -> Success {
67
0
    __assert!(!parser.is_null());
68
0
    __assert!(!event.is_null());
69
0
    memset(
70
0
        event as *mut libc::c_void,
71
        0,
72
0
        size_of::<yaml_event_t>() as libc::c_ulong,
73
    );
74
0
    if (*parser).stream_end_produced
75
0
        || (*parser).error != YAML_NO_ERROR
76
0
        || (*parser).state == YAML_PARSE_END_STATE
77
    {
78
0
        return OK;
79
0
    }
80
0
    yaml_parser_state_machine(parser, event)
81
0
}
82
83
0
unsafe fn yaml_parser_set_parser_error(
84
0
    parser: *mut yaml_parser_t,
85
0
    problem: *const libc::c_char,
86
0
    problem_mark: yaml_mark_t,
87
0
) {
88
0
    (*parser).error = YAML_PARSER_ERROR;
89
0
    let fresh0 = addr_of_mut!((*parser).problem);
90
0
    *fresh0 = problem;
91
0
    (*parser).problem_mark = problem_mark;
92
0
}
93
94
0
unsafe fn yaml_parser_set_parser_error_context(
95
0
    parser: *mut yaml_parser_t,
96
0
    context: *const libc::c_char,
97
0
    context_mark: yaml_mark_t,
98
0
    problem: *const libc::c_char,
99
0
    problem_mark: yaml_mark_t,
100
0
) {
101
0
    (*parser).error = YAML_PARSER_ERROR;
102
0
    let fresh1 = addr_of_mut!((*parser).context);
103
0
    *fresh1 = context;
104
0
    (*parser).context_mark = context_mark;
105
0
    let fresh2 = addr_of_mut!((*parser).problem);
106
0
    *fresh2 = problem;
107
0
    (*parser).problem_mark = problem_mark;
108
0
}
109
110
0
unsafe fn yaml_parser_state_machine(
111
0
    parser: *mut yaml_parser_t,
112
0
    event: *mut yaml_event_t,
113
0
) -> Success {
114
0
    match (*parser).state {
115
0
        YAML_PARSE_STREAM_START_STATE => yaml_parser_parse_stream_start(parser, event),
116
        YAML_PARSE_IMPLICIT_DOCUMENT_START_STATE => {
117
0
            yaml_parser_parse_document_start(parser, event, true)
118
        }
119
0
        YAML_PARSE_DOCUMENT_START_STATE => yaml_parser_parse_document_start(parser, event, false),
120
0
        YAML_PARSE_DOCUMENT_CONTENT_STATE => yaml_parser_parse_document_content(parser, event),
121
0
        YAML_PARSE_DOCUMENT_END_STATE => yaml_parser_parse_document_end(parser, event),
122
0
        YAML_PARSE_BLOCK_NODE_STATE => yaml_parser_parse_node(parser, event, true, false),
123
        YAML_PARSE_BLOCK_NODE_OR_INDENTLESS_SEQUENCE_STATE => {
124
0
            yaml_parser_parse_node(parser, event, true, true)
125
        }
126
0
        YAML_PARSE_FLOW_NODE_STATE => yaml_parser_parse_node(parser, event, false, false),
127
        YAML_PARSE_BLOCK_SEQUENCE_FIRST_ENTRY_STATE => {
128
0
            yaml_parser_parse_block_sequence_entry(parser, event, true)
129
        }
130
        YAML_PARSE_BLOCK_SEQUENCE_ENTRY_STATE => {
131
0
            yaml_parser_parse_block_sequence_entry(parser, event, false)
132
        }
133
        YAML_PARSE_INDENTLESS_SEQUENCE_ENTRY_STATE => {
134
0
            yaml_parser_parse_indentless_sequence_entry(parser, event)
135
        }
136
        YAML_PARSE_BLOCK_MAPPING_FIRST_KEY_STATE => {
137
0
            yaml_parser_parse_block_mapping_key(parser, event, true)
138
        }
139
        YAML_PARSE_BLOCK_MAPPING_KEY_STATE => {
140
0
            yaml_parser_parse_block_mapping_key(parser, event, false)
141
        }
142
        YAML_PARSE_BLOCK_MAPPING_VALUE_STATE => {
143
0
            yaml_parser_parse_block_mapping_value(parser, event)
144
        }
145
        YAML_PARSE_FLOW_SEQUENCE_FIRST_ENTRY_STATE => {
146
0
            yaml_parser_parse_flow_sequence_entry(parser, event, true)
147
        }
148
        YAML_PARSE_FLOW_SEQUENCE_ENTRY_STATE => {
149
0
            yaml_parser_parse_flow_sequence_entry(parser, event, false)
150
        }
151
        YAML_PARSE_FLOW_SEQUENCE_ENTRY_MAPPING_KEY_STATE => {
152
0
            yaml_parser_parse_flow_sequence_entry_mapping_key(parser, event)
153
        }
154
        YAML_PARSE_FLOW_SEQUENCE_ENTRY_MAPPING_VALUE_STATE => {
155
0
            yaml_parser_parse_flow_sequence_entry_mapping_value(parser, event)
156
        }
157
        YAML_PARSE_FLOW_SEQUENCE_ENTRY_MAPPING_END_STATE => {
158
0
            yaml_parser_parse_flow_sequence_entry_mapping_end(parser, event)
159
        }
160
        YAML_PARSE_FLOW_MAPPING_FIRST_KEY_STATE => {
161
0
            yaml_parser_parse_flow_mapping_key(parser, event, true)
162
        }
163
        YAML_PARSE_FLOW_MAPPING_KEY_STATE => {
164
0
            yaml_parser_parse_flow_mapping_key(parser, event, false)
165
        }
166
        YAML_PARSE_FLOW_MAPPING_VALUE_STATE => {
167
0
            yaml_parser_parse_flow_mapping_value(parser, event, false)
168
        }
169
        YAML_PARSE_FLOW_MAPPING_EMPTY_VALUE_STATE => {
170
0
            yaml_parser_parse_flow_mapping_value(parser, event, true)
171
        }
172
0
        _ => FAIL,
173
    }
174
0
}
175
176
0
unsafe fn yaml_parser_parse_stream_start(
177
0
    parser: *mut yaml_parser_t,
178
0
    event: *mut yaml_event_t,
179
0
) -> Success {
180
0
    let token: *mut yaml_token_t = PEEK_TOKEN(parser);
181
0
    if token.is_null() {
182
0
        return FAIL;
183
0
    }
184
0
    if (*token).type_ != YAML_STREAM_START_TOKEN {
185
0
        yaml_parser_set_parser_error(
186
0
            parser,
187
0
            b"did not find expected <stream-start>\0" as *const u8 as *const libc::c_char,
188
0
            (*token).start_mark,
189
        );
190
0
        return FAIL;
191
0
    }
192
0
    (*parser).state = YAML_PARSE_IMPLICIT_DOCUMENT_START_STATE;
193
0
    memset(
194
0
        event as *mut libc::c_void,
195
        0,
196
0
        size_of::<yaml_event_t>() as libc::c_ulong,
197
    );
198
0
    (*event).type_ = YAML_STREAM_START_EVENT;
199
0
    (*event).start_mark = (*token).start_mark;
200
0
    (*event).end_mark = (*token).start_mark;
201
0
    (*event).data.stream_start.encoding = (*token).data.stream_start.encoding;
202
0
    SKIP_TOKEN(parser);
203
0
    OK
204
0
}
205
206
0
unsafe fn yaml_parser_parse_document_start(
207
0
    parser: *mut yaml_parser_t,
208
0
    event: *mut yaml_event_t,
209
0
    implicit: bool,
210
0
) -> Success {
211
    let mut token: *mut yaml_token_t;
212
0
    let mut version_directive: *mut yaml_version_directive_t =
213
0
        ptr::null_mut::<yaml_version_directive_t>();
214
    struct TagDirectives {
215
        start: *mut yaml_tag_directive_t,
216
        end: *mut yaml_tag_directive_t,
217
    }
218
0
    let mut tag_directives = TagDirectives {
219
0
        start: ptr::null_mut::<yaml_tag_directive_t>(),
220
0
        end: ptr::null_mut::<yaml_tag_directive_t>(),
221
0
    };
222
0
    token = PEEK_TOKEN(parser);
223
0
    if token.is_null() {
224
0
        return FAIL;
225
0
    }
226
0
    if !implicit {
227
0
        while (*token).type_ == YAML_DOCUMENT_END_TOKEN {
228
0
            SKIP_TOKEN(parser);
229
0
            token = PEEK_TOKEN(parser);
230
0
            if token.is_null() {
231
0
                return FAIL;
232
0
            }
233
        }
234
0
    }
235
0
    if implicit
236
0
        && (*token).type_ != YAML_VERSION_DIRECTIVE_TOKEN
237
0
        && (*token).type_ != YAML_TAG_DIRECTIVE_TOKEN
238
0
        && (*token).type_ != YAML_DOCUMENT_START_TOKEN
239
0
        && (*token).type_ != YAML_STREAM_END_TOKEN
240
    {
241
0
        if yaml_parser_process_directives(
242
0
            parser,
243
0
            ptr::null_mut::<*mut yaml_version_directive_t>(),
244
0
            ptr::null_mut::<*mut yaml_tag_directive_t>(),
245
0
            ptr::null_mut::<*mut yaml_tag_directive_t>(),
246
0
        )
247
0
        .fail
248
        {
249
0
            return FAIL;
250
0
        }
251
0
        PUSH!((*parser).states, YAML_PARSE_DOCUMENT_END_STATE);
252
0
        (*parser).state = YAML_PARSE_BLOCK_NODE_STATE;
253
0
        memset(
254
0
            event as *mut libc::c_void,
255
            0,
256
0
            size_of::<yaml_event_t>() as libc::c_ulong,
257
        );
258
0
        (*event).type_ = YAML_DOCUMENT_START_EVENT;
259
0
        (*event).start_mark = (*token).start_mark;
260
0
        (*event).end_mark = (*token).start_mark;
261
0
        let fresh9 = addr_of_mut!((*event).data.document_start.version_directive);
262
0
        *fresh9 = ptr::null_mut::<yaml_version_directive_t>();
263
0
        let fresh10 = addr_of_mut!((*event).data.document_start.tag_directives.start);
264
0
        *fresh10 = ptr::null_mut::<yaml_tag_directive_t>();
265
0
        let fresh11 = addr_of_mut!((*event).data.document_start.tag_directives.end);
266
0
        *fresh11 = ptr::null_mut::<yaml_tag_directive_t>();
267
0
        (*event).data.document_start.implicit = true;
268
0
        OK
269
0
    } else if (*token).type_ != YAML_STREAM_END_TOKEN {
270
        let end_mark: yaml_mark_t;
271
0
        let start_mark: yaml_mark_t = (*token).start_mark;
272
0
        if yaml_parser_process_directives(
273
0
            parser,
274
0
            addr_of_mut!(version_directive),
275
0
            addr_of_mut!(tag_directives.start),
276
0
            addr_of_mut!(tag_directives.end),
277
0
        )
278
0
        .fail
279
        {
280
0
            return FAIL;
281
0
        }
282
0
        token = PEEK_TOKEN(parser);
283
0
        if !token.is_null() {
284
0
            if (*token).type_ != YAML_DOCUMENT_START_TOKEN {
285
0
                yaml_parser_set_parser_error(
286
0
                    parser,
287
0
                    b"did not find expected <document start>\0" as *const u8 as *const libc::c_char,
288
0
                    (*token).start_mark,
289
0
                );
290
0
            } else {
291
0
                PUSH!((*parser).states, YAML_PARSE_DOCUMENT_END_STATE);
292
0
                (*parser).state = YAML_PARSE_DOCUMENT_CONTENT_STATE;
293
0
                end_mark = (*token).end_mark;
294
0
                memset(
295
0
                    event as *mut libc::c_void,
296
                    0,
297
0
                    size_of::<yaml_event_t>() as libc::c_ulong,
298
                );
299
0
                (*event).type_ = YAML_DOCUMENT_START_EVENT;
300
0
                (*event).start_mark = start_mark;
301
0
                (*event).end_mark = end_mark;
302
0
                let fresh14 = addr_of_mut!((*event).data.document_start.version_directive);
303
0
                *fresh14 = version_directive;
304
0
                let fresh15 = addr_of_mut!((*event).data.document_start.tag_directives.start);
305
0
                *fresh15 = tag_directives.start;
306
0
                let fresh16 = addr_of_mut!((*event).data.document_start.tag_directives.end);
307
0
                *fresh16 = tag_directives.end;
308
0
                (*event).data.document_start.implicit = false;
309
0
                SKIP_TOKEN(parser);
310
0
                tag_directives.end = ptr::null_mut::<yaml_tag_directive_t>();
311
0
                tag_directives.start = tag_directives.end;
312
0
                return OK;
313
            }
314
0
        }
315
0
        yaml_free(version_directive as *mut libc::c_void);
316
0
        while tag_directives.start != tag_directives.end {
317
0
            yaml_free((*tag_directives.end.wrapping_offset(-1_isize)).handle as *mut libc::c_void);
318
0
            yaml_free((*tag_directives.end.wrapping_offset(-1_isize)).prefix as *mut libc::c_void);
319
0
            tag_directives.end = tag_directives.end.wrapping_offset(-1);
320
0
        }
321
0
        yaml_free(tag_directives.start as *mut libc::c_void);
322
0
        FAIL
323
    } else {
324
0
        (*parser).state = YAML_PARSE_END_STATE;
325
0
        memset(
326
0
            event as *mut libc::c_void,
327
            0,
328
0
            size_of::<yaml_event_t>() as libc::c_ulong,
329
        );
330
0
        (*event).type_ = YAML_STREAM_END_EVENT;
331
0
        (*event).start_mark = (*token).start_mark;
332
0
        (*event).end_mark = (*token).end_mark;
333
0
        SKIP_TOKEN(parser);
334
0
        OK
335
    }
336
0
}
337
338
0
unsafe fn yaml_parser_parse_document_content(
339
0
    parser: *mut yaml_parser_t,
340
0
    event: *mut yaml_event_t,
341
0
) -> Success {
342
0
    let token: *mut yaml_token_t = PEEK_TOKEN(parser);
343
0
    if token.is_null() {
344
0
        return FAIL;
345
0
    }
346
0
    if (*token).type_ == YAML_VERSION_DIRECTIVE_TOKEN
347
0
        || (*token).type_ == YAML_TAG_DIRECTIVE_TOKEN
348
0
        || (*token).type_ == YAML_DOCUMENT_START_TOKEN
349
0
        || (*token).type_ == YAML_DOCUMENT_END_TOKEN
350
0
        || (*token).type_ == YAML_STREAM_END_TOKEN
351
    {
352
0
        (*parser).state = POP!((*parser).states);
353
0
        yaml_parser_process_empty_scalar(event, (*token).start_mark)
354
    } else {
355
0
        yaml_parser_parse_node(parser, event, true, false)
356
    }
357
0
}
358
359
0
unsafe fn yaml_parser_parse_document_end(
360
0
    parser: *mut yaml_parser_t,
361
0
    event: *mut yaml_event_t,
362
0
) -> Success {
363
    let mut end_mark: yaml_mark_t;
364
0
    let mut implicit = true;
365
0
    let token: *mut yaml_token_t = PEEK_TOKEN(parser);
366
0
    if token.is_null() {
367
0
        return FAIL;
368
0
    }
369
0
    end_mark = (*token).start_mark;
370
0
    let start_mark: yaml_mark_t = end_mark;
371
0
    if (*token).type_ == YAML_DOCUMENT_END_TOKEN {
372
0
        end_mark = (*token).end_mark;
373
0
        SKIP_TOKEN(parser);
374
0
        implicit = false;
375
0
    }
376
0
    while !STACK_EMPTY!((*parser).tag_directives) {
377
0
        let tag_directive = POP!((*parser).tag_directives);
378
0
        yaml_free(tag_directive.handle as *mut libc::c_void);
379
0
        yaml_free(tag_directive.prefix as *mut libc::c_void);
380
0
    }
381
0
    (*parser).state = YAML_PARSE_DOCUMENT_START_STATE;
382
0
    memset(
383
0
        event as *mut libc::c_void,
384
        0,
385
0
        size_of::<yaml_event_t>() as libc::c_ulong,
386
    );
387
0
    (*event).type_ = YAML_DOCUMENT_END_EVENT;
388
0
    (*event).start_mark = start_mark;
389
0
    (*event).end_mark = end_mark;
390
0
    (*event).data.document_end.implicit = implicit;
391
0
    OK
392
0
}
393
394
0
unsafe fn yaml_parser_parse_node(
395
0
    parser: *mut yaml_parser_t,
396
0
    event: *mut yaml_event_t,
397
0
    block: bool,
398
0
    indentless_sequence: bool,
399
0
) -> Success {
400
    let mut current_block: u64;
401
    let mut token: *mut yaml_token_t;
402
0
    let mut anchor: *mut yaml_char_t = ptr::null_mut::<yaml_char_t>();
403
0
    let mut tag_handle: *mut yaml_char_t = ptr::null_mut::<yaml_char_t>();
404
0
    let mut tag_suffix: *mut yaml_char_t = ptr::null_mut::<yaml_char_t>();
405
0
    let mut tag: *mut yaml_char_t = ptr::null_mut::<yaml_char_t>();
406
    let mut start_mark: yaml_mark_t;
407
    let mut end_mark: yaml_mark_t;
408
0
    let mut tag_mark = yaml_mark_t {
409
0
        index: 0,
410
0
        line: 0,
411
0
        column: 0,
412
0
    };
413
    let implicit;
414
0
    token = PEEK_TOKEN(parser);
415
0
    if token.is_null() {
416
0
        return FAIL;
417
0
    }
418
0
    if (*token).type_ == YAML_ALIAS_TOKEN {
419
0
        (*parser).state = POP!((*parser).states);
420
0
        memset(
421
0
            event as *mut libc::c_void,
422
            0,
423
0
            size_of::<yaml_event_t>() as libc::c_ulong,
424
        );
425
0
        (*event).type_ = YAML_ALIAS_EVENT;
426
0
        (*event).start_mark = (*token).start_mark;
427
0
        (*event).end_mark = (*token).end_mark;
428
0
        let fresh26 = addr_of_mut!((*event).data.alias.anchor);
429
0
        *fresh26 = (*token).data.alias.value;
430
0
        SKIP_TOKEN(parser);
431
0
        OK
432
    } else {
433
0
        end_mark = (*token).start_mark;
434
0
        start_mark = end_mark;
435
0
        if (*token).type_ == YAML_ANCHOR_TOKEN {
436
0
            anchor = (*token).data.anchor.value;
437
0
            start_mark = (*token).start_mark;
438
0
            end_mark = (*token).end_mark;
439
0
            SKIP_TOKEN(parser);
440
0
            token = PEEK_TOKEN(parser);
441
0
            if token.is_null() {
442
0
                current_block = 17786380918591080555;
443
0
            } else if (*token).type_ == YAML_TAG_TOKEN {
444
0
                tag_handle = (*token).data.tag.handle;
445
0
                tag_suffix = (*token).data.tag.suffix;
446
0
                tag_mark = (*token).start_mark;
447
0
                end_mark = (*token).end_mark;
448
0
                SKIP_TOKEN(parser);
449
0
                token = PEEK_TOKEN(parser);
450
0
                if token.is_null() {
451
0
                    current_block = 17786380918591080555;
452
0
                } else {
453
0
                    current_block = 11743904203796629665;
454
0
                }
455
0
            } else {
456
0
                current_block = 11743904203796629665;
457
0
            }
458
0
        } else if (*token).type_ == YAML_TAG_TOKEN {
459
0
            tag_handle = (*token).data.tag.handle;
460
0
            tag_suffix = (*token).data.tag.suffix;
461
0
            tag_mark = (*token).start_mark;
462
0
            start_mark = tag_mark;
463
0
            end_mark = (*token).end_mark;
464
0
            SKIP_TOKEN(parser);
465
0
            token = PEEK_TOKEN(parser);
466
0
            if token.is_null() {
467
0
                current_block = 17786380918591080555;
468
0
            } else if (*token).type_ == YAML_ANCHOR_TOKEN {
469
0
                anchor = (*token).data.anchor.value;
470
0
                end_mark = (*token).end_mark;
471
0
                SKIP_TOKEN(parser);
472
0
                token = PEEK_TOKEN(parser);
473
0
                if token.is_null() {
474
0
                    current_block = 17786380918591080555;
475
0
                } else {
476
0
                    current_block = 11743904203796629665;
477
0
                }
478
0
            } else {
479
0
                current_block = 11743904203796629665;
480
0
            }
481
0
        } else {
482
0
            current_block = 11743904203796629665;
483
0
        }
484
0
        if current_block == 11743904203796629665 {
485
0
            if !tag_handle.is_null() {
486
0
                if *tag_handle == 0 {
487
0
                    tag = tag_suffix;
488
0
                    yaml_free(tag_handle as *mut libc::c_void);
489
0
                    tag_suffix = ptr::null_mut::<yaml_char_t>();
490
0
                    tag_handle = tag_suffix;
491
0
                    current_block = 9437013279121998969;
492
0
                } else {
493
                    let mut tag_directive: *mut yaml_tag_directive_t;
494
0
                    tag_directive = (*parser).tag_directives.start;
495
                    loop {
496
0
                        if !(tag_directive != (*parser).tag_directives.top) {
497
0
                            current_block = 17728966195399430138;
498
0
                            break;
499
0
                        }
500
0
                        if strcmp(
501
0
                            (*tag_directive).handle as *mut libc::c_char,
502
0
                            tag_handle as *mut libc::c_char,
503
0
                        ) == 0
504
                        {
505
0
                            let prefix_len: size_t =
506
0
                                strlen((*tag_directive).prefix as *mut libc::c_char);
507
0
                            let suffix_len: size_t = strlen(tag_suffix as *mut libc::c_char);
508
0
                            tag = yaml_malloc(prefix_len.force_add(suffix_len).force_add(1_u64))
509
0
                                as *mut yaml_char_t;
510
0
                            memcpy(
511
0
                                tag as *mut libc::c_void,
512
0
                                (*tag_directive).prefix as *const libc::c_void,
513
0
                                prefix_len,
514
                            );
515
0
                            memcpy(
516
0
                                tag.wrapping_offset(prefix_len as isize) as *mut libc::c_void,
517
0
                                tag_suffix as *const libc::c_void,
518
0
                                suffix_len,
519
                            );
520
0
                            *tag.wrapping_offset(prefix_len.force_add(suffix_len) as isize) = b'\0';
521
0
                            yaml_free(tag_handle as *mut libc::c_void);
522
0
                            yaml_free(tag_suffix as *mut libc::c_void);
523
0
                            tag_suffix = ptr::null_mut::<yaml_char_t>();
524
0
                            tag_handle = tag_suffix;
525
0
                            current_block = 17728966195399430138;
526
0
                            break;
527
0
                        } else {
528
0
                            tag_directive = tag_directive.wrapping_offset(1);
529
0
                        }
530
                    }
531
0
                    if current_block != 17786380918591080555 {
532
0
                        if tag.is_null() {
533
0
                            yaml_parser_set_parser_error_context(
534
0
                                parser,
535
0
                                b"while parsing a node\0" as *const u8 as *const libc::c_char,
536
0
                                start_mark,
537
0
                                b"found undefined tag handle\0" as *const u8 as *const libc::c_char,
538
0
                                tag_mark,
539
0
                            );
540
0
                            current_block = 17786380918591080555;
541
0
                        } else {
542
0
                            current_block = 9437013279121998969;
543
0
                        }
544
0
                    }
545
                }
546
0
            } else {
547
0
                current_block = 9437013279121998969;
548
0
            }
549
0
            if current_block != 17786380918591080555 {
550
0
                implicit = tag.is_null() || *tag == 0;
551
0
                if indentless_sequence && (*token).type_ == YAML_BLOCK_ENTRY_TOKEN {
552
0
                    end_mark = (*token).end_mark;
553
0
                    (*parser).state = YAML_PARSE_INDENTLESS_SEQUENCE_ENTRY_STATE;
554
0
                    memset(
555
0
                        event as *mut libc::c_void,
556
                        0,
557
0
                        size_of::<yaml_event_t>() as libc::c_ulong,
558
                    );
559
0
                    (*event).type_ = YAML_SEQUENCE_START_EVENT;
560
0
                    (*event).start_mark = start_mark;
561
0
                    (*event).end_mark = end_mark;
562
0
                    let fresh37 = addr_of_mut!((*event).data.sequence_start.anchor);
563
0
                    *fresh37 = anchor;
564
0
                    let fresh38 = addr_of_mut!((*event).data.sequence_start.tag);
565
0
                    *fresh38 = tag;
566
0
                    (*event).data.sequence_start.implicit = implicit;
567
0
                    (*event).data.sequence_start.style = YAML_BLOCK_SEQUENCE_STYLE;
568
0
                    return OK;
569
0
                } else if (*token).type_ == YAML_SCALAR_TOKEN {
570
0
                    let mut plain_implicit = false;
571
0
                    let mut quoted_implicit = false;
572
0
                    end_mark = (*token).end_mark;
573
0
                    if (*token).data.scalar.style == YAML_PLAIN_SCALAR_STYLE && tag.is_null()
574
0
                        || !tag.is_null()
575
0
                            && strcmp(
576
0
                                tag as *mut libc::c_char,
577
0
                                b"!\0" as *const u8 as *const libc::c_char,
578
0
                            ) == 0
579
0
                    {
580
0
                        plain_implicit = true;
581
0
                    } else if tag.is_null() {
582
0
                        quoted_implicit = true;
583
0
                    }
584
0
                    (*parser).state = POP!((*parser).states);
585
0
                    memset(
586
0
                        event as *mut libc::c_void,
587
                        0,
588
0
                        size_of::<yaml_event_t>() as libc::c_ulong,
589
                    );
590
0
                    (*event).type_ = YAML_SCALAR_EVENT;
591
0
                    (*event).start_mark = start_mark;
592
0
                    (*event).end_mark = end_mark;
593
0
                    let fresh40 = addr_of_mut!((*event).data.scalar.anchor);
594
0
                    *fresh40 = anchor;
595
0
                    let fresh41 = addr_of_mut!((*event).data.scalar.tag);
596
0
                    *fresh41 = tag;
597
0
                    let fresh42 = addr_of_mut!((*event).data.scalar.value);
598
0
                    *fresh42 = (*token).data.scalar.value;
599
0
                    (*event).data.scalar.length = (*token).data.scalar.length;
600
0
                    (*event).data.scalar.plain_implicit = plain_implicit;
601
0
                    (*event).data.scalar.quoted_implicit = quoted_implicit;
602
0
                    (*event).data.scalar.style = (*token).data.scalar.style;
603
0
                    SKIP_TOKEN(parser);
604
0
                    return OK;
605
0
                } else if (*token).type_ == YAML_FLOW_SEQUENCE_START_TOKEN {
606
0
                    end_mark = (*token).end_mark;
607
0
                    (*parser).state = YAML_PARSE_FLOW_SEQUENCE_FIRST_ENTRY_STATE;
608
0
                    memset(
609
0
                        event as *mut libc::c_void,
610
                        0,
611
0
                        size_of::<yaml_event_t>() as libc::c_ulong,
612
                    );
613
0
                    (*event).type_ = YAML_SEQUENCE_START_EVENT;
614
0
                    (*event).start_mark = start_mark;
615
0
                    (*event).end_mark = end_mark;
616
0
                    let fresh45 = addr_of_mut!((*event).data.sequence_start.anchor);
617
0
                    *fresh45 = anchor;
618
0
                    let fresh46 = addr_of_mut!((*event).data.sequence_start.tag);
619
0
                    *fresh46 = tag;
620
0
                    (*event).data.sequence_start.implicit = implicit;
621
0
                    (*event).data.sequence_start.style = YAML_FLOW_SEQUENCE_STYLE;
622
0
                    return OK;
623
0
                } else if (*token).type_ == YAML_FLOW_MAPPING_START_TOKEN {
624
0
                    end_mark = (*token).end_mark;
625
0
                    (*parser).state = YAML_PARSE_FLOW_MAPPING_FIRST_KEY_STATE;
626
0
                    memset(
627
0
                        event as *mut libc::c_void,
628
                        0,
629
0
                        size_of::<yaml_event_t>() as libc::c_ulong,
630
                    );
631
0
                    (*event).type_ = YAML_MAPPING_START_EVENT;
632
0
                    (*event).start_mark = start_mark;
633
0
                    (*event).end_mark = end_mark;
634
0
                    let fresh47 = addr_of_mut!((*event).data.mapping_start.anchor);
635
0
                    *fresh47 = anchor;
636
0
                    let fresh48 = addr_of_mut!((*event).data.mapping_start.tag);
637
0
                    *fresh48 = tag;
638
0
                    (*event).data.mapping_start.implicit = implicit;
639
0
                    (*event).data.mapping_start.style = YAML_FLOW_MAPPING_STYLE;
640
0
                    return OK;
641
0
                } else if block && (*token).type_ == YAML_BLOCK_SEQUENCE_START_TOKEN {
642
0
                    end_mark = (*token).end_mark;
643
0
                    (*parser).state = YAML_PARSE_BLOCK_SEQUENCE_FIRST_ENTRY_STATE;
644
0
                    memset(
645
0
                        event as *mut libc::c_void,
646
                        0,
647
0
                        size_of::<yaml_event_t>() as libc::c_ulong,
648
                    );
649
0
                    (*event).type_ = YAML_SEQUENCE_START_EVENT;
650
0
                    (*event).start_mark = start_mark;
651
0
                    (*event).end_mark = end_mark;
652
0
                    let fresh49 = addr_of_mut!((*event).data.sequence_start.anchor);
653
0
                    *fresh49 = anchor;
654
0
                    let fresh50 = addr_of_mut!((*event).data.sequence_start.tag);
655
0
                    *fresh50 = tag;
656
0
                    (*event).data.sequence_start.implicit = implicit;
657
0
                    (*event).data.sequence_start.style = YAML_BLOCK_SEQUENCE_STYLE;
658
0
                    return OK;
659
0
                } else if block && (*token).type_ == YAML_BLOCK_MAPPING_START_TOKEN {
660
0
                    end_mark = (*token).end_mark;
661
0
                    (*parser).state = YAML_PARSE_BLOCK_MAPPING_FIRST_KEY_STATE;
662
0
                    memset(
663
0
                        event as *mut libc::c_void,
664
                        0,
665
0
                        size_of::<yaml_event_t>() as libc::c_ulong,
666
                    );
667
0
                    (*event).type_ = YAML_MAPPING_START_EVENT;
668
0
                    (*event).start_mark = start_mark;
669
0
                    (*event).end_mark = end_mark;
670
0
                    let fresh51 = addr_of_mut!((*event).data.mapping_start.anchor);
671
0
                    *fresh51 = anchor;
672
0
                    let fresh52 = addr_of_mut!((*event).data.mapping_start.tag);
673
0
                    *fresh52 = tag;
674
0
                    (*event).data.mapping_start.implicit = implicit;
675
0
                    (*event).data.mapping_start.style = YAML_BLOCK_MAPPING_STYLE;
676
0
                    return OK;
677
0
                } else if !anchor.is_null() || !tag.is_null() {
678
0
                    let value: *mut yaml_char_t = yaml_malloc(1_u64) as *mut yaml_char_t;
679
0
                    *value = b'\0';
680
0
                    (*parser).state = POP!((*parser).states);
681
0
                    memset(
682
0
                        event as *mut libc::c_void,
683
                        0,
684
0
                        size_of::<yaml_event_t>() as libc::c_ulong,
685
                    );
686
0
                    (*event).type_ = YAML_SCALAR_EVENT;
687
0
                    (*event).start_mark = start_mark;
688
0
                    (*event).end_mark = end_mark;
689
0
                    let fresh54 = addr_of_mut!((*event).data.scalar.anchor);
690
0
                    *fresh54 = anchor;
691
0
                    let fresh55 = addr_of_mut!((*event).data.scalar.tag);
692
0
                    *fresh55 = tag;
693
0
                    let fresh56 = addr_of_mut!((*event).data.scalar.value);
694
0
                    *fresh56 = value;
695
0
                    (*event).data.scalar.length = 0_u64;
696
0
                    (*event).data.scalar.plain_implicit = implicit;
697
0
                    (*event).data.scalar.quoted_implicit = false;
698
0
                    (*event).data.scalar.style = YAML_PLAIN_SCALAR_STYLE;
699
0
                    return OK;
700
                } else {
701
0
                    yaml_parser_set_parser_error_context(
702
0
                        parser,
703
0
                        if block {
704
0
                            b"while parsing a block node\0" as *const u8 as *const libc::c_char
705
                        } else {
706
0
                            b"while parsing a flow node\0" as *const u8 as *const libc::c_char
707
                        },
708
0
                        start_mark,
709
0
                        b"did not find expected node content\0" as *const u8 as *const libc::c_char,
710
0
                        (*token).start_mark,
711
                    );
712
                }
713
0
            }
714
0
        }
715
0
        yaml_free(anchor as *mut libc::c_void);
716
0
        yaml_free(tag_handle as *mut libc::c_void);
717
0
        yaml_free(tag_suffix as *mut libc::c_void);
718
0
        yaml_free(tag as *mut libc::c_void);
719
0
        FAIL
720
    }
721
0
}
722
723
0
unsafe fn yaml_parser_parse_block_sequence_entry(
724
0
    parser: *mut yaml_parser_t,
725
0
    event: *mut yaml_event_t,
726
0
    first: bool,
727
0
) -> Success {
728
    let mut token: *mut yaml_token_t;
729
0
    if first {
730
0
        token = PEEK_TOKEN(parser);
731
0
        PUSH!((*parser).marks, (*token).start_mark);
732
0
        SKIP_TOKEN(parser);
733
0
    }
734
0
    token = PEEK_TOKEN(parser);
735
0
    if token.is_null() {
736
0
        return FAIL;
737
0
    }
738
0
    if (*token).type_ == YAML_BLOCK_ENTRY_TOKEN {
739
0
        let mark: yaml_mark_t = (*token).end_mark;
740
0
        SKIP_TOKEN(parser);
741
0
        token = PEEK_TOKEN(parser);
742
0
        if token.is_null() {
743
0
            return FAIL;
744
0
        }
745
0
        if (*token).type_ != YAML_BLOCK_ENTRY_TOKEN && (*token).type_ != YAML_BLOCK_END_TOKEN {
746
0
            PUSH!((*parser).states, YAML_PARSE_BLOCK_SEQUENCE_ENTRY_STATE);
747
0
            yaml_parser_parse_node(parser, event, true, false)
748
        } else {
749
0
            (*parser).state = YAML_PARSE_BLOCK_SEQUENCE_ENTRY_STATE;
750
0
            yaml_parser_process_empty_scalar(event, mark)
751
        }
752
0
    } else if (*token).type_ == YAML_BLOCK_END_TOKEN {
753
0
        (*parser).state = POP!((*parser).states);
754
0
        let _ = POP!((*parser).marks);
755
0
        memset(
756
0
            event as *mut libc::c_void,
757
            0,
758
0
            size_of::<yaml_event_t>() as libc::c_ulong,
759
        );
760
0
        (*event).type_ = YAML_SEQUENCE_END_EVENT;
761
0
        (*event).start_mark = (*token).start_mark;
762
0
        (*event).end_mark = (*token).end_mark;
763
0
        SKIP_TOKEN(parser);
764
0
        OK
765
    } else {
766
0
        yaml_parser_set_parser_error_context(
767
0
            parser,
768
0
            b"while parsing a block collection\0" as *const u8 as *const libc::c_char,
769
0
            POP!((*parser).marks),
770
0
            b"did not find expected '-' indicator\0" as *const u8 as *const libc::c_char,
771
0
            (*token).start_mark,
772
        );
773
0
        FAIL
774
    }
775
0
}
776
777
0
unsafe fn yaml_parser_parse_indentless_sequence_entry(
778
0
    parser: *mut yaml_parser_t,
779
0
    event: *mut yaml_event_t,
780
0
) -> Success {
781
    let mut token: *mut yaml_token_t;
782
0
    token = PEEK_TOKEN(parser);
783
0
    if token.is_null() {
784
0
        return FAIL;
785
0
    }
786
0
    if (*token).type_ == YAML_BLOCK_ENTRY_TOKEN {
787
0
        let mark: yaml_mark_t = (*token).end_mark;
788
0
        SKIP_TOKEN(parser);
789
0
        token = PEEK_TOKEN(parser);
790
0
        if token.is_null() {
791
0
            return FAIL;
792
0
        }
793
0
        if (*token).type_ != YAML_BLOCK_ENTRY_TOKEN
794
0
            && (*token).type_ != YAML_KEY_TOKEN
795
0
            && (*token).type_ != YAML_VALUE_TOKEN
796
0
            && (*token).type_ != YAML_BLOCK_END_TOKEN
797
        {
798
0
            PUSH!((*parser).states, YAML_PARSE_INDENTLESS_SEQUENCE_ENTRY_STATE);
799
0
            yaml_parser_parse_node(parser, event, true, false)
800
        } else {
801
0
            (*parser).state = YAML_PARSE_INDENTLESS_SEQUENCE_ENTRY_STATE;
802
0
            yaml_parser_process_empty_scalar(event, mark)
803
        }
804
    } else {
805
0
        (*parser).state = POP!((*parser).states);
806
0
        memset(
807
0
            event as *mut libc::c_void,
808
            0,
809
0
            size_of::<yaml_event_t>() as libc::c_ulong,
810
        );
811
0
        (*event).type_ = YAML_SEQUENCE_END_EVENT;
812
0
        (*event).start_mark = (*token).start_mark;
813
0
        (*event).end_mark = (*token).start_mark;
814
0
        OK
815
    }
816
0
}
817
818
0
unsafe fn yaml_parser_parse_block_mapping_key(
819
0
    parser: *mut yaml_parser_t,
820
0
    event: *mut yaml_event_t,
821
0
    first: bool,
822
0
) -> Success {
823
    let mut token: *mut yaml_token_t;
824
0
    if first {
825
0
        token = PEEK_TOKEN(parser);
826
0
        PUSH!((*parser).marks, (*token).start_mark);
827
0
        SKIP_TOKEN(parser);
828
0
    }
829
0
    token = PEEK_TOKEN(parser);
830
0
    if token.is_null() {
831
0
        return FAIL;
832
0
    }
833
0
    if (*token).type_ == YAML_KEY_TOKEN {
834
0
        let mark: yaml_mark_t = (*token).end_mark;
835
0
        SKIP_TOKEN(parser);
836
0
        token = PEEK_TOKEN(parser);
837
0
        if token.is_null() {
838
0
            return FAIL;
839
0
        }
840
0
        if (*token).type_ != YAML_KEY_TOKEN
841
0
            && (*token).type_ != YAML_VALUE_TOKEN
842
0
            && (*token).type_ != YAML_BLOCK_END_TOKEN
843
        {
844
0
            PUSH!((*parser).states, YAML_PARSE_BLOCK_MAPPING_VALUE_STATE);
845
0
            yaml_parser_parse_node(parser, event, true, true)
846
        } else {
847
0
            (*parser).state = YAML_PARSE_BLOCK_MAPPING_VALUE_STATE;
848
0
            yaml_parser_process_empty_scalar(event, mark)
849
        }
850
0
    } else if (*token).type_ == YAML_BLOCK_END_TOKEN {
851
0
        (*parser).state = POP!((*parser).states);
852
0
        let _ = POP!((*parser).marks);
853
0
        memset(
854
0
            event as *mut libc::c_void,
855
            0,
856
0
            size_of::<yaml_event_t>() as libc::c_ulong,
857
        );
858
0
        (*event).type_ = YAML_MAPPING_END_EVENT;
859
0
        (*event).start_mark = (*token).start_mark;
860
0
        (*event).end_mark = (*token).end_mark;
861
0
        SKIP_TOKEN(parser);
862
0
        OK
863
    } else {
864
0
        yaml_parser_set_parser_error_context(
865
0
            parser,
866
0
            b"while parsing a block mapping\0" as *const u8 as *const libc::c_char,
867
0
            POP!((*parser).marks),
868
0
            b"did not find expected key\0" as *const u8 as *const libc::c_char,
869
0
            (*token).start_mark,
870
        );
871
0
        FAIL
872
    }
873
0
}
874
875
0
unsafe fn yaml_parser_parse_block_mapping_value(
876
0
    parser: *mut yaml_parser_t,
877
0
    event: *mut yaml_event_t,
878
0
) -> Success {
879
    let mut token: *mut yaml_token_t;
880
0
    token = PEEK_TOKEN(parser);
881
0
    if token.is_null() {
882
0
        return FAIL;
883
0
    }
884
0
    if (*token).type_ == YAML_VALUE_TOKEN {
885
0
        let mark: yaml_mark_t = (*token).end_mark;
886
0
        SKIP_TOKEN(parser);
887
0
        token = PEEK_TOKEN(parser);
888
0
        if token.is_null() {
889
0
            return FAIL;
890
0
        }
891
0
        if (*token).type_ != YAML_KEY_TOKEN
892
0
            && (*token).type_ != YAML_VALUE_TOKEN
893
0
            && (*token).type_ != YAML_BLOCK_END_TOKEN
894
        {
895
0
            PUSH!((*parser).states, YAML_PARSE_BLOCK_MAPPING_KEY_STATE);
896
0
            yaml_parser_parse_node(parser, event, true, true)
897
        } else {
898
0
            (*parser).state = YAML_PARSE_BLOCK_MAPPING_KEY_STATE;
899
0
            yaml_parser_process_empty_scalar(event, mark)
900
        }
901
    } else {
902
0
        (*parser).state = YAML_PARSE_BLOCK_MAPPING_KEY_STATE;
903
0
        yaml_parser_process_empty_scalar(event, (*token).start_mark)
904
    }
905
0
}
906
907
0
unsafe fn yaml_parser_parse_flow_sequence_entry(
908
0
    parser: *mut yaml_parser_t,
909
0
    event: *mut yaml_event_t,
910
0
    first: bool,
911
0
) -> Success {
912
    let mut token: *mut yaml_token_t;
913
0
    if first {
914
0
        token = PEEK_TOKEN(parser);
915
0
        PUSH!((*parser).marks, (*token).start_mark);
916
0
        SKIP_TOKEN(parser);
917
0
    }
918
0
    token = PEEK_TOKEN(parser);
919
0
    if token.is_null() {
920
0
        return FAIL;
921
0
    }
922
0
    if (*token).type_ != YAML_FLOW_SEQUENCE_END_TOKEN {
923
0
        if !first {
924
0
            if (*token).type_ == YAML_FLOW_ENTRY_TOKEN {
925
0
                SKIP_TOKEN(parser);
926
0
                token = PEEK_TOKEN(parser);
927
0
                if token.is_null() {
928
0
                    return FAIL;
929
0
                }
930
            } else {
931
0
                yaml_parser_set_parser_error_context(
932
0
                    parser,
933
0
                    b"while parsing a flow sequence\0" as *const u8 as *const libc::c_char,
934
0
                    POP!((*parser).marks),
935
0
                    b"did not find expected ',' or ']'\0" as *const u8 as *const libc::c_char,
936
0
                    (*token).start_mark,
937
                );
938
0
                return FAIL;
939
            }
940
0
        }
941
0
        if (*token).type_ == YAML_KEY_TOKEN {
942
0
            (*parser).state = YAML_PARSE_FLOW_SEQUENCE_ENTRY_MAPPING_KEY_STATE;
943
0
            memset(
944
0
                event as *mut libc::c_void,
945
                0,
946
0
                size_of::<yaml_event_t>() as libc::c_ulong,
947
            );
948
0
            (*event).type_ = YAML_MAPPING_START_EVENT;
949
0
            (*event).start_mark = (*token).start_mark;
950
0
            (*event).end_mark = (*token).end_mark;
951
0
            let fresh99 = addr_of_mut!((*event).data.mapping_start.anchor);
952
0
            *fresh99 = ptr::null_mut::<yaml_char_t>();
953
0
            let fresh100 = addr_of_mut!((*event).data.mapping_start.tag);
954
0
            *fresh100 = ptr::null_mut::<yaml_char_t>();
955
0
            (*event).data.mapping_start.implicit = true;
956
0
            (*event).data.mapping_start.style = YAML_FLOW_MAPPING_STYLE;
957
0
            SKIP_TOKEN(parser);
958
0
            return OK;
959
0
        } else if (*token).type_ != YAML_FLOW_SEQUENCE_END_TOKEN {
960
0
            PUSH!((*parser).states, YAML_PARSE_FLOW_SEQUENCE_ENTRY_STATE);
961
0
            return yaml_parser_parse_node(parser, event, false, false);
962
0
        }
963
0
    }
964
0
    (*parser).state = POP!((*parser).states);
965
0
    let _ = POP!((*parser).marks);
966
0
    memset(
967
0
        event as *mut libc::c_void,
968
        0,
969
0
        size_of::<yaml_event_t>() as libc::c_ulong,
970
    );
971
0
    (*event).type_ = YAML_SEQUENCE_END_EVENT;
972
0
    (*event).start_mark = (*token).start_mark;
973
0
    (*event).end_mark = (*token).end_mark;
974
0
    SKIP_TOKEN(parser);
975
0
    OK
976
0
}
977
978
0
unsafe fn yaml_parser_parse_flow_sequence_entry_mapping_key(
979
0
    parser: *mut yaml_parser_t,
980
0
    event: *mut yaml_event_t,
981
0
) -> Success {
982
0
    let token: *mut yaml_token_t = PEEK_TOKEN(parser);
983
0
    if token.is_null() {
984
0
        return FAIL;
985
0
    }
986
0
    if (*token).type_ != YAML_VALUE_TOKEN
987
0
        && (*token).type_ != YAML_FLOW_ENTRY_TOKEN
988
0
        && (*token).type_ != YAML_FLOW_SEQUENCE_END_TOKEN
989
    {
990
0
        PUSH!(
991
            (*parser).states,
992
0
            YAML_PARSE_FLOW_SEQUENCE_ENTRY_MAPPING_VALUE_STATE
993
        );
994
0
        yaml_parser_parse_node(parser, event, false, false)
995
    } else {
996
0
        let mark: yaml_mark_t = (*token).end_mark;
997
0
        SKIP_TOKEN(parser);
998
0
        (*parser).state = YAML_PARSE_FLOW_SEQUENCE_ENTRY_MAPPING_VALUE_STATE;
999
0
        yaml_parser_process_empty_scalar(event, mark)
1000
    }
1001
0
}
1002
1003
0
unsafe fn yaml_parser_parse_flow_sequence_entry_mapping_value(
1004
0
    parser: *mut yaml_parser_t,
1005
0
    event: *mut yaml_event_t,
1006
0
) -> Success {
1007
    let mut token: *mut yaml_token_t;
1008
0
    token = PEEK_TOKEN(parser);
1009
0
    if token.is_null() {
1010
0
        return FAIL;
1011
0
    }
1012
0
    if (*token).type_ == YAML_VALUE_TOKEN {
1013
0
        SKIP_TOKEN(parser);
1014
0
        token = PEEK_TOKEN(parser);
1015
0
        if token.is_null() {
1016
0
            return FAIL;
1017
0
        }
1018
0
        if (*token).type_ != YAML_FLOW_ENTRY_TOKEN && (*token).type_ != YAML_FLOW_SEQUENCE_END_TOKEN
1019
        {
1020
0
            PUSH!(
1021
                (*parser).states,
1022
0
                YAML_PARSE_FLOW_SEQUENCE_ENTRY_MAPPING_END_STATE
1023
            );
1024
0
            return yaml_parser_parse_node(parser, event, false, false);
1025
0
        }
1026
0
    }
1027
0
    (*parser).state = YAML_PARSE_FLOW_SEQUENCE_ENTRY_MAPPING_END_STATE;
1028
0
    yaml_parser_process_empty_scalar(event, (*token).start_mark)
1029
0
}
1030
1031
0
unsafe fn yaml_parser_parse_flow_sequence_entry_mapping_end(
1032
0
    parser: *mut yaml_parser_t,
1033
0
    event: *mut yaml_event_t,
1034
0
) -> Success {
1035
0
    let token: *mut yaml_token_t = PEEK_TOKEN(parser);
1036
0
    if token.is_null() {
1037
0
        return FAIL;
1038
0
    }
1039
0
    (*parser).state = YAML_PARSE_FLOW_SEQUENCE_ENTRY_STATE;
1040
0
    memset(
1041
0
        event as *mut libc::c_void,
1042
        0,
1043
0
        size_of::<yaml_event_t>() as libc::c_ulong,
1044
    );
1045
0
    (*event).type_ = YAML_MAPPING_END_EVENT;
1046
0
    (*event).start_mark = (*token).start_mark;
1047
0
    (*event).end_mark = (*token).start_mark;
1048
0
    OK
1049
0
}
1050
1051
0
unsafe fn yaml_parser_parse_flow_mapping_key(
1052
0
    parser: *mut yaml_parser_t,
1053
0
    event: *mut yaml_event_t,
1054
0
    first: bool,
1055
0
) -> Success {
1056
    let mut token: *mut yaml_token_t;
1057
0
    if first {
1058
0
        token = PEEK_TOKEN(parser);
1059
0
        PUSH!((*parser).marks, (*token).start_mark);
1060
0
        SKIP_TOKEN(parser);
1061
0
    }
1062
0
    token = PEEK_TOKEN(parser);
1063
0
    if token.is_null() {
1064
0
        return FAIL;
1065
0
    }
1066
0
    if (*token).type_ != YAML_FLOW_MAPPING_END_TOKEN {
1067
0
        if !first {
1068
0
            if (*token).type_ == YAML_FLOW_ENTRY_TOKEN {
1069
0
                SKIP_TOKEN(parser);
1070
0
                token = PEEK_TOKEN(parser);
1071
0
                if token.is_null() {
1072
0
                    return FAIL;
1073
0
                }
1074
            } else {
1075
0
                yaml_parser_set_parser_error_context(
1076
0
                    parser,
1077
0
                    b"while parsing a flow mapping\0" as *const u8 as *const libc::c_char,
1078
0
                    POP!((*parser).marks),
1079
0
                    b"did not find expected ',' or '}'\0" as *const u8 as *const libc::c_char,
1080
0
                    (*token).start_mark,
1081
                );
1082
0
                return FAIL;
1083
            }
1084
0
        }
1085
0
        if (*token).type_ == YAML_KEY_TOKEN {
1086
0
            SKIP_TOKEN(parser);
1087
0
            token = PEEK_TOKEN(parser);
1088
0
            if token.is_null() {
1089
0
                return FAIL;
1090
0
            }
1091
0
            if (*token).type_ != YAML_VALUE_TOKEN
1092
0
                && (*token).type_ != YAML_FLOW_ENTRY_TOKEN
1093
0
                && (*token).type_ != YAML_FLOW_MAPPING_END_TOKEN
1094
            {
1095
0
                PUSH!((*parser).states, YAML_PARSE_FLOW_MAPPING_VALUE_STATE);
1096
0
                return yaml_parser_parse_node(parser, event, false, false);
1097
            } else {
1098
0
                (*parser).state = YAML_PARSE_FLOW_MAPPING_VALUE_STATE;
1099
0
                return yaml_parser_process_empty_scalar(event, (*token).start_mark);
1100
            }
1101
0
        } else if (*token).type_ != YAML_FLOW_MAPPING_END_TOKEN {
1102
0
            PUSH!((*parser).states, YAML_PARSE_FLOW_MAPPING_EMPTY_VALUE_STATE);
1103
0
            return yaml_parser_parse_node(parser, event, false, false);
1104
0
        }
1105
0
    }
1106
0
    (*parser).state = POP!((*parser).states);
1107
0
    let _ = POP!((*parser).marks);
1108
0
    memset(
1109
0
        event as *mut libc::c_void,
1110
        0,
1111
0
        size_of::<yaml_event_t>() as libc::c_ulong,
1112
    );
1113
0
    (*event).type_ = YAML_MAPPING_END_EVENT;
1114
0
    (*event).start_mark = (*token).start_mark;
1115
0
    (*event).end_mark = (*token).end_mark;
1116
0
    SKIP_TOKEN(parser);
1117
0
    OK
1118
0
}
1119
1120
0
unsafe fn yaml_parser_parse_flow_mapping_value(
1121
0
    parser: *mut yaml_parser_t,
1122
0
    event: *mut yaml_event_t,
1123
0
    empty: bool,
1124
0
) -> Success {
1125
    let mut token: *mut yaml_token_t;
1126
0
    token = PEEK_TOKEN(parser);
1127
0
    if token.is_null() {
1128
0
        return FAIL;
1129
0
    }
1130
0
    if empty {
1131
0
        (*parser).state = YAML_PARSE_FLOW_MAPPING_KEY_STATE;
1132
0
        return yaml_parser_process_empty_scalar(event, (*token).start_mark);
1133
0
    }
1134
0
    if (*token).type_ == YAML_VALUE_TOKEN {
1135
0
        SKIP_TOKEN(parser);
1136
0
        token = PEEK_TOKEN(parser);
1137
0
        if token.is_null() {
1138
0
            return FAIL;
1139
0
        }
1140
0
        if (*token).type_ != YAML_FLOW_ENTRY_TOKEN && (*token).type_ != YAML_FLOW_MAPPING_END_TOKEN
1141
        {
1142
0
            PUSH!((*parser).states, YAML_PARSE_FLOW_MAPPING_KEY_STATE);
1143
0
            return yaml_parser_parse_node(parser, event, false, false);
1144
0
        }
1145
0
    }
1146
0
    (*parser).state = YAML_PARSE_FLOW_MAPPING_KEY_STATE;
1147
0
    yaml_parser_process_empty_scalar(event, (*token).start_mark)
1148
0
}
1149
1150
0
unsafe fn yaml_parser_process_empty_scalar(event: *mut yaml_event_t, mark: yaml_mark_t) -> Success {
1151
0
    let value: *mut yaml_char_t = yaml_malloc(1_u64) as *mut yaml_char_t;
1152
0
    *value = b'\0';
1153
0
    memset(
1154
0
        event as *mut libc::c_void,
1155
        0,
1156
0
        size_of::<yaml_event_t>() as libc::c_ulong,
1157
    );
1158
0
    (*event).type_ = YAML_SCALAR_EVENT;
1159
0
    (*event).start_mark = mark;
1160
0
    (*event).end_mark = mark;
1161
0
    let fresh138 = addr_of_mut!((*event).data.scalar.anchor);
1162
0
    *fresh138 = ptr::null_mut::<yaml_char_t>();
1163
0
    let fresh139 = addr_of_mut!((*event).data.scalar.tag);
1164
0
    *fresh139 = ptr::null_mut::<yaml_char_t>();
1165
0
    let fresh140 = addr_of_mut!((*event).data.scalar.value);
1166
0
    *fresh140 = value;
1167
0
    (*event).data.scalar.length = 0_u64;
1168
0
    (*event).data.scalar.plain_implicit = true;
1169
0
    (*event).data.scalar.quoted_implicit = false;
1170
0
    (*event).data.scalar.style = YAML_PLAIN_SCALAR_STYLE;
1171
0
    OK
1172
0
}
1173
1174
0
unsafe fn yaml_parser_process_directives(
1175
0
    parser: *mut yaml_parser_t,
1176
0
    version_directive_ref: *mut *mut yaml_version_directive_t,
1177
0
    tag_directives_start_ref: *mut *mut yaml_tag_directive_t,
1178
0
    tag_directives_end_ref: *mut *mut yaml_tag_directive_t,
1179
0
) -> Success {
1180
    let mut current_block: u64;
1181
0
    let mut default_tag_directives: [yaml_tag_directive_t; 3] = [
1182
0
        yaml_tag_directive_t {
1183
0
            handle: b"!\0" as *const u8 as *const libc::c_char as *mut yaml_char_t,
1184
0
            prefix: b"!\0" as *const u8 as *const libc::c_char as *mut yaml_char_t,
1185
0
        },
1186
0
        yaml_tag_directive_t {
1187
0
            handle: b"!!\0" as *const u8 as *const libc::c_char as *mut yaml_char_t,
1188
0
            prefix: b"tag:yaml.org,2002:\0" as *const u8 as *const libc::c_char as *mut yaml_char_t,
1189
0
        },
1190
0
        yaml_tag_directive_t {
1191
0
            handle: ptr::null_mut::<yaml_char_t>(),
1192
0
            prefix: ptr::null_mut::<yaml_char_t>(),
1193
0
        },
1194
0
    ];
1195
    let mut default_tag_directive: *mut yaml_tag_directive_t;
1196
0
    let mut version_directive: *mut yaml_version_directive_t =
1197
0
        ptr::null_mut::<yaml_version_directive_t>();
1198
    struct TagDirectives {
1199
        start: *mut yaml_tag_directive_t,
1200
        end: *mut yaml_tag_directive_t,
1201
        top: *mut yaml_tag_directive_t,
1202
    }
1203
0
    let mut tag_directives = TagDirectives {
1204
0
        start: ptr::null_mut::<yaml_tag_directive_t>(),
1205
0
        end: ptr::null_mut::<yaml_tag_directive_t>(),
1206
0
        top: ptr::null_mut::<yaml_tag_directive_t>(),
1207
0
    };
1208
    let mut token: *mut yaml_token_t;
1209
0
    STACK_INIT!(tag_directives, yaml_tag_directive_t);
1210
0
    token = PEEK_TOKEN(parser);
1211
0
    if !token.is_null() {
1212
        loop {
1213
0
            if !((*token).type_ == YAML_VERSION_DIRECTIVE_TOKEN
1214
0
                || (*token).type_ == YAML_TAG_DIRECTIVE_TOKEN)
1215
            {
1216
0
                current_block = 16924917904204750491;
1217
0
                break;
1218
0
            }
1219
0
            if (*token).type_ == YAML_VERSION_DIRECTIVE_TOKEN {
1220
0
                if !version_directive.is_null() {
1221
0
                    yaml_parser_set_parser_error(
1222
0
                        parser,
1223
0
                        b"found duplicate %YAML directive\0" as *const u8 as *const libc::c_char,
1224
0
                        (*token).start_mark,
1225
                    );
1226
0
                    current_block = 17143798186130252483;
1227
0
                    break;
1228
0
                } else if (*token).data.version_directive.major != 1
1229
0
                    || (*token).data.version_directive.minor != 1
1230
0
                        && (*token).data.version_directive.minor != 2
1231
                {
1232
0
                    yaml_parser_set_parser_error(
1233
0
                        parser,
1234
0
                        b"found incompatible YAML document\0" as *const u8 as *const libc::c_char,
1235
0
                        (*token).start_mark,
1236
                    );
1237
0
                    current_block = 17143798186130252483;
1238
0
                    break;
1239
0
                } else {
1240
0
                    version_directive =
1241
0
                        yaml_malloc(size_of::<yaml_version_directive_t>() as libc::c_ulong)
1242
0
                            as *mut yaml_version_directive_t;
1243
0
                    (*version_directive).major = (*token).data.version_directive.major;
1244
0
                    (*version_directive).minor = (*token).data.version_directive.minor;
1245
0
                }
1246
0
            } else if (*token).type_ == YAML_TAG_DIRECTIVE_TOKEN {
1247
0
                let value = yaml_tag_directive_t {
1248
0
                    handle: (*token).data.tag_directive.handle,
1249
0
                    prefix: (*token).data.tag_directive.prefix,
1250
0
                };
1251
0
                if yaml_parser_append_tag_directive(parser, value, false, (*token).start_mark).fail
1252
                {
1253
0
                    current_block = 17143798186130252483;
1254
0
                    break;
1255
0
                }
1256
0
                PUSH!(tag_directives, value);
1257
0
            }
1258
0
            SKIP_TOKEN(parser);
1259
0
            token = PEEK_TOKEN(parser);
1260
0
            if token.is_null() {
1261
0
                current_block = 17143798186130252483;
1262
0
                break;
1263
0
            }
1264
        }
1265
0
        if current_block != 17143798186130252483 {
1266
0
            default_tag_directive = default_tag_directives.as_mut_ptr();
1267
            loop {
1268
0
                if (*default_tag_directive).handle.is_null() {
1269
0
                    current_block = 18377268871191777778;
1270
0
                    break;
1271
0
                }
1272
0
                if yaml_parser_append_tag_directive(
1273
0
                    parser,
1274
0
                    *default_tag_directive,
1275
0
                    true,
1276
0
                    (*token).start_mark,
1277
0
                )
1278
0
                .fail
1279
                {
1280
0
                    current_block = 17143798186130252483;
1281
0
                    break;
1282
0
                }
1283
0
                default_tag_directive = default_tag_directive.wrapping_offset(1);
1284
            }
1285
0
            if current_block != 17143798186130252483 {
1286
0
                if !version_directive_ref.is_null() {
1287
0
                    *version_directive_ref = version_directive;
1288
0
                }
1289
0
                if !tag_directives_start_ref.is_null() {
1290
0
                    if STACK_EMPTY!(tag_directives) {
1291
0
                        *tag_directives_end_ref = ptr::null_mut::<yaml_tag_directive_t>();
1292
0
                        *tag_directives_start_ref = *tag_directives_end_ref;
1293
0
                        STACK_DEL!(tag_directives);
1294
0
                    } else {
1295
0
                        *tag_directives_start_ref = tag_directives.start;
1296
0
                        *tag_directives_end_ref = tag_directives.top;
1297
0
                    }
1298
0
                } else {
1299
0
                    STACK_DEL!(tag_directives);
1300
0
                }
1301
0
                if version_directive_ref.is_null() {
1302
0
                    yaml_free(version_directive as *mut libc::c_void);
1303
0
                }
1304
0
                return OK;
1305
0
            }
1306
0
        }
1307
0
    }
1308
0
    yaml_free(version_directive as *mut libc::c_void);
1309
0
    while !STACK_EMPTY!(tag_directives) {
1310
0
        let tag_directive = POP!(tag_directives);
1311
0
        yaml_free(tag_directive.handle as *mut libc::c_void);
1312
0
        yaml_free(tag_directive.prefix as *mut libc::c_void);
1313
0
    }
1314
0
    STACK_DEL!(tag_directives);
1315
0
    FAIL
1316
0
}
1317
1318
0
unsafe fn yaml_parser_append_tag_directive(
1319
0
    parser: *mut yaml_parser_t,
1320
0
    value: yaml_tag_directive_t,
1321
0
    allow_duplicates: bool,
1322
0
    mark: yaml_mark_t,
1323
0
) -> Success {
1324
    let mut tag_directive: *mut yaml_tag_directive_t;
1325
0
    let mut copy = yaml_tag_directive_t {
1326
0
        handle: ptr::null_mut::<yaml_char_t>(),
1327
0
        prefix: ptr::null_mut::<yaml_char_t>(),
1328
0
    };
1329
0
    tag_directive = (*parser).tag_directives.start;
1330
0
    while tag_directive != (*parser).tag_directives.top {
1331
0
        if strcmp(
1332
0
            value.handle as *mut libc::c_char,
1333
0
            (*tag_directive).handle as *mut libc::c_char,
1334
0
        ) == 0
1335
        {
1336
0
            if allow_duplicates {
1337
0
                return OK;
1338
0
            }
1339
0
            yaml_parser_set_parser_error(
1340
0
                parser,
1341
0
                b"found duplicate %TAG directive\0" as *const u8 as *const libc::c_char,
1342
0
                mark,
1343
            );
1344
0
            return FAIL;
1345
0
        }
1346
0
        tag_directive = tag_directive.wrapping_offset(1);
1347
    }
1348
0
    copy.handle = yaml_strdup(value.handle);
1349
0
    copy.prefix = yaml_strdup(value.prefix);
1350
0
    PUSH!((*parser).tag_directives, copy);
1351
0
    OK
1352
0
}