485 #define CACHE(parser,length) \
486 (parser->unread >= (length) \
488 : yaml_parser_update_buffer(parser, (length)))
494 #define SKIP(parser) \
495 (parser->mark.index ++, \
496 parser->mark.column ++, \
498 parser->buffer.pointer += WIDTH(parser->buffer))
500 #define SKIP_LINE(parser) \
501 (IS_CRLF(parser->buffer) ? \
502 (parser->mark.index += 2, \
503 parser->mark.column = 0, \
504 parser->mark.line ++, \
505 parser->unread -= 2, \
506 parser->buffer.pointer += 2) : \
507 IS_BREAK(parser->buffer) ? \
508 (parser->mark.index ++, \
509 parser->mark.column = 0, \
510 parser->mark.line ++, \
512 parser->buffer.pointer += WIDTH(parser->buffer)) : 0)
518 #define READ(parser,string) \
519 (STRING_EXTEND(parser,string) ? \
520 (COPY(string,parser->buffer), \
521 parser->mark.index ++, \
522 parser->mark.column ++, \
530 #define READ_LINE(parser,string) \
531 (STRING_EXTEND(parser,string) ? \
532 (((CHECK_AT(parser->buffer,'\r',0) \
533 && CHECK_AT(parser->buffer,'\n',1)) ? \
534 (*((string).pointer++) = (yaml_char_t) '\n', \
535 parser->buffer.pointer += 2, \
536 parser->mark.index += 2, \
537 parser->mark.column = 0, \
538 parser->mark.line ++, \
539 parser->unread -= 2) : \
540 (CHECK_AT(parser->buffer,'\r',0) \
541 || CHECK_AT(parser->buffer,'\n',0)) ? \
542 (*((string).pointer++) = (yaml_char_t) '\n', \
543 parser->buffer.pointer ++, \
544 parser->mark.index ++, \
545 parser->mark.column = 0, \
546 parser->mark.line ++, \
547 parser->unread --) : \
548 (CHECK_AT(parser->buffer,'\xC2',0) \
549 && CHECK_AT(parser->buffer,'\x85',1)) ? \
550 (*((string).pointer++) = (yaml_char_t) '\n', \
551 parser->buffer.pointer += 2, \
552 parser->mark.index ++, \
553 parser->mark.column = 0, \
554 parser->mark.line ++, \
555 parser->unread --) : \
556 (CHECK_AT(parser->buffer,'\xE2',0) && \
557 CHECK_AT(parser->buffer,'\x80',1) && \
558 (CHECK_AT(parser->buffer,'\xA8',2) || \
559 CHECK_AT(parser->buffer,'\xA9',2))) ? \
560 (*((string).pointer++) = *(parser->buffer.pointer++), \
561 *((string).pointer++) = *(parser->buffer.pointer++), \
562 *((string).pointer++) = *(parser->buffer.pointer++), \
563 parser->mark.index ++, \
564 parser->mark.column = 0, \
565 parser->mark.line ++, \
566 parser->unread --) : 0), \
753 if (parser->stream_end_produced || parser->error) {
759 if (!parser->token_available) {
766 *token =
DEQUEUE(parser, parser->tokens);
767 parser->token_available = 0;
768 parser->tokens_parsed ++;
771 parser->stream_end_produced = 1;
802 int need_more_tokens;
812 need_more_tokens = 0;
814 if (parser->tokens.head == parser->tokens.tail)
818 need_more_tokens = 1;
829 for (simple_key = parser->simple_keys.start;
830 simple_key != parser->simple_keys.top; simple_key++) {
833 need_more_tokens = 1;
841 if (!need_more_tokens)
850 parser->token_available = 1;
864 if (!
CACHE(parser, 1))
892 if (!
CACHE(parser, 4))
1046 "while scanning for the next token", parser->
mark,
1047 "found character that cannot start any token");
1080 "while scanning a simple key", simple_key->
mark,
1081 "could not find expected ':'");
1151 "while scanning a simple key", simple_key->
mark,
1152 "could not find expected ':'");
1222 if (parser->
indent < column)
1232 #if PTRDIFF_MAX > INT_MAX
1233 if (column > INT_MAX) {
1239 parser->
indent = (int)column;
1278 while (parser->
indent > column)
1432 start_mark = parser->
mark;
1438 end_mark = parser->
mark;
1442 TOKEN_INIT(token, type, start_mark, end_mark);
1479 start_mark = parser->
mark;
1481 end_mark = parser->
mark;
1485 TOKEN_INIT(token, type, start_mark, end_mark);
1522 start_mark = parser->
mark;
1524 end_mark = parser->
mark;
1528 TOKEN_INIT(token, type, start_mark, end_mark);
1559 start_mark = parser->
mark;
1561 end_mark = parser->
mark;
1591 "block sequence entries are not allowed in this context");
1620 start_mark = parser->
mark;
1622 end_mark = parser->
mark;
1652 "mapping keys are not allowed in this context");
1673 start_mark = parser->
mark;
1675 end_mark = parser->
mark;
1738 "mapping values are not allowed in this context");
1755 start_mark = parser->
mark;
1757 end_mark = parser->
mark;
1936 if (!
CACHE(parser, 1))
return 0;
1951 if (!
CACHE(parser, 1))
return 0;
1957 if (!
CACHE(parser, 1))
return 0;
1965 if (!
CACHE(parser, 1))
return 0;
1973 if (!
CACHE(parser, 2))
return 0;
2013 start_mark = parser->
mark;
2024 if (strcmp((
char *)name,
"YAML") == 0)
2032 end_mark = parser->
mark;
2037 start_mark, end_mark);
2042 else if (strcmp((
char *)name,
"TAG") == 0)
2050 end_mark = parser->
mark;
2055 start_mark, end_mark);
2063 start_mark,
"found uknown directive name");
2069 if (!
CACHE(parser, 1))
goto error;
2073 if (!
CACHE(parser, 1))
goto error;
2079 if (!
CACHE(parser, 1))
goto error;
2087 start_mark,
"did not find expected comment or line break");
2094 if (!
CACHE(parser, 2))
goto error;
2129 if (!
CACHE(parser, 1))
goto error;
2133 if (!
READ(parser,
string))
goto error;
2134 if (!
CACHE(parser, 1))
goto error;
2139 if (
string.start ==
string.pointer) {
2141 start_mark,
"could not find expected directive name");
2149 start_mark,
"found unexpected non-alphabetical character");
2153 *name =
string.start;
2176 if (!
CACHE(parser, 1))
return 0;
2180 if (!
CACHE(parser, 1))
return 0;
2192 start_mark,
"did not find expected digit or '.' character");
2205 #define MAX_NUMBER_LENGTH 9
2226 if (!
CACHE(parser, 1))
return 0;
2234 start_mark,
"found extremely long version number");
2241 if (!
CACHE(parser, 1))
return 0;
2248 start_mark,
"did not find expected version number");
2273 if (!
CACHE(parser, 1))
goto error;
2277 if (!
CACHE(parser, 1))
goto error;
2287 if (!
CACHE(parser, 1))
goto error;
2291 start_mark,
"did not find expected whitespace");
2299 if (!
CACHE(parser, 1))
goto error;
2309 if (!
CACHE(parser, 1))
goto error;
2313 start_mark,
"did not find expected whitespace or line break");
2317 *handle = handle_value;
2318 *prefix = prefix_value;
2340 start_mark = parser->
mark;
2346 if (!
CACHE(parser, 1))
goto error;
2349 if (!
READ(parser,
string))
goto error;
2350 if (!
CACHE(parser, 1))
goto error;
2354 end_mark = parser->
mark;
2369 "while scanning an anchor" :
"while scanning an alias", start_mark,
2370 "did not find expected alphabetic or numeric character");
2401 start_mark = parser->
mark;
2405 if (!
CACHE(parser, 2))
goto error;
2412 if (!handle)
goto error;
2429 start_mark,
"did not find the expected '>'");
2446 if (handle[0] ==
'!' && handle[1] !=
'\0' && handle[
strlen((
char *)handle)-1] ==
'!')
2464 if (!handle)
goto error;
2473 if (suffix[0] ==
'\0') {
2483 if (!
CACHE(parser, 1))
goto error;
2487 start_mark,
"did not find expected whitespace or line break");
2491 end_mark = parser->
mark;
2519 if (!
CACHE(parser, 1))
goto error;
2523 "while scanning a tag directive" :
"while scanning a tag",
2524 start_mark,
"did not find expected '!'");
2530 if (!
READ(parser,
string))
goto error;
2534 if (!
CACHE(parser, 1))
goto error;
2538 if (!
READ(parser,
string))
goto error;
2539 if (!
CACHE(parser, 1))
goto error;
2546 if (!
READ(parser,
string))
goto error;
2556 if (directive && !(
string.start[0] ==
'!' &&
string.start[1] ==
'\0')) {
2558 start_mark,
"did not find expected '!'");
2563 *handle =
string.start;
2580 size_t length = head ?
strlen((
char *)head) : 0;
2587 while ((
size_t)(
string.end -
string.start) <= length) {
2601 memcpy(
string.start, head+1, length-1);
2602 string.pointer += length-1;
2607 if (!
CACHE(parser, 1))
goto error;
2636 directive, start_mark, &
string))
goto error;
2639 if (!
READ(parser,
string))
goto error;
2643 if (!
CACHE(parser, 1))
goto error;
2653 "while parsing a %TAG directive" :
"while parsing a tag",
2654 start_mark,
"did not find expected tag URI");
2658 *uri =
string.start;
2681 unsigned char octet = 0;
2685 if (!
CACHE(parser, 3))
return 0;
2691 "while parsing a %TAG directive" :
"while parsing a tag",
2692 start_mark,
"did not find URI escaped octet");
2703 width = (octet & 0x80) == 0x00 ? 1 :
2704 (octet & 0xE0) == 0xC0 ? 2 :
2705 (octet & 0xF0) == 0xE0 ? 3 :
2706 (octet & 0xF8) == 0xF0 ? 4 : 0;
2709 "while parsing a %TAG directive" :
"while parsing a tag",
2710 start_mark,
"found an incorrect leading UTF-8 octet");
2717 if ((octet & 0xC0) != 0x80) {
2719 "while parsing a %TAG directive" :
"while parsing a tag",
2720 start_mark,
"found an incorrect trailing UTF-8 octet");
2726 *(
string->pointer++) = octet;
2752 int leading_blank = 0;
2753 int trailing_blank = 0;
2761 start_mark = parser->
mark;
2767 if (!
CACHE(parser, 1))
goto error;
2781 if (!
CACHE(parser, 1))
goto error;
2789 start_mark,
"found an intendation indicator equal to 0");
2807 start_mark,
"found an intendation indicator equal to 0");
2815 if (!
CACHE(parser, 1))
goto error;
2826 if (!
CACHE(parser, 1))
goto error;
2830 if (!
CACHE(parser, 1))
goto error;
2836 if (!
CACHE(parser, 1))
goto error;
2844 start_mark,
"did not find expected comment or line break");
2851 if (!
CACHE(parser, 2))
goto error;
2855 end_mark = parser->
mark;
2860 indent = parser->
indent >= 0 ? parser->
indent+increment : increment;
2866 start_mark, &end_mark))
goto error;
2870 if (!
CACHE(parser, 1))
goto error;
2884 if (!literal && (*leading_break.
start ==
'\n')
2885 && !leading_blank && !trailing_blank)
2889 if (*trailing_breaks.
start ==
'\0') {
2891 *(
string.pointer ++) =
' ';
2894 CLEAR(parser, leading_break);
2897 if (!
JOIN(parser,
string, leading_break))
goto error;
2898 CLEAR(parser, leading_break);
2903 if (!
JOIN(parser,
string, trailing_breaks))
goto error;
2904 CLEAR(parser, trailing_breaks);
2913 if (!
READ(parser,
string))
goto error;
2914 if (!
CACHE(parser, 1))
goto error;
2919 if (!
CACHE(parser, 2))
goto error;
2921 if (!
READ_LINE(parser, leading_break))
goto error;
2926 &indent, &trailing_breaks, start_mark, &end_mark))
goto error;
2931 if (chomping != -1) {
2932 if (!
JOIN(parser,
string, leading_break))
goto error;
2934 if (chomping == 1) {
2935 if (!
JOIN(parser,
string, trailing_breaks))
goto error;
2942 start_mark, end_mark);
2969 *end_mark = parser->
mark;
2977 if (!
CACHE(parser, 1))
return 0;
2979 while ((!*indent || (
int)parser->
mark.
column < *indent)
2982 if (!
CACHE(parser, 1))
return 0;
2993 start_mark,
"found a tab character where an intendation space is expected");
3002 if (!
CACHE(parser, 2))
return 0;
3003 if (!
READ_LINE(parser, *breaks))
return 0;
3004 *end_mark = parser->
mark;
3010 *indent = max_indent;
3011 if (*indent < parser->indent + 1)
3012 *indent = parser->
indent + 1;
3043 start_mark = parser->
mark;
3053 if (!
CACHE(parser, 4))
goto error;
3065 start_mark,
"found unexpected document indicator");
3073 start_mark,
"found unexpected end of stream");
3079 if (!
CACHE(parser, 2))
goto error;
3091 *(
string.pointer++) =
'\'';
3098 else if (
CHECK(parser->
buffer, single ?
'\'' :
'"'))
3108 if (!
CACHE(parser, 3))
goto error;
3119 size_t code_length = 0;
3128 *(
string.pointer++) =
'\0';
3132 *(
string.pointer++) =
'\x07';
3136 *(
string.pointer++) =
'\x08';
3141 *(
string.pointer++) =
'\x09';
3145 *(
string.pointer++) =
'\x0A';
3149 *(
string.pointer++) =
'\x0B';
3153 *(
string.pointer++) =
'\x0C';
3157 *(
string.pointer++) =
'\x0D';
3161 *(
string.pointer++) =
'\x1B';
3165 *(
string.pointer++) =
'\x20';
3169 *(
string.pointer++) =
'"';
3173 *(
string.pointer++) =
'\'';
3177 *(
string.pointer++) =
'\\';
3181 *(
string.pointer++) =
'\xC2';
3182 *(
string.pointer++) =
'\x85';
3186 *(
string.pointer++) =
'\xC2';
3187 *(
string.pointer++) =
'\xA0';
3191 *(
string.pointer++) =
'\xE2';
3192 *(
string.pointer++) =
'\x80';
3193 *(
string.pointer++) =
'\xA8';
3197 *(
string.pointer++) =
'\xE2';
3198 *(
string.pointer++) =
'\x80';
3199 *(
string.pointer++) =
'\xA9';
3216 start_mark,
"found unknown escape character");
3227 unsigned int value = 0;
3232 if (!
CACHE(parser, code_length))
goto error;
3234 for (k = 0; k < code_length; k ++) {
3237 start_mark,
"did not find expected hexdecimal number");
3245 if ((value >= 0xD800 && value <= 0xDFFF) || value > 0x10FFFF) {
3247 start_mark,
"found invalid Unicode character escape code");
3251 if (value <= 0x7F) {
3252 *(
string.pointer++) = value;
3254 else if (value <= 0x7FF) {
3255 *(
string.pointer++) = 0xC0 + (value >> 6);
3256 *(
string.pointer++) = 0x80 + (value & 0x3F);
3258 else if (value <= 0xFFFF) {
3259 *(
string.pointer++) = 0xE0 + (value >> 12);
3260 *(
string.pointer++) = 0x80 + ((value >> 6) & 0x3F);
3261 *(
string.pointer++) = 0x80 + (value & 0x3F);
3264 *(
string.pointer++) = 0xF0 + (value >> 18);
3265 *(
string.pointer++) = 0x80 + ((value >> 12) & 0x3F);
3266 *(
string.pointer++) = 0x80 + ((value >> 6) & 0x3F);
3267 *(
string.pointer++) = 0x80 + (value & 0x3F);
3272 for (k = 0; k < code_length; k ++) {
3282 if (!
READ(parser,
string))
goto error;
3285 if (!
CACHE(parser, 2))
goto error;
3295 if (!
CACHE(parser, 1))
goto error;
3303 if (!leading_blanks) {
3304 if (!
READ(parser, whitespaces))
goto error;
3312 if (!
CACHE(parser, 2))
goto error;
3316 if (!leading_blanks)
3318 CLEAR(parser, whitespaces);
3319 if (!
READ_LINE(parser, leading_break))
goto error;
3324 if (!
READ_LINE(parser, trailing_breaks))
goto error;
3327 if (!
CACHE(parser, 1))
goto error;
3336 if (leading_break.
start[0] ==
'\n') {
3337 if (trailing_breaks.
start[0] ==
'\0') {
3339 *(
string.pointer++) =
' ';
3342 if (!
JOIN(parser,
string, trailing_breaks))
goto error;
3343 CLEAR(parser, trailing_breaks);
3345 CLEAR(parser, leading_break);
3348 if (!
JOIN(parser,
string, leading_break))
goto error;
3349 if (!
JOIN(parser,
string, trailing_breaks))
goto error;
3350 CLEAR(parser, leading_break);
3351 CLEAR(parser, trailing_breaks);
3356 if (!
JOIN(parser,
string, whitespaces))
goto error;
3357 CLEAR(parser, whitespaces);
3365 end_mark = parser->
mark;
3371 start_mark, end_mark);
3401 int leading_blanks = 0;
3402 int indent = parser->
indent+1;
3409 start_mark = end_mark = parser->
mark;
3417 if (!
CACHE(parser, 4))
goto error;
3443 start_mark,
"found unexpected ':'");
3459 if (leading_blanks || whitespaces.
start != whitespaces.
pointer)
3465 if (leading_break.
start[0] ==
'\n') {
3466 if (trailing_breaks.
start[0] ==
'\0') {
3468 *(
string.pointer++) =
' ';
3471 if (!
JOIN(parser,
string, trailing_breaks))
goto error;
3472 CLEAR(parser, trailing_breaks);
3474 CLEAR(parser, leading_break);
3477 if (!
JOIN(parser,
string, leading_break))
goto error;
3478 if (!
JOIN(parser,
string, trailing_breaks))
goto error;
3479 CLEAR(parser, leading_break);
3480 CLEAR(parser, trailing_breaks);
3487 if (!
JOIN(parser,
string, whitespaces))
goto error;
3488 CLEAR(parser, whitespaces);
3494 if (!
READ(parser,
string))
goto error;
3496 end_mark = parser->
mark;
3498 if (!
CACHE(parser, 2))
goto error;
3508 if (!
CACHE(parser, 1))
goto error;
3516 if (leading_blanks && (
int)parser->
mark.
column < indent
3519 start_mark,
"found a tab character that violate intendation");
3525 if (!leading_blanks) {
3526 if (!
READ(parser, whitespaces))
goto error;
3534 if (!
CACHE(parser, 2))
goto error;
3538 if (!leading_blanks)
3540 CLEAR(parser, whitespaces);
3541 if (!
READ_LINE(parser, leading_break))
goto error;
3546 if (!
READ_LINE(parser, trailing_breaks))
goto error;
3549 if (!
CACHE(parser, 1))
goto error;
3565 if (leading_blanks) {