X-Git-Url: http://andersk.mit.edu/gitweb/libyaml.git/blobdiff_plain/54815ffd349279576102da76745f482b5ba5a236..bc67233b541d9e50a71288524db71e4f663d9433:/src/scanner.c diff --git a/src/scanner.c b/src/scanner.c index a9b78ff..1189d9d 100644 --- a/src/scanner.c +++ b/src/scanner.c @@ -70,7 +70,7 @@ * %TAG !yaml! tag:yaml.org,2002: * --- * - * The correspoding sequence of tokens: + * The corresponding sequence of tokens: * * STREAM-START(utf-8) * VERSION-DIRECTIVE(1,1) @@ -487,190 +487,6 @@ ? 1 \ : yaml_parser_update_buffer(parser, (length))) -/* - * Check the octet at the specified position. - */ - -#define CHECK_AT(parser,octet,offset) \ - (parser->buffer.pointer[offset] == (yaml_char_t)(octet)) - -/* - * Check the current octet in the buffer. - */ - -#define CHECK(parser,octet) CHECK_AT(parser,(octet),0) - -/* - * Check if the character at the specified position is an alphabetical - * character, a digit, '_', or '-'. - */ - -#define IS_ALPHA_AT(parser,offset) \ - ((parser->buffer.pointer[offset] >= (yaml_char_t) '0' && \ - parser->buffer.pointer[offset] <= (yaml_char_t) '9') || \ - (parser->buffer.pointer[offset] >= (yaml_char_t) 'A' && \ - parser->buffer.pointer[offset] <= (yaml_char_t) 'Z') || \ - (parser->buffer.pointer[offset] >= (yaml_char_t) 'a' && \ - parser->buffer.pointer[offset] <= (yaml_char_t) 'z') || \ - parser->buffer.pointer[offset] == '_' || \ - parser->buffer.pointer[offset] == '-') - -#define IS_ALPHA(parser) IS_ALPHA_AT(parser,0) - -/* - * Check if the character at the specified position is a digit. - */ - -#define IS_DIGIT_AT(parser,offset) \ - ((parser->buffer.pointer[offset] >= (yaml_char_t) '0' && \ - parser->buffer.pointer[offset] <= (yaml_char_t) '9')) - -#define IS_DIGIT(parser) IS_DIGIT_AT(parser,0) - -/* - * Get the value of a digit. - */ - -#define AS_DIGIT_AT(parser,offset) \ - (parser->buffer.pointer[offset] - (yaml_char_t) '0') - -#define AS_DIGIT(parser) AS_DIGIT_AT(parser,0) - -/* - * Check if the character at the specified position is a hex-digit. - */ - -#define IS_HEX_AT(parser,offset) \ - ((parser->buffer.pointer[offset] >= (yaml_char_t) '0' && \ - parser->buffer.pointer[offset] <= (yaml_char_t) '9') || \ - (parser->buffer.pointer[offset] >= (yaml_char_t) 'A' && \ - parser->buffer.pointer[offset] <= (yaml_char_t) 'F') || \ - (parser->buffer.pointer[offset] >= (yaml_char_t) 'a' && \ - parser->buffer.pointer[offset] <= (yaml_char_t) 'f')) - -#define IS_HEX(parser) IS_HEX_AT(parser,0) - -/* - * Get the value of a hex-digit. - */ - -#define AS_HEX_AT(parser,offset) \ - ((parser->buffer.pointer[offset] >= (yaml_char_t) 'A' && \ - parser->buffer.pointer[offset] <= (yaml_char_t) 'F') ? \ - (parser->buffer.pointer[offset] - (yaml_char_t) 'A' + 10) : \ - (parser->buffer.pointer[offset] >= (yaml_char_t) 'a' && \ - parser->buffer.pointer[offset] <= (yaml_char_t) 'f') ? \ - (parser->buffer.pointer[offset] - (yaml_char_t) 'a' + 10) : \ - (parser->buffer.pointer[offset] - (yaml_char_t) '0')) - -#define AS_HEX(parser) AS_HEX_AT(parser,0) - -/* - * Check if the character at the specified position is NUL. - */ - -#define IS_Z_AT(parser,offset) CHECK_AT(parser,'\0',(offset)) - -#define IS_Z(parser) IS_Z_AT(parser,0) - -/* - * Check if the character at the specified position is BOM. - */ - -#define IS_BOM_AT(parser,offset) \ - (CHECK_AT(parser,'\xEF',(offset)) \ - && CHECK_AT(parser,'\xBB',(offset)+1) \ - && CHECK_AT(parser,'\xBF',(offset)+1)) /* BOM (#xFEFF) */ - -#define IS_BOM(parser) IS_BOM_AT(parser,0) - -/* - * Check if the character at the specified position is space. - */ - -#define IS_SPACE_AT(parser,offset) CHECK_AT(parser,' ',(offset)) - -#define IS_SPACE(parser) IS_SPACE_AT(parser,0) - -/* - * Check if the character at the specified position is tab. - */ - -#define IS_TAB_AT(parser,offset) CHECK_AT(parser,'\t',(offset)) - -#define IS_TAB(parser) IS_TAB_AT(parser,0) - -/* - * Check if the character at the specified position is blank (space or tab). - */ - -#define IS_BLANK_AT(parser,offset) \ - (IS_SPACE_AT(parser,(offset)) || IS_TAB_AT(parser,(offset))) - -#define IS_BLANK(parser) IS_BLANK_AT(parser,0) - -/* - * Check if the character at the specified position is a line break. - */ - -#define IS_BREAK_AT(parser,offset) \ - (CHECK_AT(parser,'\r',(offset)) /* CR (#xD)*/ \ - || CHECK_AT(parser,'\n',(offset)) /* LF (#xA) */ \ - || (CHECK_AT(parser,'\xC2',(offset)) \ - && CHECK_AT(parser,'\x85',(offset)+1)) /* NEL (#x85) */ \ - || (CHECK_AT(parser,'\xE2',(offset)) \ - && CHECK_AT(parser,'\x80',(offset)+1) \ - && CHECK_AT(parser,'\xA8',(offset)+2)) /* LS (#x2028) */ \ - || (CHECK_AT(parser,'\xE2',(offset)) \ - && CHECK_AT(parser,'\x80',(offset)+1) \ - && CHECK_AT(parser,'\xA9',(offset)+2))) /* PS (#x2029) */ - -#define IS_BREAK(parser) IS_BREAK_AT(parser,0) - -#define IS_CRLF_AT(parser,offset) \ - (CHECK_AT(parser,'\r',(offset)) && CHECK_AT(parser,'\n',(offset)+1)) - -#define IS_CRLF(parser) IS_CRLF_AT(parser,0) - -/* - * Check if the character is a line break or NUL. - */ - -#define IS_BREAKZ_AT(parser,offset) \ - (IS_BREAK_AT(parser,(offset)) || IS_Z_AT(parser,(offset))) - -#define IS_BREAKZ(parser) IS_BREAKZ_AT(parser,0) - -/* - * Check if the character is a line break, space, or NUL. - */ - -#define IS_SPACEZ_AT(parser,offset) \ - (IS_SPACE_AT(parser,(offset)) || IS_BREAKZ_AT(parser,(offset))) - -#define IS_SPACEZ(parser) IS_SPACEZ_AT(parser,0) - -/* - * Check if the character is a line break, space, tab, or NUL. - */ - -#define IS_BLANKZ_AT(parser,offset) \ - (IS_BLANK_AT(parser,(offset)) || IS_BREAKZ_AT(parser,(offset))) - -#define IS_BLANKZ(parser) IS_BLANKZ_AT(parser,0) - -/* - * Determine the width of the character. - */ - -#define WIDTH_AT(parser,offset) \ - ((parser->buffer.pointer[offset] & 0x80) == 0x00 ? 1 : \ - (parser->buffer.pointer[offset] & 0xE0) == 0xC0 ? 2 : \ - (parser->buffer.pointer[offset] & 0xF0) == 0xE0 ? 3 : \ - (parser->buffer.pointer[offset] & 0xF8) == 0xF0 ? 4 : 0) - -#define WIDTH(parser) WIDTH_AT(parser,0) - /* * Advance the buffer pointer. */ @@ -679,21 +495,21 @@ (parser->mark.index ++, \ parser->mark.column ++, \ parser->unread --, \ - parser->buffer.pointer += WIDTH(parser)) + parser->buffer.pointer += WIDTH(parser->buffer)) #define SKIP_LINE(parser) \ - (IS_CRLF(parser) ? \ + (IS_CRLF(parser->buffer) ? \ (parser->mark.index += 2, \ parser->mark.column = 0, \ parser->mark.line ++, \ parser->unread -= 2, \ parser->buffer.pointer += 2) : \ - IS_BREAK(parser) ? \ + IS_BREAK(parser->buffer) ? \ (parser->mark.index ++, \ parser->mark.column = 0, \ parser->mark.line ++, \ parser->unread --, \ - parser->buffer.pointer += WIDTH(parser)) : 0) + parser->buffer.pointer += WIDTH(parser->buffer)) : 0) /* * Copy a character to a string buffer and advance pointers. @@ -701,20 +517,7 @@ #define READ(parser,string) \ (STRING_EXTEND(parser,string) ? \ - (((*parser->buffer.pointer & 0x80) == 0x00 ? \ - (*((string).pointer++) = *(parser->buffer.pointer++)) : \ - (*parser->buffer.pointer & 0xE0) == 0xC0 ? \ - (*((string).pointer++) = *(parser->buffer.pointer++), \ - *((string).pointer++) = *(parser->buffer.pointer++)) : \ - (*parser->buffer.pointer & 0xF0) == 0xE0 ? \ - (*((string).pointer++) = *(parser->buffer.pointer++), \ - *((string).pointer++) = *(parser->buffer.pointer++), \ - *((string).pointer++) = *(parser->buffer.pointer++)) : \ - (*parser->buffer.pointer & 0xF8) == 0xF0 ? \ - (*((string).pointer++) = *(parser->buffer.pointer++), \ - *((string).pointer++) = *(parser->buffer.pointer++), \ - *((string).pointer++) = *(parser->buffer.pointer++), \ - *((string).pointer++) = *(parser->buffer.pointer++)) : 0), \ + (COPY(string,parser->buffer), \ parser->mark.index ++, \ parser->mark.column ++, \ parser->unread --, \ @@ -726,31 +529,34 @@ #define READ_LINE(parser,string) \ (STRING_EXTEND(parser,string) ? \ - (((CHECK_AT(parser,'\r',0) && CHECK_AT(parser,'\n',1)) ? /* CR LF -> LF */ \ + (((CHECK_AT(parser->buffer,'\r',0) \ + && CHECK_AT(parser->buffer,'\n',1)) ? /* CR LF -> LF */ \ (*((string).pointer++) = (yaml_char_t) '\n', \ parser->buffer.pointer += 2, \ parser->mark.index += 2, \ parser->mark.column = 0, \ parser->mark.line ++, \ parser->unread -= 2) : \ - (CHECK_AT(parser,'\r',0) || CHECK_AT(parser,'\n',0)) ? /* CR|LF -> LF */ \ + (CHECK_AT(parser->buffer,'\r',0) \ + || CHECK_AT(parser->buffer,'\n',0)) ? /* CR|LF -> LF */ \ (*((string).pointer++) = (yaml_char_t) '\n', \ parser->buffer.pointer ++, \ parser->mark.index ++, \ parser->mark.column = 0, \ parser->mark.line ++, \ parser->unread --) : \ - (CHECK_AT(parser,'\xC2',0) && CHECK_AT(parser,'\x85',1)) ? /* NEL -> LF */ \ + (CHECK_AT(parser->buffer,'\xC2',0) \ + && CHECK_AT(parser->buffer,'\x85',1)) ? /* NEL -> LF */ \ (*((string).pointer++) = (yaml_char_t) '\n', \ parser->buffer.pointer += 2, \ parser->mark.index ++, \ parser->mark.column = 0, \ parser->mark.line ++, \ parser->unread --) : \ - (CHECK_AT(parser,'\xE2',0) && \ - CHECK_AT(parser,'\x80',1) && \ - (CHECK_AT(parser,'\xA8',2) || \ - CHECK_AT(parser,'\xA9',2))) ? /* LS|PS -> LS|PS */ \ + (CHECK_AT(parser->buffer,'\xE2',0) && \ + CHECK_AT(parser->buffer,'\x80',1) && \ + (CHECK_AT(parser->buffer,'\xA8',2) || \ + CHECK_AT(parser->buffer,'\xA9',2))) ? /* LS|PS -> LS|PS */ \ (*((string).pointer++) = *(parser->buffer.pointer++), \ *((string).pointer++) = *(parser->buffer.pointer++), \ *((string).pointer++) = *(parser->buffer.pointer++), \ @@ -760,52 +566,6 @@ parser->unread --) : 0), \ 1) : 0) -/* - * Token initializers. - */ - -#define TOKEN_INIT(token,token_type,token_start_mark,token_end_mark) \ - (memset(&(token), 0, sizeof(yaml_token_t)), \ - (token).type = (token_type), \ - (token).start_mark = (token_start_mark), \ - (token).end_mark = (token_end_mark)) - -#define STREAM_START_TOKEN_INIT(token,token_encoding,start_mark,end_mark) \ - (TOKEN_INIT((token),YAML_STREAM_START_TOKEN,(start_mark),(end_mark)), \ - (token).data.stream_start.encoding = (token_encoding)) - -#define STREAM_END_TOKEN_INIT(token,start_mark,end_mark) \ - (TOKEN_INIT((token),YAML_STREAM_END_TOKEN,(start_mark),(end_mark))) - -#define ALIAS_TOKEN_INIT(token,token_value,start_mark,end_mark) \ - (TOKEN_INIT((token),YAML_ALIAS_TOKEN,(start_mark),(end_mark)), \ - (token).data.alias.value = (token_value)) - -#define ANCHOR_TOKEN_INIT(token,token_value,start_mark,end_mark) \ - (TOKEN_INIT((token),YAML_ANCHOR_TOKEN,(start_mark),(end_mark)), \ - (token).data.anchor.value = (token_value)) - -#define TAG_TOKEN_INIT(token,token_handle,token_suffix,start_mark,end_mark) \ - (TOKEN_INIT((token),YAML_TAG_TOKEN,(start_mark),(end_mark)), \ - (token).data.tag.handle = (token_handle), \ - (token).data.tag.suffix = (token_suffix)) - -#define SCALAR_TOKEN_INIT(token,token_value,token_length,token_style,start_mark,end_mark) \ - (TOKEN_INIT((token),YAML_SCALAR_TOKEN,(start_mark),(end_mark)), \ - (token).data.scalar.value = (token_value), \ - (token).data.scalar.length = (token_length), \ - (token).data.scalar.style = (token_style)) - -#define VERSION_DIRECTIVE_TOKEN_INIT(token,token_major,token_minor,start_mark,end_mark) \ - (TOKEN_INIT((token),YAML_VERSION_DIRECTIVE_TOKEN,(start_mark),(end_mark)), \ - (token).data.version_directive.major = (token_major), \ - (token).data.version_directive.minor = (token_minor)) - -#define TAG_DIRECTIVE_TOKEN_INIT(token,token_handle,token_prefix,start_mark,end_mark) \ - (TOKEN_INIT((token),YAML_TAG_DIRECTIVE_TOKEN,(start_mark),(end_mark)), \ - (token).data.tag_directive.handle = (token_handle), \ - (token).data.tag_directive.prefix = (token_prefix)) - /* * Public API declarations. */ @@ -855,11 +615,11 @@ yaml_parser_decrease_flow_level(yaml_parser_t *parser); */ static int -yaml_parser_roll_indent(yaml_parser_t *parser, int column, - int number, yaml_token_type_t type, yaml_mark_t mark); +yaml_parser_roll_indent(yaml_parser_t *parser, ptrdiff_t column, + ptrdiff_t number, yaml_token_type_t type, yaml_mark_t mark); static int -yaml_parser_unroll_indent(yaml_parser_t *parser, int column); +yaml_parser_unroll_indent(yaml_parser_t *parser, ptrdiff_t column); /* * Token fetchers. @@ -984,11 +744,13 @@ yaml_parser_scan(yaml_parser_t *parser, yaml_token_t *token) assert(parser); /* Non-NULL parser object is expected. */ assert(token); /* Non-NULL token object is expected. */ + /* Erase the token object. */ + + memset(token, 0, sizeof(yaml_token_t)); + /* No tokens after STREAM-END or error. */ if (parser->stream_end_produced || parser->error) { - memset(token, 0, sizeof(yaml_token_t)); - return 1; } @@ -1000,7 +762,7 @@ yaml_parser_scan(yaml_parser_t *parser, yaml_token_t *token) } /* Fetch the next token from the queue. */ - + *token = DEQUEUE(parser, parser->tokens); parser->token_available = 0; parser->tokens_parsed ++; @@ -1132,111 +894,113 @@ yaml_parser_fetch_next_token(yaml_parser_t *parser) /* Is it the end of the stream? */ - if (IS_Z(parser)) + if (IS_Z(parser->buffer)) return yaml_parser_fetch_stream_end(parser); /* Is it a directive? */ - if (parser->mark.column == 0 && CHECK(parser, '%')) + if (parser->mark.column == 0 && CHECK(parser->buffer, '%')) return yaml_parser_fetch_directive(parser); /* Is it the document start indicator? */ if (parser->mark.column == 0 - && CHECK_AT(parser, '-', 0) - && CHECK_AT(parser, '-', 1) - && CHECK_AT(parser, '-', 2) - && IS_BLANKZ_AT(parser, 3)) + && CHECK_AT(parser->buffer, '-', 0) + && CHECK_AT(parser->buffer, '-', 1) + && CHECK_AT(parser->buffer, '-', 2) + && IS_BLANKZ_AT(parser->buffer, 3)) return yaml_parser_fetch_document_indicator(parser, YAML_DOCUMENT_START_TOKEN); /* Is it the document end indicator? */ if (parser->mark.column == 0 - && CHECK_AT(parser, '.', 0) - && CHECK_AT(parser, '.', 1) - && CHECK_AT(parser, '.', 2) - && IS_BLANKZ_AT(parser, 3)) + && CHECK_AT(parser->buffer, '.', 0) + && CHECK_AT(parser->buffer, '.', 1) + && CHECK_AT(parser->buffer, '.', 2) + && IS_BLANKZ_AT(parser->buffer, 3)) return yaml_parser_fetch_document_indicator(parser, YAML_DOCUMENT_END_TOKEN); /* Is it the flow sequence start indicator? */ - if (CHECK(parser, '[')) + if (CHECK(parser->buffer, '[')) return yaml_parser_fetch_flow_collection_start(parser, YAML_FLOW_SEQUENCE_START_TOKEN); /* Is it the flow mapping start indicator? */ - if (CHECK(parser, '{')) + if (CHECK(parser->buffer, '{')) return yaml_parser_fetch_flow_collection_start(parser, YAML_FLOW_MAPPING_START_TOKEN); /* Is it the flow sequence end indicator? */ - if (CHECK(parser, ']')) + if (CHECK(parser->buffer, ']')) return yaml_parser_fetch_flow_collection_end(parser, YAML_FLOW_SEQUENCE_END_TOKEN); /* Is it the flow mapping end indicator? */ - if (CHECK(parser, '}')) + if (CHECK(parser->buffer, '}')) return yaml_parser_fetch_flow_collection_end(parser, YAML_FLOW_MAPPING_END_TOKEN); /* Is it the flow entry indicator? */ - if (CHECK(parser, ',')) + if (CHECK(parser->buffer, ',')) return yaml_parser_fetch_flow_entry(parser); /* Is it the block entry indicator? */ - if (CHECK(parser, '-') && IS_BLANKZ_AT(parser, 1)) + if (CHECK(parser->buffer, '-') && IS_BLANKZ_AT(parser->buffer, 1)) return yaml_parser_fetch_block_entry(parser); /* Is it the key indicator? */ - if (CHECK(parser, '?') && (parser->flow_level || IS_BLANKZ_AT(parser, 1))) + if (CHECK(parser->buffer, '?') + && (parser->flow_level || IS_BLANKZ_AT(parser->buffer, 1))) return yaml_parser_fetch_key(parser); /* Is it the value indicator? */ - if (CHECK(parser, ':') && (parser->flow_level || IS_BLANKZ_AT(parser, 1))) + if (CHECK(parser->buffer, ':') + && (parser->flow_level || IS_BLANKZ_AT(parser->buffer, 1))) return yaml_parser_fetch_value(parser); /* Is it an alias? */ - if (CHECK(parser, '*')) + if (CHECK(parser->buffer, '*')) return yaml_parser_fetch_anchor(parser, YAML_ALIAS_TOKEN); /* Is it an anchor? */ - if (CHECK(parser, '&')) + if (CHECK(parser->buffer, '&')) return yaml_parser_fetch_anchor(parser, YAML_ANCHOR_TOKEN); /* Is it a tag? */ - if (CHECK(parser, '!')) + if (CHECK(parser->buffer, '!')) return yaml_parser_fetch_tag(parser); /* Is it a literal scalar? */ - if (CHECK(parser, '|') && !parser->flow_level) + if (CHECK(parser->buffer, '|') && !parser->flow_level) return yaml_parser_fetch_block_scalar(parser, 1); /* Is it a folded scalar? */ - if (CHECK(parser, '>') && !parser->flow_level) + if (CHECK(parser->buffer, '>') && !parser->flow_level) return yaml_parser_fetch_block_scalar(parser, 0); /* Is it a single-quoted scalar? */ - if (CHECK(parser, '\'')) + if (CHECK(parser->buffer, '\'')) return yaml_parser_fetch_flow_scalar(parser, 1); /* Is it a double-quoted scalar? */ - if (CHECK(parser, '"')) + if (CHECK(parser->buffer, '"')) return yaml_parser_fetch_flow_scalar(parser, 0); /* @@ -1258,16 +1022,20 @@ yaml_parser_fetch_next_token(yaml_parser_t *parser) * The last rule is more restrictive than the specification requires. */ - if (!(IS_BLANKZ(parser) || CHECK(parser, '-') || CHECK(parser, '?') - || CHECK(parser, ':') || CHECK(parser, ',') || CHECK(parser, '[') - || CHECK(parser, ']') || CHECK(parser, '{') || CHECK(parser, '}') - || CHECK(parser, '#') || CHECK(parser, '&') || CHECK(parser, '*') - || CHECK(parser, '!') || CHECK(parser, '|') || CHECK(parser, '>') - || CHECK(parser, '\'') || CHECK(parser, '"') || CHECK(parser, '%') - || CHECK(parser, '@') || CHECK(parser, '`')) || - (CHECK(parser, '-') && !IS_BLANK_AT(parser, 1)) || + if (!(IS_BLANKZ(parser->buffer) || CHECK(parser->buffer, '-') + || CHECK(parser->buffer, '?') || CHECK(parser->buffer, ':') + || CHECK(parser->buffer, ',') || CHECK(parser->buffer, '[') + || CHECK(parser->buffer, ']') || CHECK(parser->buffer, '{') + || CHECK(parser->buffer, '}') || CHECK(parser->buffer, '#') + || CHECK(parser->buffer, '&') || CHECK(parser->buffer, '*') + || CHECK(parser->buffer, '!') || CHECK(parser->buffer, '|') + || CHECK(parser->buffer, '>') || CHECK(parser->buffer, '\'') + || CHECK(parser->buffer, '"') || CHECK(parser->buffer, '%') + || CHECK(parser->buffer, '@') || CHECK(parser->buffer, '`')) || + (CHECK(parser->buffer, '-') && !IS_BLANK_AT(parser->buffer, 1)) || (!parser->flow_level && - (CHECK(parser, '?') || CHECK(parser, ':')) && !IS_BLANKZ_AT(parser, 1))) + (CHECK(parser->buffer, '?') || CHECK(parser->buffer, ':')) + && !IS_BLANKZ_AT(parser->buffer, 1))) return yaml_parser_fetch_plain_scalar(parser); /* @@ -1310,7 +1078,7 @@ yaml_parser_stale_simple_keys(yaml_parser_t *parser) if (simple_key->required) { return yaml_parser_set_scanner_error(parser, "while scanning a simple key", simple_key->mark, - "could not found expected ':'"); + "could not find expected ':'"); } simple_key->possible = 0; @@ -1335,14 +1103,7 @@ yaml_parser_save_simple_key(yaml_parser_t *parser) */ int required = (!parser->flow_level - && parser->indent == parser->mark.column); - - /* - * A simple key is required only when it is the first token in the current - * line. Therefore it is always allowed. But we add a check anyway. - */ - - assert(parser->simple_key_allowed || !required); /* Impossible. */ + && parser->indent == (ptrdiff_t)parser->mark.column); /* * If the current position may start a simple key, save it. @@ -1350,9 +1111,12 @@ yaml_parser_save_simple_key(yaml_parser_t *parser) if (parser->simple_key_allowed) { - yaml_simple_key_t simple_key = { 1, required, - parser->tokens_parsed + parser->tokens.tail - parser->tokens.head, - parser->mark }; + yaml_simple_key_t simple_key; + simple_key.possible = 1; + simple_key.required = required; + simple_key.token_number = + parser->tokens_parsed + (parser->tokens.tail - parser->tokens.head); + simple_key.mark = parser->mark; if (!yaml_parser_remove_simple_key(parser)) return 0; @@ -1378,7 +1142,7 @@ yaml_parser_remove_simple_key(yaml_parser_t *parser) if (simple_key->required) { return yaml_parser_set_scanner_error(parser, "while scanning a simple key", simple_key->mark, - "could not found expected ':'"); + "could not find expected ':'"); } } @@ -1405,6 +1169,11 @@ yaml_parser_increase_flow_level(yaml_parser_t *parser) /* Increase the flow level. */ + if (parser->flow_level == INT_MAX) { + parser->error = YAML_MEMORY_ERROR; + return 0; + } + parser->flow_level++; return 1; @@ -1417,9 +1186,11 @@ yaml_parser_increase_flow_level(yaml_parser_t *parser) static int yaml_parser_decrease_flow_level(yaml_parser_t *parser) { + yaml_simple_key_t dummy_key; /* Used to eliminate a compiler warning. */ + if (parser->flow_level) { parser->flow_level --; - POP(parser, parser->simple_keys); + dummy_key = POP(parser, parser->simple_keys); } return 1; @@ -1429,12 +1200,12 @@ yaml_parser_decrease_flow_level(yaml_parser_t *parser) * Push the current indentation level to the stack and set the new level * the current column is greater than the indentation level. In this case, * append or insert the specified token into the token queue. - * + * */ static int -yaml_parser_roll_indent(yaml_parser_t *parser, int column, - int number, yaml_token_type_t type, yaml_mark_t mark) +yaml_parser_roll_indent(yaml_parser_t *parser, ptrdiff_t column, + ptrdiff_t number, yaml_token_type_t type, yaml_mark_t mark) { yaml_token_t token; @@ -1453,6 +1224,11 @@ yaml_parser_roll_indent(yaml_parser_t *parser, int column, if (!PUSH(parser, parser->indents, parser->indent)) return 0; + if (column > INT_MAX) { + parser->error = YAML_MEMORY_ERROR; + return 0; + } + parser->indent = column; /* Create a token and insert it into the queue. */ @@ -1475,13 +1251,13 @@ yaml_parser_roll_indent(yaml_parser_t *parser, int column, /* * Pop indentation levels from the indents stack until the current level - * becomes less or equal to the column. For each intendation level, append + * becomes less or equal to the column. For each indentation level, append * the BLOCK-END token. */ static int -yaml_parser_unroll_indent(yaml_parser_t *parser, int column) +yaml_parser_unroll_indent(yaml_parser_t *parser, ptrdiff_t column) { yaml_token_t token; @@ -1490,7 +1266,7 @@ yaml_parser_unroll_indent(yaml_parser_t *parser, int column) if (parser->flow_level) return 1; - /* Loop through the intendation levels in the stack. */ + /* Loop through the indentation levels in the stack. */ while (parser->indent > column) { @@ -1556,6 +1332,13 @@ yaml_parser_fetch_stream_end(yaml_parser_t *parser) { yaml_token_t token; + /* Force new line. */ + + if (parser->mark.column != 0) { + parser->mark.column = 0; + parser->mark.line ++; + } + /* Reset the indentation level. */ if (!yaml_parser_unroll_indent(parser, -1)) @@ -2145,7 +1928,7 @@ yaml_parser_scan_to_next_token(yaml_parser_t *parser) if (!CACHE(parser, 1)) return 0; - if (parser->mark.column == 0 && IS_BOM(parser)) + if (parser->mark.column == 0 && IS_BOM(parser->buffer)) SKIP(parser); /* @@ -2155,22 +1938,22 @@ yaml_parser_scan_to_next_token(yaml_parser_t *parser) * * - in the flow context; * - in the block context, but not at the beginning of the line or - * after '-', '?', or ':' (complex value). + * after '-', '?', or ':' (complex value). */ if (!CACHE(parser, 1)) return 0; - while (CHECK(parser,' ') || + while (CHECK(parser->buffer,' ') || ((parser->flow_level || !parser->simple_key_allowed) && - CHECK(parser, '\t'))) { + CHECK(parser->buffer, '\t'))) { SKIP(parser); if (!CACHE(parser, 1)) return 0; } /* Eat a comment until a line break. */ - if (CHECK(parser, '#')) { - while (!IS_BREAKZ(parser)) { + if (CHECK(parser->buffer, '#')) { + while (!IS_BREAKZ(parser->buffer)) { SKIP(parser); if (!CACHE(parser, 1)) return 0; } @@ -2178,7 +1961,7 @@ yaml_parser_scan_to_next_token(yaml_parser_t *parser) /* If it is a line break, eat it. */ - if (IS_BREAK(parser)) + if (IS_BREAK(parser->buffer)) { if (!CACHE(parser, 2)) return 0; SKIP_LINE(parser); @@ -2270,7 +2053,7 @@ yaml_parser_scan_directive(yaml_parser_t *parser, yaml_token_t *token) else { yaml_parser_set_scanner_error(parser, "while scanning a directive", - start_mark, "found uknown directive name"); + start_mark, "found unknown directive name"); goto error; } @@ -2278,13 +2061,13 @@ yaml_parser_scan_directive(yaml_parser_t *parser, yaml_token_t *token) if (!CACHE(parser, 1)) goto error; - while (IS_BLANK(parser)) { + while (IS_BLANK(parser->buffer)) { SKIP(parser); if (!CACHE(parser, 1)) goto error; } - if (CHECK(parser, '#')) { - while (!IS_BREAKZ(parser)) { + if (CHECK(parser->buffer, '#')) { + while (!IS_BREAKZ(parser->buffer)) { SKIP(parser); if (!CACHE(parser, 1)) goto error; } @@ -2292,15 +2075,15 @@ yaml_parser_scan_directive(yaml_parser_t *parser, yaml_token_t *token) /* Check if we are at the end of the line. */ - if (!IS_BREAKZ(parser)) { + if (!IS_BREAKZ(parser->buffer)) { yaml_parser_set_scanner_error(parser, "while scanning a directive", - start_mark, "did not found expected comment or line break"); + start_mark, "did not find expected comment or line break"); goto error; } /* Eat a line break. */ - if (IS_BREAK(parser)) { + if (IS_BREAK(parser->buffer)) { if (!CACHE(parser, 2)) goto error; SKIP_LINE(parser); } @@ -2338,7 +2121,7 @@ yaml_parser_scan_directive_name(yaml_parser_t *parser, if (!CACHE(parser, 1)) goto error; - while (IS_ALPHA(parser)) + while (IS_ALPHA(parser->buffer)) { if (!READ(parser, string)) goto error; if (!CACHE(parser, 1)) goto error; @@ -2348,13 +2131,13 @@ yaml_parser_scan_directive_name(yaml_parser_t *parser, if (string.start == string.pointer) { yaml_parser_set_scanner_error(parser, "while scanning a directive", - start_mark, "cannot found expected directive name"); + start_mark, "could not find expected directive name"); goto error; } /* Check for an blank character after the name. */ - if (!IS_BLANKZ(parser)) { + if (!IS_BLANKZ(parser->buffer)) { yaml_parser_set_scanner_error(parser, "while scanning a directive", start_mark, "found unexpected non-alphabetical character"); goto error; @@ -2385,7 +2168,7 @@ yaml_parser_scan_version_directive_value(yaml_parser_t *parser, if (!CACHE(parser, 1)) return 0; - while (IS_BLANK(parser)) { + while (IS_BLANK(parser->buffer)) { SKIP(parser); if (!CACHE(parser, 1)) return 0; } @@ -2397,7 +2180,7 @@ yaml_parser_scan_version_directive_value(yaml_parser_t *parser, /* Eat '.'. */ - if (!CHECK(parser, '.')) { + if (!CHECK(parser->buffer, '.')) { return yaml_parser_set_scanner_error(parser, "while scanning a %YAML directive", start_mark, "did not find expected digit or '.' character"); } @@ -2435,7 +2218,7 @@ yaml_parser_scan_version_directive_number(yaml_parser_t *parser, if (!CACHE(parser, 1)) return 0; - while (IS_DIGIT(parser)) + while (IS_DIGIT(parser->buffer)) { /* Check if the number is too long. */ @@ -2444,7 +2227,7 @@ yaml_parser_scan_version_directive_number(yaml_parser_t *parser, start_mark, "found extremely long version number"); } - value = value*10 + AS_DIGIT(parser); + value = value*10 + AS_DIGIT(parser->buffer); SKIP(parser); @@ -2482,7 +2265,7 @@ yaml_parser_scan_tag_directive_value(yaml_parser_t *parser, if (!CACHE(parser, 1)) goto error; - while (IS_BLANK(parser)) { + while (IS_BLANK(parser->buffer)) { SKIP(parser); if (!CACHE(parser, 1)) goto error; } @@ -2496,7 +2279,7 @@ yaml_parser_scan_tag_directive_value(yaml_parser_t *parser, if (!CACHE(parser, 1)) goto error; - if (!IS_BLANK(parser)) { + if (!IS_BLANK(parser->buffer)) { yaml_parser_set_scanner_error(parser, "while scanning a %TAG directive", start_mark, "did not find expected whitespace"); goto error; @@ -2504,7 +2287,7 @@ yaml_parser_scan_tag_directive_value(yaml_parser_t *parser, /* Eat whitespaces. */ - while (IS_BLANK(parser)) { + while (IS_BLANK(parser->buffer)) { SKIP(parser); if (!CACHE(parser, 1)) goto error; } @@ -2518,7 +2301,7 @@ yaml_parser_scan_tag_directive_value(yaml_parser_t *parser, if (!CACHE(parser, 1)) goto error; - if (!IS_BLANKZ(parser)) { + if (!IS_BLANKZ(parser->buffer)) { yaml_parser_set_scanner_error(parser, "while scanning a %TAG directive", start_mark, "did not find expected whitespace or line break"); goto error; @@ -2555,7 +2338,7 @@ yaml_parser_scan_anchor(yaml_parser_t *parser, yaml_token_t *token, if (!CACHE(parser, 1)) goto error; - while (IS_ALPHA(parser)) { + while (IS_ALPHA(parser->buffer)) { if (!READ(parser, string)) goto error; if (!CACHE(parser, 1)) goto error; length ++; @@ -2570,9 +2353,11 @@ yaml_parser_scan_anchor(yaml_parser_t *parser, yaml_token_t *token, * '?', ':', ',', ']', '}', '%', '@', '`'. */ - if (!length || !(IS_BLANKZ(parser) || CHECK(parser, '?') || CHECK(parser, ':') || - CHECK(parser, ',') || CHECK(parser, ']') || CHECK(parser, '}') || - CHECK(parser, '%') || CHECK(parser, '@') || CHECK(parser, '`'))) { + if (!length || !(IS_BLANKZ(parser->buffer) || CHECK(parser->buffer, '?') + || CHECK(parser->buffer, ':') || CHECK(parser->buffer, ',') + || CHECK(parser->buffer, ']') || CHECK(parser->buffer, '}') + || CHECK(parser->buffer, '%') || CHECK(parser->buffer, '@') + || CHECK(parser->buffer, '`'))) { yaml_parser_set_scanner_error(parser, type == YAML_ANCHOR_TOKEN ? "while scanning an anchor" : "while scanning an alias", start_mark, "did not find expected alphabetic or numeric character"); @@ -2612,7 +2397,7 @@ yaml_parser_scan_tag(yaml_parser_t *parser, yaml_token_t *token) if (!CACHE(parser, 2)) goto error; - if (CHECK_AT(parser, '<', 1)) + if (CHECK_AT(parser->buffer, '<', 1)) { /* Set the handle to '' */ @@ -2632,7 +2417,7 @@ yaml_parser_scan_tag(yaml_parser_t *parser, yaml_token_t *token) /* Check for '>' and eat it. */ - if (!CHECK(parser, '>')) { + if (!CHECK(parser->buffer, '>')) { yaml_parser_set_scanner_error(parser, "while scanning a tag", start_mark, "did not find the expected '>'"); goto error; @@ -2690,9 +2475,9 @@ yaml_parser_scan_tag(yaml_parser_t *parser, yaml_token_t *token) if (!CACHE(parser, 1)) goto error; - if (!IS_BLANKZ(parser)) { + if (!IS_BLANKZ(parser->buffer)) { yaml_parser_set_scanner_error(parser, "while scanning a tag", - start_mark, "did not found expected whitespace or line break"); + start_mark, "did not find expected whitespace or line break"); goto error; } @@ -2726,7 +2511,7 @@ yaml_parser_scan_tag_handle(yaml_parser_t *parser, int directive, if (!CACHE(parser, 1)) goto error; - if (!CHECK(parser, '!')) { + if (!CHECK(parser->buffer, '!')) { yaml_parser_set_scanner_error(parser, directive ? "while scanning a tag directive" : "while scanning a tag", start_mark, "did not find expected '!'"); @@ -2741,7 +2526,7 @@ yaml_parser_scan_tag_handle(yaml_parser_t *parser, int directive, if (!CACHE(parser, 1)) goto error; - while (IS_ALPHA(parser)) + while (IS_ALPHA(parser->buffer)) { if (!READ(parser, string)) goto error; if (!CACHE(parser, 1)) goto error; @@ -2749,7 +2534,7 @@ yaml_parser_scan_tag_handle(yaml_parser_t *parser, int directive, /* Check if the trailing character is '!' and copy it. */ - if (CHECK(parser, '!')) + if (CHECK(parser->buffer, '!')) { if (!READ(parser, string)) goto error; } @@ -2792,7 +2577,7 @@ yaml_parser_scan_tag_uri(yaml_parser_t *parser, int directive, /* Resize the string to include the head. */ - while (string.end - string.start <= length) { + while ((size_t)(string.end - string.start) <= length) { if (!yaml_string_extend(&string.start, &string.pointer, &string.end)) { parser->error = YAML_MEMORY_ERROR; goto error; @@ -2822,17 +2607,24 @@ yaml_parser_scan_tag_uri(yaml_parser_t *parser, int directive, * '%'. */ - while (IS_ALPHA(parser) || CHECK(parser, ';') || CHECK(parser, '/') || - CHECK(parser, '?') || CHECK(parser, ':') || CHECK(parser, '@') || - CHECK(parser, '&') || CHECK(parser, '=') || CHECK(parser, '+') || - CHECK(parser, '$') || CHECK(parser, ',') || CHECK(parser, '.') || - CHECK(parser, '!') || CHECK(parser, '~') || CHECK(parser, '*') || - CHECK(parser, '\'') || CHECK(parser, '(') || CHECK(parser, ')') || - CHECK(parser, '[') || CHECK(parser, ']') || CHECK(parser, '%')) + while (IS_ALPHA(parser->buffer) || CHECK(parser->buffer, ';') + || CHECK(parser->buffer, '/') || CHECK(parser->buffer, '?') + || CHECK(parser->buffer, ':') || CHECK(parser->buffer, '@') + || CHECK(parser->buffer, '&') || CHECK(parser->buffer, '=') + || CHECK(parser->buffer, '+') || CHECK(parser->buffer, '$') + || CHECK(parser->buffer, ',') || CHECK(parser->buffer, '.') + || CHECK(parser->buffer, '!') || CHECK(parser->buffer, '~') + || CHECK(parser->buffer, '*') || CHECK(parser->buffer, '\'') + || CHECK(parser->buffer, '(') || CHECK(parser->buffer, ')') + || CHECK(parser->buffer, '[') || CHECK(parser->buffer, ']') + || CHECK(parser->buffer, '%')) { /* Check if it is a URI-escape sequence. */ - if (CHECK(parser, '%')) { + if (CHECK(parser->buffer, '%')) { + if (!STRING_EXTEND(parser, string)) + goto error; + if (!yaml_parser_scan_uri_escapes(parser, directive, start_mark, &string)) goto error; } @@ -2885,7 +2677,9 @@ yaml_parser_scan_uri_escapes(yaml_parser_t *parser, int directive, if (!CACHE(parser, 3)) return 0; - if (!(CHECK(parser, '%') && IS_HEX_AT(parser, 1) && IS_HEX_AT(parser, 2))) { + if (!(CHECK(parser->buffer, '%') + && IS_HEX_AT(parser->buffer, 1) + && IS_HEX_AT(parser->buffer, 2))) { return yaml_parser_set_scanner_error(parser, directive ? "while parsing a %TAG directive" : "while parsing a tag", start_mark, "did not find URI escaped octet"); @@ -2893,7 +2687,7 @@ yaml_parser_scan_uri_escapes(yaml_parser_t *parser, int directive, /* Get the octet. */ - octet = (AS_HEX_AT(parser, 1) << 4) + AS_HEX_AT(parser, 2); + octet = (AS_HEX_AT(parser->buffer, 1) << 4) + AS_HEX_AT(parser->buffer, 2); /* If it is the leading octet, determine the length of the UTF-8 sequence. */ @@ -2967,11 +2761,11 @@ yaml_parser_scan_block_scalar(yaml_parser_t *parser, yaml_token_t *token, /* Check for a chomping indicator. */ - if (CHECK(parser, '+') || CHECK(parser, '-')) + if (CHECK(parser->buffer, '+') || CHECK(parser->buffer, '-')) { /* Set the chomping method and eat the indicator. */ - chomping = CHECK(parser, '+') ? +1 : -1; + chomping = CHECK(parser->buffer, '+') ? +1 : -1; SKIP(parser); @@ -2979,19 +2773,19 @@ yaml_parser_scan_block_scalar(yaml_parser_t *parser, yaml_token_t *token, if (!CACHE(parser, 1)) goto error; - if (IS_DIGIT(parser)) + if (IS_DIGIT(parser->buffer)) { - /* Check that the intendation is greater than 0. */ + /* Check that the indentation is greater than 0. */ - if (CHECK(parser, '0')) { + if (CHECK(parser->buffer, '0')) { yaml_parser_set_scanner_error(parser, "while scanning a block scalar", - start_mark, "found an intendation indicator equal to 0"); + start_mark, "found an indentation indicator equal to 0"); goto error; } - /* Get the intendation level and eat the indicator. */ + /* Get the indentation level and eat the indicator. */ - increment = AS_DIGIT(parser); + increment = AS_DIGIT(parser->buffer); SKIP(parser); } @@ -2999,22 +2793,22 @@ yaml_parser_scan_block_scalar(yaml_parser_t *parser, yaml_token_t *token, /* Do the same as above, but in the opposite order. */ - else if (IS_DIGIT(parser)) + else if (IS_DIGIT(parser->buffer)) { - if (CHECK(parser, '0')) { + if (CHECK(parser->buffer, '0')) { yaml_parser_set_scanner_error(parser, "while scanning a block scalar", - start_mark, "found an intendation indicator equal to 0"); + start_mark, "found an indentation indicator equal to 0"); goto error; } - increment = AS_DIGIT(parser); + increment = AS_DIGIT(parser->buffer); SKIP(parser); if (!CACHE(parser, 1)) goto error; - if (CHECK(parser, '+') || CHECK(parser, '-')) { - chomping = CHECK(parser, '+') ? +1 : -1; + if (CHECK(parser->buffer, '+') || CHECK(parser->buffer, '-')) { + chomping = CHECK(parser->buffer, '+') ? +1 : -1; SKIP(parser); } @@ -3024,13 +2818,13 @@ yaml_parser_scan_block_scalar(yaml_parser_t *parser, yaml_token_t *token, if (!CACHE(parser, 1)) goto error; - while (IS_BLANK(parser)) { + while (IS_BLANK(parser->buffer)) { SKIP(parser); if (!CACHE(parser, 1)) goto error; } - if (CHECK(parser, '#')) { - while (!IS_BREAKZ(parser)) { + if (CHECK(parser->buffer, '#')) { + while (!IS_BREAKZ(parser->buffer)) { SKIP(parser); if (!CACHE(parser, 1)) goto error; } @@ -3038,22 +2832,22 @@ yaml_parser_scan_block_scalar(yaml_parser_t *parser, yaml_token_t *token, /* Check if we are at the end of the line. */ - if (!IS_BREAKZ(parser)) { + if (!IS_BREAKZ(parser->buffer)) { yaml_parser_set_scanner_error(parser, "while scanning a block scalar", - start_mark, "did not found expected comment or line break"); + start_mark, "did not find expected comment or line break"); goto error; } /* Eat a line break. */ - if (IS_BREAK(parser)) { + if (IS_BREAK(parser->buffer)) { if (!CACHE(parser, 2)) goto error; SKIP_LINE(parser); } end_mark = parser->mark; - /* Set the intendation level if it was specified. */ + /* Set the indentation level if it was specified. */ if (increment) { indent = parser->indent >= 0 ? parser->indent+increment : increment; @@ -3068,7 +2862,7 @@ yaml_parser_scan_block_scalar(yaml_parser_t *parser, yaml_token_t *token, if (!CACHE(parser, 1)) goto error; - while (parser->mark.column == indent && !IS_Z(parser)) + while ((int)parser->mark.column == indent && !IS_Z(parser->buffer)) { /* * We are at the beginning of a non-empty line. @@ -3076,7 +2870,7 @@ yaml_parser_scan_block_scalar(yaml_parser_t *parser, yaml_token_t *token, /* Is it a trailing whitespace? */ - trailing_blank = IS_BLANK(parser); + trailing_blank = IS_BLANK(parser->buffer); /* Check if we need to fold the leading line break. */ @@ -3104,11 +2898,11 @@ yaml_parser_scan_block_scalar(yaml_parser_t *parser, yaml_token_t *token, /* Is it a leading whitespace? */ - leading_blank = IS_BLANK(parser); + leading_blank = IS_BLANK(parser->buffer); /* Consume the current line. */ - while (!IS_BREAKZ(parser)) { + while (!IS_BREAKZ(parser->buffer)) { if (!READ(parser, string)) goto error; if (!CACHE(parser, 1)) goto error; } @@ -3119,7 +2913,7 @@ yaml_parser_scan_block_scalar(yaml_parser_t *parser, yaml_token_t *token, if (!READ_LINE(parser, leading_break)) goto error; - /* Eat the following intendation spaces and line breaks. */ + /* Eat the following indentation spaces and line breaks. */ if (!yaml_parser_scan_block_scalar_breaks(parser, &indent, &trailing_breaks, start_mark, &end_mark)) goto error; @@ -3154,8 +2948,8 @@ error: } /* - * Scan intendation spaces and line breaks for a block scalar. Determine the - * intendation level if needed. + * Scan indentation spaces and line breaks for a block scalar. Determine the + * indentation level if needed. */ static int @@ -3167,32 +2961,34 @@ yaml_parser_scan_block_scalar_breaks(yaml_parser_t *parser, *end_mark = parser->mark; - /* Eat the intendation spaces and line breaks. */ + /* Eat the indentation spaces and line breaks. */ while (1) { - /* Eat the intendation spaces. */ + /* Eat the indentation spaces. */ if (!CACHE(parser, 1)) return 0; - while ((!*indent || parser->mark.column < *indent) && IS_SPACE(parser)) { + while ((!*indent || (int)parser->mark.column < *indent) + && IS_SPACE(parser->buffer)) { SKIP(parser); if (!CACHE(parser, 1)) return 0; } - if (parser->mark.column > max_indent) - max_indent = parser->mark.column; + if ((int)parser->mark.column > max_indent) + max_indent = (int)parser->mark.column; - /* Check for a tab character messing the intendation. */ + /* Check for a tab character messing the indentation. */ - if ((!*indent || parser->mark.column < *indent) && IS_TAB(parser)) { + if ((!*indent || (int)parser->mark.column < *indent) + && IS_TAB(parser->buffer)) { return yaml_parser_set_scanner_error(parser, "while scanning a block scalar", - start_mark, "found a tab character where an intendation space is expected"); + start_mark, "found a tab character where an indentation space is expected"); } /* Have we found a non-empty line? */ - if (!IS_BREAK(parser)) break; + if (!IS_BREAK(parser->buffer)) break; /* Consume the line break. */ @@ -3211,7 +3007,7 @@ yaml_parser_scan_block_scalar_breaks(yaml_parser_t *parser, *indent = 1; } - return 1; + return 1; } /* @@ -3250,13 +3046,13 @@ yaml_parser_scan_flow_scalar(yaml_parser_t *parser, yaml_token_t *token, if (!CACHE(parser, 4)) goto error; if (parser->mark.column == 0 && - ((CHECK_AT(parser, '-', 0) && - CHECK_AT(parser, '-', 1) && - CHECK_AT(parser, '-', 2)) || - (CHECK_AT(parser, '.', 0) && - CHECK_AT(parser, '.', 1) && - CHECK_AT(parser, '.', 2))) && - IS_BLANKZ_AT(parser, 3)) + ((CHECK_AT(parser->buffer, '-', 0) && + CHECK_AT(parser->buffer, '-', 1) && + CHECK_AT(parser->buffer, '-', 2)) || + (CHECK_AT(parser->buffer, '.', 0) && + CHECK_AT(parser->buffer, '.', 1) && + CHECK_AT(parser->buffer, '.', 2))) && + IS_BLANKZ_AT(parser->buffer, 3)) { yaml_parser_set_scanner_error(parser, "while scanning a quoted scalar", start_mark, "found unexpected document indicator"); @@ -3265,7 +3061,7 @@ yaml_parser_scan_flow_scalar(yaml_parser_t *parser, yaml_token_t *token, /* Check for EOF. */ - if (IS_Z(parser)) { + if (IS_Z(parser->buffer)) { yaml_parser_set_scanner_error(parser, "while scanning a quoted scalar", start_mark, "found unexpected end of stream"); goto error; @@ -3277,11 +3073,12 @@ yaml_parser_scan_flow_scalar(yaml_parser_t *parser, yaml_token_t *token, leading_blanks = 0; - while (!IS_BLANKZ(parser)) + while (!IS_BLANKZ(parser->buffer)) { /* Check for an escaped single quote. */ - if (single && CHECK_AT(parser, '\'', 0) && CHECK_AT(parser, '\'', 1)) + if (single && CHECK_AT(parser->buffer, '\'', 0) + && CHECK_AT(parser->buffer, '\'', 1)) { if (!STRING_EXTEND(parser, string)) goto error; *(string.pointer++) = '\''; @@ -3291,14 +3088,15 @@ yaml_parser_scan_flow_scalar(yaml_parser_t *parser, yaml_token_t *token, /* Check for the right quote. */ - else if (CHECK(parser, single ? '\'' : '"')) + else if (CHECK(parser->buffer, single ? '\'' : '"')) { break; } /* Check for an escaped line break. */ - else if (!single && CHECK(parser, '\\') && IS_BREAK_AT(parser, 1)) + else if (!single && CHECK(parser->buffer, '\\') + && IS_BREAK_AT(parser->buffer, 1)) { if (!CACHE(parser, 3)) goto error; SKIP(parser); @@ -3309,9 +3107,9 @@ yaml_parser_scan_flow_scalar(yaml_parser_t *parser, yaml_token_t *token, /* Check for an escape sequence. */ - else if (!single && CHECK(parser, '\\')) + else if (!single && CHECK(parser->buffer, '\\')) { - int code_length = 0; + size_t code_length = 0; if (!STRING_EXTEND(parser, string)) goto error; @@ -3364,6 +3162,10 @@ yaml_parser_scan_flow_scalar(yaml_parser_t *parser, yaml_token_t *token, *(string.pointer++) = '"'; break; + case '/': + *(string.pointer++) = '/'; + break; + case '\'': *(string.pointer++) = '\''; break; @@ -3420,19 +3222,19 @@ yaml_parser_scan_flow_scalar(yaml_parser_t *parser, yaml_token_t *token, if (code_length) { unsigned int value = 0; - int k; + size_t k; /* Scan the character value. */ if (!CACHE(parser, code_length)) goto error; for (k = 0; k < code_length; k ++) { - if (!IS_HEX_AT(parser, k)) { + if (!IS_HEX_AT(parser->buffer, k)) { yaml_parser_set_scanner_error(parser, "while parsing a quoted scalar", start_mark, "did not find expected hexdecimal number"); goto error; } - value = (value << 4) + AS_HEX_AT(parser, k); + value = (value << 4) + AS_HEX_AT(parser->buffer, k); } /* Check the value and write the character. */ @@ -3482,16 +3284,16 @@ yaml_parser_scan_flow_scalar(yaml_parser_t *parser, yaml_token_t *token, /* Check if we are at the end of the scalar. */ - if (CHECK(parser, single ? '\'' : '"')) + if (CHECK(parser->buffer, single ? '\'' : '"')) break; /* Consume blank characters. */ if (!CACHE(parser, 1)) goto error; - while (IS_BLANK(parser) || IS_BREAK(parser)) + while (IS_BLANK(parser->buffer) || IS_BREAK(parser->buffer)) { - if (IS_BLANK(parser)) + if (IS_BLANK(parser->buffer)) { /* Consume a space or a tab character. */ @@ -3612,26 +3414,28 @@ yaml_parser_scan_plain_scalar(yaml_parser_t *parser, yaml_token_t *token) if (!CACHE(parser, 4)) goto error; if (parser->mark.column == 0 && - ((CHECK_AT(parser, '-', 0) && - CHECK_AT(parser, '-', 1) && - CHECK_AT(parser, '-', 2)) || - (CHECK_AT(parser, '.', 0) && - CHECK_AT(parser, '.', 1) && - CHECK_AT(parser, '.', 2))) && - IS_BLANKZ_AT(parser, 3)) break; + ((CHECK_AT(parser->buffer, '-', 0) && + CHECK_AT(parser->buffer, '-', 1) && + CHECK_AT(parser->buffer, '-', 2)) || + (CHECK_AT(parser->buffer, '.', 0) && + CHECK_AT(parser->buffer, '.', 1) && + CHECK_AT(parser->buffer, '.', 2))) && + IS_BLANKZ_AT(parser->buffer, 3)) break; /* Check for a comment. */ - if (CHECK(parser, '#')) + if (CHECK(parser->buffer, '#')) break; /* Consume non-blank characters. */ - while (!IS_BLANKZ(parser)) + while (!IS_BLANKZ(parser->buffer)) { /* Check for 'x:x' in the flow context. TODO: Fix the test "spec-08-13". */ - if (parser->flow_level && CHECK(parser, ':') && !IS_BLANKZ_AT(parser, 1)) { + if (parser->flow_level + && CHECK(parser->buffer, ':') + && !IS_BLANKZ_AT(parser->buffer, 1)) { yaml_parser_set_scanner_error(parser, "while scanning a plain scalar", start_mark, "found unexpected ':'"); goto error; @@ -3639,12 +3443,12 @@ yaml_parser_scan_plain_scalar(yaml_parser_t *parser, yaml_token_t *token) /* Check for indicators that may end a plain scalar. */ - if ((CHECK(parser, ':') && IS_BLANKZ_AT(parser, 1)) || - (parser->flow_level && - (CHECK(parser, ',') || CHECK(parser, ':') || - CHECK(parser, '?') || CHECK(parser, '[') || - CHECK(parser, ']') || CHECK(parser, '{') || - CHECK(parser, '}')))) + if ((CHECK(parser->buffer, ':') && IS_BLANKZ_AT(parser->buffer, 1)) + || (parser->flow_level && + (CHECK(parser->buffer, ',') || CHECK(parser->buffer, ':') + || CHECK(parser->buffer, '?') || CHECK(parser->buffer, '[') + || CHECK(parser->buffer, ']') || CHECK(parser->buffer, '{') + || CHECK(parser->buffer, '}')))) break; /* Check if we need to join whitespaces and breaks. */ @@ -3693,22 +3497,23 @@ yaml_parser_scan_plain_scalar(yaml_parser_t *parser, yaml_token_t *token) /* Is it the end? */ - if (!(IS_BLANK(parser) || IS_BREAK(parser))) + if (!(IS_BLANK(parser->buffer) || IS_BREAK(parser->buffer))) break; /* Consume blank characters. */ if (!CACHE(parser, 1)) goto error; - while (IS_BLANK(parser) || IS_BREAK(parser)) + while (IS_BLANK(parser->buffer) || IS_BREAK(parser->buffer)) { - if (IS_BLANK(parser)) + if (IS_BLANK(parser->buffer)) { - /* Check for tab character that abuse intendation. */ + /* Check for tab character that abuse indentation. */ - if (leading_blanks && parser->mark.column < indent && IS_TAB(parser)) { + if (leading_blanks && (int)parser->mark.column < indent + && IS_TAB(parser->buffer)) { yaml_parser_set_scanner_error(parser, "while scanning a plain scalar", - start_mark, "found a tab character that violate intendation"); + start_mark, "found a tab character that violate indentation"); goto error; } @@ -3741,9 +3546,9 @@ yaml_parser_scan_plain_scalar(yaml_parser_t *parser, yaml_token_t *token) if (!CACHE(parser, 1)) goto error; } - /* Check intendation level. */ + /* Check indentation level. */ - if (!parser->flow_level && parser->mark.column < indent) + if (!parser->flow_level && (int)parser->mark.column < indent) break; } @@ -3772,4 +3577,3 @@ error: return 0; } -