MCPcopy Create free account
hub / github.com/Moddable-OpenSource/moddable / yaml_parser_scan_plain_scalar

Function yaml_parser_scan_plain_scalar

xs/tools/yaml/scanner.c:3407–3597  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

3405 */
3406
3407static int
3408yaml_parser_scan_plain_scalar(yaml_parser_t *parser, yaml_token_t *token)
3409{
3410 yaml_mark_t start_mark;
3411 yaml_mark_t end_mark;
3412 yaml_string_t string = NULL_STRING;
3413 yaml_string_t leading_break = NULL_STRING;
3414 yaml_string_t trailing_breaks = NULL_STRING;
3415 yaml_string_t whitespaces = NULL_STRING;
3416 int leading_blanks = 0;
3417 int indent = parser->indent+1;
3418
3419 if (!STRING_INIT(parser, string, INITIAL_STRING_SIZE)) goto error;
3420 if (!STRING_INIT(parser, leading_break, INITIAL_STRING_SIZE)) goto error;
3421 if (!STRING_INIT(parser, trailing_breaks, INITIAL_STRING_SIZE)) goto error;
3422 if (!STRING_INIT(parser, whitespaces, INITIAL_STRING_SIZE)) goto error;
3423
3424 start_mark = end_mark = parser->mark;
3425
3426 /* Consume the content of the plain scalar. */
3427
3428 while (1)
3429 {
3430 /* Check for a document indicator. */
3431
3432 if (!CACHE(parser, 4)) goto error;
3433
3434 if (parser->mark.column == 0 &&
3435 ((CHECK_AT(parser->buffer, '-', 0) &&
3436 CHECK_AT(parser->buffer, '-', 1) &&
3437 CHECK_AT(parser->buffer, '-', 2)) ||
3438 (CHECK_AT(parser->buffer, '.', 0) &&
3439 CHECK_AT(parser->buffer, '.', 1) &&
3440 CHECK_AT(parser->buffer, '.', 2))) &&
3441 IS_BLANKZ_AT(parser->buffer, 3)) break;
3442
3443 /* Check for a comment. */
3444
3445 if (CHECK(parser->buffer, '#'))
3446 break;
3447
3448 /* Consume non-blank characters. */
3449
3450 while (!IS_BLANKZ(parser->buffer))
3451 {
3452 /* Check for 'x:x' in the flow context. TODO: Fix the test "spec-08-13". */
3453
3454 if (parser->flow_level
3455 && CHECK(parser->buffer, ':')
3456 && !IS_BLANKZ_AT(parser->buffer, 1)) {
3457 yaml_parser_set_scanner_error(parser, "while scanning a plain scalar",
3458 start_mark, "found unexpected ':'");
3459 goto error;
3460 }
3461
3462 /* Check for indicators that may end a plain scalar. */
3463
3464 if ((CHECK(parser->buffer, ':') && IS_BLANKZ_AT(parser->buffer, 1))

Callers 1

Calls 1

Tested by

no test coverage detected