| 1 | |
|---|
| 2 | #if HAVE_CONFIG_H |
|---|
| 3 | #include <config.h> |
|---|
| 4 | #endif |
|---|
| 5 | |
|---|
| 6 | #include <yaml.h> |
|---|
| 7 | |
|---|
| 8 | #include <assert.h> |
|---|
| 9 | #include <limits.h> |
|---|
| 10 | |
|---|
| 11 | /* |
|---|
| 12 | * Memory management. |
|---|
| 13 | */ |
|---|
| 14 | |
|---|
| 15 | YAML_DECLARE(void *) |
|---|
| 16 | yaml_malloc(size_t size); |
|---|
| 17 | |
|---|
| 18 | YAML_DECLARE(void *) |
|---|
| 19 | yaml_realloc(void *ptr, size_t size); |
|---|
| 20 | |
|---|
| 21 | YAML_DECLARE(void) |
|---|
| 22 | yaml_free(void *ptr); |
|---|
| 23 | |
|---|
| 24 | YAML_DECLARE(yaml_char_t *) |
|---|
| 25 | yaml_strdup(const yaml_char_t *); |
|---|
| 26 | |
|---|
| 27 | /* |
|---|
| 28 | * Error management. |
|---|
| 29 | */ |
|---|
| 30 | |
|---|
| 31 | /* |
|---|
| 32 | * Generic error initializers; not to be used directly. |
|---|
| 33 | */ |
|---|
| 34 | |
|---|
| 35 | #define ERROR_INIT(error, _type) \ |
|---|
| 36 | (memset(&(error), 0, sizeof(yaml_error_t)), \ |
|---|
| 37 | (error).type = (_type), \ |
|---|
| 38 | 0) |
|---|
| 39 | |
|---|
| 40 | #define READING_ERROR_INIT(error, _type, _problem, _offset, _value) \ |
|---|
| 41 | (ERROR_INIT(error, _type), \ |
|---|
| 42 | (error).data.reading.problem = (_problem), \ |
|---|
| 43 | (error).data.reading.offset = (_offset), \ |
|---|
| 44 | (error).data.reading.value = (_value), \ |
|---|
| 45 | 0) |
|---|
| 46 | |
|---|
| 47 | #define LOADING_ERROR_INIT(error, _type, _problem, _problem_mark) \ |
|---|
| 48 | (ERROR_INIT(error, _type), \ |
|---|
| 49 | (error).data.loading.context = NULL, \ |
|---|
| 50 | (error).data.loading.context_mark.index = 0, \ |
|---|
| 51 | (error).data.loading.context_mark.line = 0, \ |
|---|
| 52 | (error).data.loading.context_mark.column = 0, \ |
|---|
| 53 | (error).data.loading.problem = (_problem), \ |
|---|
| 54 | (error).data.loading.problem_mark = (_problem_mark), \ |
|---|
| 55 | 0) |
|---|
| 56 | |
|---|
| 57 | #define LOADING_ERROR_WITH_CONTEXT_INIT(error, _type, _context, _context_mark, \ |
|---|
| 58 | _problem, _problem_mark) \ |
|---|
| 59 | (ERROR_INIT(error, _type), \ |
|---|
| 60 | (error).data.loading.context = (_context), \ |
|---|
| 61 | (error).data.loading.context_mark = (_context_mark), \ |
|---|
| 62 | (error).data.loading.problem = (_problem), \ |
|---|
| 63 | (error).data.loading.problem_mark = (_problem_mark), \ |
|---|
| 64 | 0) |
|---|
| 65 | |
|---|
| 66 | #define WRITING_ERROR_INIT(error, _type, _problem, _offset) \ |
|---|
| 67 | (ERROR_INIT(error, _type), \ |
|---|
| 68 | (error).data.writing.problem = (_problem), \ |
|---|
| 69 | (error).data.writing.offset = (_offset), \ |
|---|
| 70 | 0) |
|---|
| 71 | |
|---|
| 72 | #define DUMPING_ERROR_INIT(error, _type, _problem) \ |
|---|
| 73 | (ERROR_INIT(error, _type), \ |
|---|
| 74 | (error).data.dumping.problem = (_problem), \ |
|---|
| 75 | 0) |
|---|
| 76 | |
|---|
| 77 | #define RESOLVING_ERROR_INIT(error, _type, _problem) \ |
|---|
| 78 | (ERROR_INIT(error, _type), \ |
|---|
| 79 | (error).data.resolving.problem = (_problem), \ |
|---|
| 80 | 0) |
|---|
| 81 | |
|---|
| 82 | /* |
|---|
| 83 | * Specific error initializers. |
|---|
| 84 | */ |
|---|
| 85 | |
|---|
| 86 | #define MEMORY_ERROR_INIT(self) \ |
|---|
| 87 | ERROR_INIT((self)->error, YAML_MEMORY_ERROR) |
|---|
| 88 | |
|---|
| 89 | #define READER_ERROR_INIT(self, _problem, _offset) \ |
|---|
| 90 | READING_ERROR_INIT((self)->error, YAML_READER_ERROR, _problem, _offset, -1) |
|---|
| 91 | |
|---|
| 92 | #define DECODER_ERROR_INIT(self, _problem, _offset, _value) \ |
|---|
| 93 | READING_ERROR_INIT((self)->error, YAML_DECODER_ERROR, _problem, _offset, _value) |
|---|
| 94 | |
|---|
| 95 | #define SCANNER_ERROR_INIT(self, _problem, _problem_mark) \ |
|---|
| 96 | LOADING_ERROR_INIT((self)->error, YAML_SCANNER_ERROR, _problem, _problem_mark) |
|---|
| 97 | |
|---|
| 98 | #define SCANNER_ERROR_WITH_CONTEXT_INIT(self, _context, _context_mark, \ |
|---|
| 99 | _problem, _problem_mark) \ |
|---|
| 100 | LOADING_ERROR_WITH_CONTEXT_INIT((self)->error, YAML_SCANNER_ERROR, \ |
|---|
| 101 | _context, _context_mark, _problem, _problem_mark) |
|---|
| 102 | |
|---|
| 103 | #define PARSER_ERROR_INIT(self, _problem, _problem_mark) \ |
|---|
| 104 | LOADING_ERROR_INIT((self)->error, YAML_PARSER_ERROR, _problem, _problem_mark) |
|---|
| 105 | |
|---|
| 106 | #define PARSER_ERROR_WITH_CONTEXT_INIT(self, _context, _context_mark, \ |
|---|
| 107 | _problem, _problem_mark) \ |
|---|
| 108 | LOADING_ERROR_WITH_CONTEXT_INIT((self)->error, YAML_PARSER_ERROR, \ |
|---|
| 109 | _context, _context_mark, _problem, _problem_mark) |
|---|
| 110 | |
|---|
| 111 | #define COMPOSER_ERROR_INIT(self, _problem, _problem_mark) \ |
|---|
| 112 | LOADING_ERROR_INIT((self)->error, YAML_COMPOSER_ERROR, _problem, _problem_mark) |
|---|
| 113 | |
|---|
| 114 | #define COMPOSER_ERROR_WITH_CONTEXT_INIT(self, _context, _context_mark, \ |
|---|
| 115 | _problem, _problem_mark) \ |
|---|
| 116 | LOADING_ERROR_WITH_CONTEXT_INIT((self)->error, YAML_COMPOSER_ERROR, \ |
|---|
| 117 | _context, _context_mark, _problem, _problem_mark) |
|---|
| 118 | |
|---|
| 119 | #define WRITER_ERROR_INIT(self, _problem, _offset) \ |
|---|
| 120 | WRITING_ERROR_INIT((self)->error, YAML_WRITER_ERROR, _problem, _offset) |
|---|
| 121 | |
|---|
| 122 | #define EMITTER_ERROR_INIT(self, _problem) \ |
|---|
| 123 | DUMPING_ERROR_INIT((self)->error, YAML_EMITTER_ERROR, _problem) |
|---|
| 124 | |
|---|
| 125 | #define SERIALIZER_ERROR_INIT(self, _problem) \ |
|---|
| 126 | DUMPING_ERROR_INIT((self)->error, YAML_SERIALIZER_ERROR, _problem) |
|---|
| 127 | |
|---|
| 128 | #define RESOLVER_ERROR_INIT(self, _problem) \ |
|---|
| 129 | RESOLVER_ERROR_INIT((self)->error, YAML_RESOLVER_ERROR, _problem) |
|---|
| 130 | |
|---|
| 131 | /* |
|---|
| 132 | * The size of the input raw buffer. |
|---|
| 133 | */ |
|---|
| 134 | |
|---|
| 135 | #define RAW_INPUT_BUFFER_CAPACITY 16384 |
|---|
| 136 | |
|---|
| 137 | /* |
|---|
| 138 | * The size of the input buffer. |
|---|
| 139 | * |
|---|
| 140 | * The input buffer should be large enough to hold the content of the raw |
|---|
| 141 | * buffer after it is decoded. |
|---|
| 142 | */ |
|---|
| 143 | |
|---|
| 144 | #define INPUT_BUFFER_CAPACITY (RAW_INPUT_BUFFER_CAPACITY*3) |
|---|
| 145 | |
|---|
| 146 | /* |
|---|
| 147 | * The size of the output buffer. |
|---|
| 148 | */ |
|---|
| 149 | |
|---|
| 150 | #define OUTPUT_BUFFER_CAPACITY 16384 |
|---|
| 151 | |
|---|
| 152 | /* |
|---|
| 153 | * The size of the output raw buffer. |
|---|
| 154 | * |
|---|
| 155 | * The raw buffer should be able to hold the content of the output buffer |
|---|
| 156 | * after it is encoded. |
|---|
| 157 | */ |
|---|
| 158 | |
|---|
| 159 | #define RAW_OUTPUT_BUFFER_CAPACITY (OUTPUT_BUFFER_CAPACITY*2+2) |
|---|
| 160 | |
|---|
| 161 | /* |
|---|
| 162 | * The size of other stacks and queues. |
|---|
| 163 | */ |
|---|
| 164 | |
|---|
| 165 | #define INITIAL_STACK_CAPACITY 16 |
|---|
| 166 | #define INITIAL_QUEUE_CAPACITY 16 |
|---|
| 167 | #define INITIAL_STRING_CAPACITY 16 |
|---|
| 168 | |
|---|
| 169 | /* |
|---|
| 170 | * String management. |
|---|
| 171 | */ |
|---|
| 172 | |
|---|
| 173 | /* |
|---|
| 174 | * An immutable string used as an input buffer. |
|---|
| 175 | */ |
|---|
| 176 | |
|---|
| 177 | typedef struct yaml_istring_s { |
|---|
| 178 | const yaml_char_t *buffer; |
|---|
| 179 | size_t pointer; |
|---|
| 180 | size_t length; |
|---|
| 181 | } yaml_istring_t; |
|---|
| 182 | |
|---|
| 183 | /* |
|---|
| 184 | * A string that is used as an output buffer. |
|---|
| 185 | */ |
|---|
| 186 | |
|---|
| 187 | typedef struct yaml_ostring_s { |
|---|
| 188 | yaml_char_t *buffer; |
|---|
| 189 | size_t pointer; |
|---|
| 190 | size_t capacity; |
|---|
| 191 | } yaml_ostring_t; |
|---|
| 192 | |
|---|
| 193 | /* |
|---|
| 194 | * A string that could be used both as an input and an output buffer. |
|---|
| 195 | */ |
|---|
| 196 | |
|---|
| 197 | typedef struct yaml_iostring_s { |
|---|
| 198 | yaml_char_t *buffer; |
|---|
| 199 | size_t pointer; |
|---|
| 200 | size_t length; |
|---|
| 201 | size_t capacity; |
|---|
| 202 | } yaml_iostring_t; |
|---|
| 203 | |
|---|
| 204 | /* |
|---|
| 205 | * Separate type for non-UTF-8 i/o strings. |
|---|
| 206 | */ |
|---|
| 207 | |
|---|
| 208 | typedef struct yaml_raw_iostring_s { |
|---|
| 209 | unsigned char *buffer; |
|---|
| 210 | size_t pointer; |
|---|
| 211 | size_t length; |
|---|
| 212 | size_t capacity; |
|---|
| 213 | } yaml_raw_iostring_t; |
|---|
| 214 | |
|---|
| 215 | YAML_DECLARE(int) |
|---|
| 216 | yaml_ostring_extend(yaml_char_t **buffer, size_t *capacity); |
|---|
| 217 | |
|---|
| 218 | YAML_DECLARE(int) |
|---|
| 219 | yaml_ostring_join( |
|---|
| 220 | yaml_char_t **base_buffer, size_t *base_pointer, size_t *base_capacity, |
|---|
| 221 | yaml_char_t *adj_buffer, size_t adj_pointer); |
|---|
| 222 | |
|---|
| 223 | #define ISTRING(buffer, length) { (buffer), 0, (length) } |
|---|
| 224 | |
|---|
| 225 | #define NULL_OSTRING { NULL, 0, 0 } |
|---|
| 226 | |
|---|
| 227 | #define IOSTRING_INIT(self, string, _capacity) \ |
|---|
| 228 | (((string).buffer = yaml_malloc(_capacity)) ? \ |
|---|
| 229 | ((string).pointer = (string).length = 0, \ |
|---|
| 230 | (string).capacity = (_capacity), \ |
|---|
| 231 | memset((string).buffer, 0, (_capacity)), \ |
|---|
| 232 | 1) : \ |
|---|
| 233 | ((self)->error.type = YAML_MEMORY_ERROR, \ |
|---|
| 234 | 0)) |
|---|
| 235 | |
|---|
| 236 | #define IOSTRING_DEL(self, string) \ |
|---|
| 237 | (yaml_free((string).buffer), \ |
|---|
| 238 | (string).buffer = NULL, \ |
|---|
| 239 | ((string).pointer = (string).length = (string).capacity = 0)) |
|---|
| 240 | |
|---|
| 241 | #define OSTRING_INIT(self, string, _capacity) \ |
|---|
| 242 | (((string).buffer = yaml_malloc(_capacity)) ? \ |
|---|
| 243 | ((string).pointer = 0, \ |
|---|
| 244 | (string).capacity = (_capacity), \ |
|---|
| 245 | memset((string).buffer, 0, (_capacity)), \ |
|---|
| 246 | 1) : \ |
|---|
| 247 | ((self)->error.type = YAML_MEMORY_ERROR, \ |
|---|
| 248 | 0)) |
|---|
| 249 | |
|---|
| 250 | #define OSTRING_DEL(self, string) \ |
|---|
| 251 | (yaml_free((string).buffer), \ |
|---|
| 252 | (string).buffer = NULL, \ |
|---|
| 253 | ((string).pointer = (string).capacity = 0)) |
|---|
| 254 | |
|---|
| 255 | #define OSTRING_EXTEND(self, string) \ |
|---|
| 256 | ((((string).pointer+5 < (string).capacity) \ |
|---|
| 257 | || yaml_ostring_extend(&(string).buffer, &(string).capacity)) ? \ |
|---|
| 258 | 1 : \ |
|---|
| 259 | ((self)->error.type = YAML_MEMORY_ERROR, \ |
|---|
| 260 | 0)) |
|---|
| 261 | |
|---|
| 262 | #define CLEAR(self, string) \ |
|---|
| 263 | ((string).pointer = 0, \ |
|---|
| 264 | memset((string).buffer, 0, (string).capacity)) |
|---|
| 265 | |
|---|
| 266 | #define JOIN(self, base_string, adj_string) \ |
|---|
| 267 | ((yaml_ostring_join(&(base_string).buffer, &(base_string).pointer, \ |
|---|
| 268 | &(base_string).capacity, \ |
|---|
| 269 | (adj_string).buffer, (adj_string).pointer)) ? \ |
|---|
| 270 | ((adj_string).pointer = 0, \ |
|---|
| 271 | 1) : \ |
|---|
| 272 | ((self)->error.type = YAML_MEMORY_ERROR, \ |
|---|
| 273 | 0)) |
|---|
| 274 | |
|---|
| 275 | /* |
|---|
| 276 | * String check operations. |
|---|
| 277 | */ |
|---|
| 278 | |
|---|
| 279 | /* |
|---|
| 280 | * Get the octet at the specified position. |
|---|
| 281 | */ |
|---|
| 282 | |
|---|
| 283 | #define OCTET_AT(string, offset) \ |
|---|
| 284 | ((string).buffer[(string).pointer+(offset)]) |
|---|
| 285 | |
|---|
| 286 | /* |
|---|
| 287 | * Get the current offset. |
|---|
| 288 | */ |
|---|
| 289 | |
|---|
| 290 | #define OCTET(string) OCTET_AT((string), 0) |
|---|
| 291 | |
|---|
| 292 | /* |
|---|
| 293 | * Check the octet at the specified position. |
|---|
| 294 | */ |
|---|
| 295 | |
|---|
| 296 | #define CHECK_AT(string, octet, offset) \ |
|---|
| 297 | (OCTET_AT((string), (offset)) == (yaml_char_t)(octet)) |
|---|
| 298 | |
|---|
| 299 | /* |
|---|
| 300 | * Check the current octet in the buffer. |
|---|
| 301 | */ |
|---|
| 302 | |
|---|
| 303 | #define CHECK(string, octet) CHECK_AT((string), (octet), 0) |
|---|
| 304 | |
|---|
| 305 | /* |
|---|
| 306 | * Check if the character at the specified position is an alphabetical |
|---|
| 307 | * character, a digit, '_', or '-'. |
|---|
| 308 | */ |
|---|
| 309 | |
|---|
| 310 | #define IS_ALPHA_AT(string, offset) \ |
|---|
| 311 | ((OCTET_AT((string), (offset)) >= (yaml_char_t) '0' && \ |
|---|
| 312 | OCTET_AT((string), (offset)) <= (yaml_char_t) '9') || \ |
|---|
| 313 | (OCTET_AT((string), (offset)) >= (yaml_char_t) 'A' && \ |
|---|
| 314 | OCTET_AT((string), (offset)) <= (yaml_char_t) 'Z') || \ |
|---|
| 315 | (OCTET_AT((string), (offset)) >= (yaml_char_t) 'a' && \ |
|---|
| 316 | OCTET_AT((string), (offset)) <= (yaml_char_t) 'z') || \ |
|---|
| 317 | OCTET_AT((string), (offset)) == '_' || \ |
|---|
| 318 | OCTET_AT((string), (offset)) == '-') |
|---|
| 319 | |
|---|
| 320 | #define IS_ALPHA(string) IS_ALPHA_AT((string), 0) |
|---|
| 321 | |
|---|
| 322 | /* |
|---|
| 323 | * Check if the character at the specified position is a digit. |
|---|
| 324 | */ |
|---|
| 325 | |
|---|
| 326 | #define IS_DIGIT_AT(string, offset) \ |
|---|
| 327 | ((OCTET_AT((string), (offset)) >= (yaml_char_t) '0' && \ |
|---|
| 328 | OCTET_AT((string), (offset)) <= (yaml_char_t) '9')) |
|---|
| 329 | |
|---|
| 330 | #define IS_DIGIT(string) IS_DIGIT_AT((string), 0) |
|---|
| 331 | |
|---|
| 332 | /* |
|---|
| 333 | * Get the value of a digit. |
|---|
| 334 | */ |
|---|
| 335 | |
|---|
| 336 | #define AS_DIGIT_AT(string, offset) \ |
|---|
| 337 | (OCTET_AT((string), (offset)) - (yaml_char_t) '0') |
|---|
| 338 | |
|---|
| 339 | #define AS_DIGIT(string) AS_DIGIT_AT((string), 0) |
|---|
| 340 | |
|---|
| 341 | /* |
|---|
| 342 | * Check if the character at the specified position is a hex-digit. |
|---|
| 343 | */ |
|---|
| 344 | |
|---|
| 345 | #define IS_HEX_AT(string, offset) \ |
|---|
| 346 | ((OCTET_AT((string), (offset)) >= (yaml_char_t) '0' && \ |
|---|
| 347 | OCTET_AT((string), (offset)) <= (yaml_char_t) '9') || \ |
|---|
| 348 | (OCTET_AT((string), (offset)) >= (yaml_char_t) 'A' && \ |
|---|
| 349 | OCTET_AT((string), (offset)) <= (yaml_char_t) 'F') || \ |
|---|
| 350 | (OCTET_AT((string), (offset)) >= (yaml_char_t) 'a' && \ |
|---|
| 351 | OCTET_AT((string), (offset)) <= (yaml_char_t) 'f')) |
|---|
| 352 | |
|---|
| 353 | #define IS_HEX(string) IS_HEX_AT((string), 0) |
|---|
| 354 | |
|---|
| 355 | /* |
|---|
| 356 | * Get the value of a hex-digit. |
|---|
| 357 | */ |
|---|
| 358 | |
|---|
| 359 | #define AS_HEX_AT(string, offset) \ |
|---|
| 360 | ((OCTET_AT((string), (offset)) >= (yaml_char_t) 'A' && \ |
|---|
| 361 | OCTET_AT((string), (offset)) <= (yaml_char_t) 'F') ? \ |
|---|
| 362 | (OCTET_AT((string), (offset)) - (yaml_char_t) 'A' + 10) : \ |
|---|
| 363 | (OCTET_AT((string), (offset)) >= (yaml_char_t) 'a' && \ |
|---|
| 364 | OCTET_AT((string), (offset)) <= (yaml_char_t) 'f') ? \ |
|---|
| 365 | (OCTET_AT((string), (offset)) - (yaml_char_t) 'a' + 10) : \ |
|---|
| 366 | (OCTET_AT((string), (offset)) - (yaml_char_t) '0')) |
|---|
| 367 | |
|---|
| 368 | #define AS_HEX(string) AS_HEX_AT((string), 0) |
|---|
| 369 | |
|---|
| 370 | /* |
|---|
| 371 | * Check if the character is ASCII. |
|---|
| 372 | */ |
|---|
| 373 | |
|---|
| 374 | #define IS_ASCII_AT(string, offset) \ |
|---|
| 375 | (OCTET_AT((string), (offset)) <= (yaml_char_t) '\x7F') |
|---|
| 376 | |
|---|
| 377 | #define IS_ASCII(string) IS_ASCII_AT((string), 0) |
|---|
| 378 | |
|---|
| 379 | /* |
|---|
| 380 | * Check if the character can be printed unescaped. |
|---|
| 381 | */ |
|---|
| 382 | |
|---|
| 383 | #define IS_PRINTABLE_AT(string, offset) \ |
|---|
| 384 | ((OCTET_AT((string), (offset)) == 0x0A) /* . == #x0A */ \ |
|---|
| 385 | || (OCTET_AT((string), (offset)) >= 0x20 /* #x20 <= . <= #x7E */ \ |
|---|
| 386 | && OCTET_AT((string), (offset)) <= 0x7E) \ |
|---|
| 387 | || (OCTET_AT((string), (offset)) == 0xC2 /* #0xA0 <= . <= #xD7FF */ \ |
|---|
| 388 | && OCTET_AT((string), (offset)+1) >= 0xA0) \ |
|---|
| 389 | || (OCTET_AT((string), (offset)) > 0xC2 \ |
|---|
| 390 | && OCTET_AT((string), (offset)) < 0xED) \ |
|---|
| 391 | || (OCTET_AT((string), (offset)) == 0xED \ |
|---|
| 392 | && OCTET_AT((string), (offset)+1) < 0xA0) \ |
|---|
| 393 | || (OCTET_AT((string), (offset)) == 0xEE) \ |
|---|
| 394 | || (OCTET_AT((string), (offset)) == 0xEF /* #xE000 <= . <= #xFFFD */ \ |
|---|
| 395 | && !(OCTET_AT((string), (offset)+1) == 0xBB /* && . != #xFEFF */ \ |
|---|
| 396 | && OCTET_AT((string), (offset)+2) == 0xBF) \ |
|---|
| 397 | && !(OCTET_AT((string), (offset)+1) == 0xBF \ |
|---|
| 398 | && (OCTET_AT((string), (offset)+2) == 0xBE \ |
|---|
| 399 | || OCTET_AT((string), (offset)+2) == 0xBF)))) |
|---|
| 400 | |
|---|
| 401 | #define IS_PRINTABLE(string) IS_PRINTABLE_AT((string), 0) |
|---|
| 402 | |
|---|
| 403 | /* |
|---|
| 404 | * Check if the character at the specified position is NUL. |
|---|
| 405 | */ |
|---|
| 406 | |
|---|
| 407 | #define IS_Z_AT(string, offset) CHECK_AT((string), '\0', (offset)) |
|---|
| 408 | |
|---|
| 409 | #define IS_Z(string) IS_Z_AT((string), 0) |
|---|
| 410 | |
|---|
| 411 | /* |
|---|
| 412 | * Check if the character at the specified position is BOM. |
|---|
| 413 | */ |
|---|
| 414 | |
|---|
| 415 | #define IS_BOM_AT(string, offset) \ |
|---|
| 416 | (CHECK_AT((string), '\xEF', (offset)) \ |
|---|
| 417 | && CHECK_AT((string), '\xBB', (offset)+1) \ |
|---|
| 418 | && CHECK_AT((string), '\xBF', (offset)+2)) /* BOM (#xFEFF) */ |
|---|
| 419 | |
|---|
| 420 | #define IS_BOM(string) IS_BOM_AT(string, 0) |
|---|
| 421 | |
|---|
| 422 | /* |
|---|
| 423 | * Check if the character at the specified position is space. |
|---|
| 424 | */ |
|---|
| 425 | |
|---|
| 426 | #define IS_SPACE_AT(string, offset) CHECK_AT((string), ' ', (offset)) |
|---|
| 427 | |
|---|
| 428 | #define IS_SPACE(string) IS_SPACE_AT((string), 0) |
|---|
| 429 | |
|---|
| 430 | /* |
|---|
| 431 | * Check if the character at the specified position is tab. |
|---|
| 432 | */ |
|---|
| 433 | |
|---|
| 434 | #define IS_TAB_AT(string, offset) CHECK_AT((string), '\t', (offset)) |
|---|
| 435 | |
|---|
| 436 | #define IS_TAB(string) IS_TAB_AT((string), 0) |
|---|
| 437 | |
|---|
| 438 | /* |
|---|
| 439 | * Check if the character at the specified position is blank (space or tab). |
|---|
| 440 | */ |
|---|
| 441 | |
|---|
| 442 | #define IS_BLANK_AT(string, offset) \ |
|---|
| 443 | (IS_SPACE_AT((string), (offset)) || IS_TAB_AT((string), (offset))) |
|---|
| 444 | |
|---|
| 445 | #define IS_BLANK(string) IS_BLANK_AT((string), 0) |
|---|
| 446 | |
|---|
| 447 | /* |
|---|
| 448 | * Check if the character at the specified position is a line break. |
|---|
| 449 | */ |
|---|
| 450 | |
|---|
| 451 | #define IS_BREAK_AT(string, offset) \ |
|---|
| 452 | (CHECK_AT((string), '\r', (offset)) /* CR (#xD)*/ \ |
|---|
| 453 | || CHECK_AT((string), '\n', (offset)) /* LF (#xA) */ \ |
|---|
| 454 | || (CHECK_AT((string), '\xC2', (offset)) \ |
|---|
| 455 | && CHECK_AT((string), '\x85', (offset)+1)) /* NEL (#x85) */ \ |
|---|
| 456 | || (CHECK_AT((string), '\xE2', (offset)) \ |
|---|
| 457 | && CHECK_AT((string), '\x80', (offset)+1) \ |
|---|
| 458 | && CHECK_AT((string), '\xA8', (offset)+2)) /* LS (#x2028) */ \ |
|---|
| 459 | || (CHECK_AT((string), '\xE2', (offset)) \ |
|---|
| 460 | && CHECK_AT((string), '\x80', (offset)+1) \ |
|---|
| 461 | && CHECK_AT((string), '\xA9', (offset)+2))) /* PS (#x2029) */ |
|---|
| 462 | |
|---|
| 463 | #define IS_BREAK(string) IS_BREAK_AT((string), 0) |
|---|
| 464 | |
|---|
| 465 | #define IS_CRLF_AT(string, offset) \ |
|---|
| 466 | (CHECK_AT((string), '\r', (offset)) && CHECK_AT((string), '\n', (offset)+1)) |
|---|
| 467 | |
|---|
| 468 | #define IS_CRLF(string) IS_CRLF_AT((string), 0) |
|---|
| 469 | |
|---|
| 470 | /* |
|---|
| 471 | * Check if the character is a line break or NUL. |
|---|
| 472 | */ |
|---|
| 473 | |
|---|
| 474 | #define IS_BREAKZ_AT(string, offset) \ |
|---|
| 475 | (IS_BREAK_AT((string), (offset)) || IS_Z_AT((string), (offset))) |
|---|
| 476 | |
|---|
| 477 | #define IS_BREAKZ(string) IS_BREAKZ_AT((string), 0) |
|---|
| 478 | |
|---|
| 479 | /* |
|---|
| 480 | * Check if the character is a line break, space, or NUL. |
|---|
| 481 | */ |
|---|
| 482 | |
|---|
| 483 | #define IS_SPACEZ_AT(string, offset) \ |
|---|
| 484 | (IS_SPACE_AT((string), (offset)) || IS_BREAKZ_AT((string), (offset))) |
|---|
| 485 | |
|---|
| 486 | #define IS_SPACEZ(string) IS_SPACEZ_AT((string), 0) |
|---|
| 487 | |
|---|
| 488 | /* |
|---|
| 489 | * Check if the character is a line break, space, tab, or NUL. |
|---|
| 490 | */ |
|---|
| 491 | |
|---|
| 492 | #define IS_BLANKZ_AT(string, offset) \ |
|---|
| 493 | (IS_BLANK_AT((string), (offset)) || IS_BREAKZ_AT((string), (offset))) |
|---|
| 494 | |
|---|
| 495 | #define IS_BLANKZ(string) IS_BLANKZ_AT((string), 0) |
|---|
| 496 | |
|---|
| 497 | /* |
|---|
| 498 | * Determine the width of the character. |
|---|
| 499 | */ |
|---|
| 500 | |
|---|
| 501 | #define WIDTH_AT(string, offset) \ |
|---|
| 502 | ((OCTET_AT((string), (offset)) & 0x80) == 0x00 ? 1 : \ |
|---|
| 503 | (OCTET_AT((string), (offset)) & 0xE0) == 0xC0 ? 2 : \ |
|---|
| 504 | (OCTET_AT((string), (offset)) & 0xF0) == 0xE0 ? 3 : \ |
|---|
| 505 | (OCTET_AT((string), (offset)) & 0xF8) == 0xF0 ? 4 : 0) |
|---|
| 506 | |
|---|
| 507 | #define WIDTH(string) WIDTH_AT((string), 0) |
|---|
| 508 | |
|---|
| 509 | /* |
|---|
| 510 | * Move the string pointer to the next character. |
|---|
| 511 | */ |
|---|
| 512 | |
|---|
| 513 | #define MOVE(string) ((string).pointer += WIDTH((string))) |
|---|
| 514 | |
|---|
| 515 | /* |
|---|
| 516 | * Write a single octet and bump the pointer. |
|---|
| 517 | */ |
|---|
| 518 | |
|---|
| 519 | #define JOIN_OCTET(string, octet) \ |
|---|
| 520 | ((string).buffer[(string).pointer++] = (octet)) |
|---|
| 521 | |
|---|
| 522 | /* |
|---|
| 523 | * Copy a single octet and bump the pointers. |
|---|
| 524 | */ |
|---|
| 525 | |
|---|
| 526 | #define COPY_OCTET(target_string, source_string) \ |
|---|
| 527 | ((target_string).buffer[(target_string).pointer++] \ |
|---|
| 528 | = (source_string).buffer[(source_string).pointer++]) |
|---|
| 529 | |
|---|
| 530 | /* |
|---|
| 531 | * Copy a character and move the pointers of both strings. |
|---|
| 532 | */ |
|---|
| 533 | |
|---|
| 534 | #define COPY(target_string, source_string) \ |
|---|
| 535 | ((OCTET(source_string) & 0x80) == 0x00 ? \ |
|---|
| 536 | COPY_OCTET((target_string), (source_string)) : \ |
|---|
| 537 | (OCTET(source_string) & 0xE0) == 0xC0 ? \ |
|---|
| 538 | (COPY_OCTET((target_string), (source_string)), \ |
|---|
| 539 | COPY_OCTET((target_string), (source_string))) : \ |
|---|
| 540 | (OCTET(source_string) & 0xF0) == 0xE0 ? \ |
|---|
| 541 | (COPY_OCTET((target_string), (source_string)), \ |
|---|
| 542 | COPY_OCTET((target_string), (source_string)), \ |
|---|
| 543 | COPY_OCTET((target_string), (source_string))) : \ |
|---|
| 544 | (OCTET(source_string) & 0xF8) == 0xF0 ? \ |
|---|
| 545 | (COPY_OCTET((target_string), (source_string)), \ |
|---|
| 546 | COPY_OCTET((target_string), (source_string)), \ |
|---|
| 547 | COPY_OCTET((target_string), (source_string)), \ |
|---|
| 548 | COPY_OCTET((target_string), (source_string))) : 0) |
|---|
| 549 | |
|---|
| 550 | /* |
|---|
| 551 | * Stack and queue management. |
|---|
| 552 | */ |
|---|
| 553 | |
|---|
| 554 | YAML_DECLARE(int) |
|---|
| 555 | yaml_stack_extend(void **list, size_t size, size_t *length, size_t *capacity); |
|---|
| 556 | |
|---|
| 557 | YAML_DECLARE(int) |
|---|
| 558 | yaml_queue_extend(void **list, size_t size, |
|---|
| 559 | size_t *head, size_t *tail, size_t *capacity); |
|---|
| 560 | |
|---|
| 561 | #define STACK_INIT(self, stack, _capacity) \ |
|---|
| 562 | (((stack).list = yaml_malloc((_capacity)*sizeof(*(stack).list))) ? \ |
|---|
| 563 | ((stack).length = 0, \ |
|---|
| 564 | (stack).capacity = (_capacity), \ |
|---|
| 565 | 1) : \ |
|---|
| 566 | ((self)->error.type = YAML_MEMORY_ERROR, \ |
|---|
| 567 | 0)) |
|---|
| 568 | |
|---|
| 569 | #define STACK_DEL(self, stack) \ |
|---|
| 570 | (yaml_free((stack).list), \ |
|---|
| 571 | (stack).list = NULL, \ |
|---|
| 572 | (stack).length = (stack).capacity = 0) |
|---|
| 573 | |
|---|
| 574 | #define STACK_EMPTY(self, stack) \ |
|---|
| 575 | ((stack).length == 0) |
|---|
| 576 | |
|---|
| 577 | #define STACK_ITER(self, stack, index) \ |
|---|
| 578 | ((stack).list + index) |
|---|
| 579 | |
|---|
| 580 | #define PUSH(self, stack, value) \ |
|---|
| 581 | (((stack).length < (stack).capacity \ |
|---|
| 582 | || yaml_stack_extend((void **)&(stack).list, sizeof(*(stack).list), \ |
|---|
| 583 | &(stack).length, &(stack).capacity)) ? \ |
|---|
| 584 | ((stack).list[(stack).length++] = (value), \ |
|---|
| 585 | 1) : \ |
|---|
| 586 | ((self)->error.type = YAML_MEMORY_ERROR, \ |
|---|
| 587 | 0)) |
|---|
| 588 | |
|---|
| 589 | #define POP(self, stack) \ |
|---|
| 590 | ((stack).list[--(stack).length]) |
|---|
| 591 | |
|---|
| 592 | #define QUEUE_INIT(self, queue, _capacity) \ |
|---|
| 593 | (((queue).list = yaml_malloc((_capacity)*sizeof(*(queue).list))) ? \ |
|---|
| 594 | ((queue).head = (queue).tail = 0, \ |
|---|
| 595 | (queue).capacity = (_capacity), \ |
|---|
| 596 | 1) : \ |
|---|
| 597 | ((self)->error.type = YAML_MEMORY_ERROR, \ |
|---|
| 598 | 0)) |
|---|
| 599 | |
|---|
| 600 | #define QUEUE_DEL(self, queue) \ |
|---|
| 601 | (yaml_free((queue).list), \ |
|---|
| 602 | (queue).list = NULL, \ |
|---|
| 603 | (queue).head = (queue).tail = (queue).capacity = 0) |
|---|
| 604 | |
|---|
| 605 | #define QUEUE_EMPTY(self, queue) \ |
|---|
| 606 | ((queue).head == (queue).tail) |
|---|
| 607 | |
|---|
| 608 | #define QUEUE_ITER(self, queue, index) \ |
|---|
| 609 | ((queue).list + (queue).head + index) |
|---|
| 610 | |
|---|
| 611 | #define ENQUEUE(self, queue, value) \ |
|---|
| 612 | (((queue).tail != (queue).capacity \ |
|---|
| 613 | || yaml_queue_extend((void **)&(queue).list, sizeof(*(queue).list), \ |
|---|
| 614 | &(queue).head, &(queue).tail, &(queue).capacity)) ? \ |
|---|
| 615 | ((queue).list[(queue).tail++] = (value), \ |
|---|
| 616 | 1) : \ |
|---|
| 617 | ((self)->error.type = YAML_MEMORY_ERROR, \ |
|---|
| 618 | 0)) |
|---|
| 619 | |
|---|
| 620 | #define DEQUEUE(self, queue) \ |
|---|
| 621 | ((queue).list[(queue).head++]) |
|---|
| 622 | |
|---|
| 623 | #define QUEUE_INSERT(self, queue, index, value) \ |
|---|
| 624 | (((queue).tail != (queue).capacity \ |
|---|
| 625 | || yaml_queue_extend((void **)&(queue).list, sizeof(*(queue).list), \ |
|---|
| 626 | &(queue).head, &(queue).tail, &(queue).capacity)) ? \ |
|---|
| 627 | (memmove((queue).list+(queue).head+(index)+1, \ |
|---|
| 628 | (queue).list+(queue).head+(index), \ |
|---|
| 629 | ((queue).tail-(queue).head-(index))*sizeof(*(queue).list)), \ |
|---|
| 630 | (queue).list[(queue).head+(index)] = (value), \ |
|---|
| 631 | (queue).tail++, \ |
|---|
| 632 | 1) : \ |
|---|
| 633 | ((self)->error.type = YAML_MEMORY_ERROR, \ |
|---|
| 634 | 0)) |
|---|
| 635 | |
|---|
| 636 | /* |
|---|
| 637 | * Token initializers. |
|---|
| 638 | */ |
|---|
| 639 | |
|---|
| 640 | #define TOKEN_INIT(token, _type, _start_mark, _end_mark) \ |
|---|
| 641 | (memset(&(token), 0, sizeof(yaml_token_t)), \ |
|---|
| 642 | (token).type = (_type), \ |
|---|
| 643 | (token).start_mark = (_start_mark), \ |
|---|
| 644 | (token).end_mark = (_end_mark)) |
|---|
| 645 | |
|---|
| 646 | #define STREAM_START_TOKEN_INIT(token, _encoding, _start_mark, _end_mark) \ |
|---|
| 647 | (TOKEN_INIT((token), YAML_STREAM_START_TOKEN, (_start_mark), (_end_mark)), \ |
|---|
| 648 | (token).data.stream_start.encoding = (_encoding)) |
|---|
| 649 | |
|---|
| 650 | #define STREAM_END_TOKEN_INIT(token, _start_mark, _end_mark) \ |
|---|
| 651 | (TOKEN_INIT((token), YAML_STREAM_END_TOKEN, (_start_mark), (_end_mark))) |
|---|
| 652 | |
|---|
| 653 | #define ALIAS_TOKEN_INIT(token, _value, _start_mark, _end_mark) \ |
|---|
| 654 | (TOKEN_INIT((token), YAML_ALIAS_TOKEN, (_start_mark), (_end_mark)), \ |
|---|
| 655 | (token).data.alias.value = (_value)) |
|---|
| 656 | |
|---|
| 657 | #define ANCHOR_TOKEN_INIT(token, _value, _start_mark, _end_mark) \ |
|---|
| 658 | (TOKEN_INIT((token), YAML_ANCHOR_TOKEN, (_start_mark), (_end_mark)), \ |
|---|
| 659 | (token).data.anchor.value = (_value)) |
|---|
| 660 | |
|---|
| 661 | #define TAG_TOKEN_INIT(token, _handle, _suffix, _start_mark, _end_mark) \ |
|---|
| 662 | (TOKEN_INIT((token), YAML_TAG_TOKEN, (_start_mark), (_end_mark)), \ |
|---|
| 663 | (token).data.tag.handle = (_handle), \ |
|---|
| 664 | (token).data.tag.suffix = (_suffix)) |
|---|
| 665 | |
|---|
| 666 | #define SCALAR_TOKEN_INIT(token, _value, _length, _style, _start_mark, _end_mark) \ |
|---|
| 667 | (TOKEN_INIT((token), YAML_SCALAR_TOKEN, (_start_mark), (_end_mark)), \ |
|---|
| 668 | (token).data.scalar.value = (_value), \ |
|---|
| 669 | (token).data.scalar.length = (_length), \ |
|---|
| 670 | (token).data.scalar.style = (_style)) |
|---|
| 671 | |
|---|
| 672 | #define VERSION_DIRECTIVE_TOKEN_INIT(token, _major, _minor, _start_mark, _end_mark) \ |
|---|
| 673 | (TOKEN_INIT((token), YAML_VERSION_DIRECTIVE_TOKEN, (_start_mark), (_end_mark)), \ |
|---|
| 674 | (token).data.version_directive.major = (_major), \ |
|---|
| 675 | (token).data.version_directive.minor = (_minor)) |
|---|
| 676 | |
|---|
| 677 | #define TAG_DIRECTIVE_TOKEN_INIT(token, _handle, _prefix, _start_mark, _end_mark) \ |
|---|
| 678 | (TOKEN_INIT((token), YAML_TAG_DIRECTIVE_TOKEN, (_start_mark), (_end_mark)), \ |
|---|
| 679 | (token).data.tag_directive.handle = (_handle), \ |
|---|
| 680 | (token).data.tag_directive.prefix = (_prefix)) |
|---|
| 681 | |
|---|
| 682 | /* |
|---|
| 683 | * Event initializers. |
|---|
| 684 | */ |
|---|
| 685 | |
|---|
| 686 | #define EVENT_INIT(event, _type, _start_mark, _end_mark) \ |
|---|
| 687 | (memset(&(event), 0, sizeof(yaml_event_t)), \ |
|---|
| 688 | (event).type = (_type), \ |
|---|
| 689 | (event).start_mark = (_start_mark), \ |
|---|
| 690 | (event).end_mark = (_end_mark)) |
|---|
| 691 | |
|---|
| 692 | #define STREAM_START_EVENT_INIT(event, _encoding, _start_mark, _end_mark) \ |
|---|
| 693 | (EVENT_INIT((event), YAML_STREAM_START_EVENT, (_start_mark), (_end_mark)), \ |
|---|
| 694 | (event).data.stream_start.encoding = (_encoding)) |
|---|
| 695 | |
|---|
| 696 | #define STREAM_END_EVENT_INIT(event, _start_mark, _end_mark) \ |
|---|
| 697 | (EVENT_INIT((event), YAML_STREAM_END_EVENT, (_start_mark), (_end_mark))) |
|---|
| 698 | |
|---|
| 699 | #define DOCUMENT_START_EVENT_INIT(event, _version_directive, \ |
|---|
| 700 | _tag_directives_list, _tag_directives_length, _tag_directives_capacity, \ |
|---|
| 701 | _is_implicit, _start_mark, _end_mark) \ |
|---|
| 702 | (EVENT_INIT((event), YAML_DOCUMENT_START_EVENT, (_start_mark),(_end_mark)), \ |
|---|
| 703 | (event).data.document_start.version_directive = (_version_directive), \ |
|---|
| 704 | (event).data.document_start.tag_directives.list = (_tag_directives_list), \ |
|---|
| 705 | (event).data.document_start.tag_directives.length = (_tag_directives_length), \ |
|---|
| 706 | (event).data.document_start.tag_directives.capacity = (_tag_directives_capacity), \ |
|---|
| 707 | (event).data.document_start.is_implicit = (_is_implicit)) |
|---|
| 708 | |
|---|
| 709 | #define DOCUMENT_END_EVENT_INIT(event, _is_implicit, _start_mark, _end_mark) \ |
|---|
| 710 | (EVENT_INIT((event), YAML_DOCUMENT_END_EVENT, (_start_mark), (_end_mark)), \ |
|---|
| 711 | (event).data.document_end.is_implicit = (_is_implicit)) |
|---|
| 712 | |
|---|
| 713 | #define ALIAS_EVENT_INIT(event, _anchor, _start_mark, _end_mark) \ |
|---|
| 714 | (EVENT_INIT((event), YAML_ALIAS_EVENT, (_start_mark), (_end_mark)), \ |
|---|
| 715 | (event).data.alias.anchor = (_anchor)) |
|---|
| 716 | |
|---|
| 717 | #define SCALAR_EVENT_INIT(event, _anchor, _tag, _value, _length, \ |
|---|
| 718 | _is_plain_implicit, _is_quoted_implicit, _style, _start_mark, _end_mark) \ |
|---|
| 719 | (EVENT_INIT((event), YAML_SCALAR_EVENT, (_start_mark), (_end_mark)), \ |
|---|
| 720 | (event).data.scalar.anchor = (_anchor), \ |
|---|
| 721 | (event).data.scalar.tag = (_tag), \ |
|---|
| 722 | (event).data.scalar.value = (_value), \ |
|---|
| 723 | (event).data.scalar.length = (_length), \ |
|---|
| 724 | (event).data.scalar.is_plain_implicit = (_is_plain_implicit), \ |
|---|
| 725 | (event).data.scalar.is_quoted_implicit = (_is_quoted_implicit), \ |
|---|
| 726 | (event).data.scalar.style = (_style)) |
|---|
| 727 | |
|---|
| 728 | #define SEQUENCE_START_EVENT_INIT(event, _anchor, _tag, _is_implicit, _style, \ |
|---|
| 729 | _start_mark, _end_mark) \ |
|---|
| 730 | (EVENT_INIT((event), YAML_SEQUENCE_START_EVENT, (_start_mark), (_end_mark)), \ |
|---|
| 731 | (event).data.sequence_start.anchor = (_anchor), \ |
|---|
| 732 | (event).data.sequence_start.tag = (_tag), \ |
|---|
| 733 | (event).data.sequence_start.is_implicit = (_is_implicit), \ |
|---|
| 734 | (event).data.sequence_start.style = (_style)) |
|---|
| 735 | |
|---|
| 736 | #define SEQUENCE_END_EVENT_INIT(event, _start_mark, _end_mark) \ |
|---|
| 737 | (EVENT_INIT((event), YAML_SEQUENCE_END_EVENT, (_start_mark), (_end_mark))) |
|---|
| 738 | |
|---|
| 739 | #define MAPPING_START_EVENT_INIT(event, _anchor, _tag, _is_implicit, _style, \ |
|---|
| 740 | _start_mark, _end_mark) \ |
|---|
| 741 | (EVENT_INIT((event), YAML_MAPPING_START_EVENT, (_start_mark), (_end_mark)), \ |
|---|
| 742 | (event).data.mapping_start.anchor = (_anchor), \ |
|---|
| 743 | (event).data.mapping_start.tag = (_tag), \ |
|---|
| 744 | (event).data.mapping_start.is_implicit = (_is_implicit), \ |
|---|
| 745 | (event).data.mapping_start.style = (_style)) |
|---|
| 746 | |
|---|
| 747 | #define MAPPING_END_EVENT_INIT(event, _start_mark, _end_mark) \ |
|---|
| 748 | (EVENT_INIT((event), YAML_MAPPING_END_EVENT, (_start_mark), (_end_mark))) |
|---|
| 749 | |
|---|
| 750 | #if 0 |
|---|
| 751 | |
|---|
| 752 | /* |
|---|
| 753 | * Document initializer. |
|---|
| 754 | */ |
|---|
| 755 | |
|---|
| 756 | #define DOCUMENT_INIT(document,document_nodes_start,document_nodes_end, \ |
|---|
| 757 | document_version_directive,document_tag_directives_start, \ |
|---|
| 758 | document_tag_directives_end,document_start_implicit, \ |
|---|
| 759 | document_end_implicit,document_start_mark,document_end_mark) \ |
|---|
| 760 | (memset(&(document), 0, sizeof(yaml_document_t)), \ |
|---|
| 761 | (document).nodes.start = (document_nodes_start), \ |
|---|
| 762 | (document).nodes.end = (document_nodes_end), \ |
|---|
| 763 | (document).nodes.top = (document_nodes_start), \ |
|---|
| 764 | (document).version_directive = (document_version_directive), \ |
|---|
| 765 | (document).tag_directives.start = (document_tag_directives_start), \ |
|---|
| 766 | (document).tag_directives.end = (document_tag_directives_end), \ |
|---|
| 767 | (document).start_implicit = (document_start_implicit), \ |
|---|
| 768 | (document).end_implicit = (document_end_implicit), \ |
|---|
| 769 | (document).start_mark = (document_start_mark), \ |
|---|
| 770 | (document).end_mark = (document_end_mark)) |
|---|
| 771 | |
|---|
| 772 | /* |
|---|
| 773 | * Node initializers. |
|---|
| 774 | */ |
|---|
| 775 | |
|---|
| 776 | #define NODE_INIT(node,node_type,node_tag,node_start_mark,node_end_mark) \ |
|---|
| 777 | (memset(&(node), 0, sizeof(yaml_node_t)), \ |
|---|
| 778 | (node).type = (node_type), \ |
|---|
| 779 | (node).tag = (node_tag), \ |
|---|
| 780 | (node).start_mark = (node_start_mark), \ |
|---|
| 781 | (node).end_mark = (node_end_mark)) |
|---|
| 782 | |
|---|
| 783 | #define SCALAR_NODE_INIT(node,node_tag,node_value,node_length, \ |
|---|
| 784 | node_style,start_mark,end_mark) \ |
|---|
| 785 | (NODE_INIT((node),YAML_SCALAR_NODE,(node_tag),(start_mark),(end_mark)), \ |
|---|
| 786 | (node).data.scalar.value = (node_value), \ |
|---|
| 787 | (node).data.scalar.length = (node_length), \ |
|---|
| 788 | (node).data.scalar.style = (node_style)) |
|---|
| 789 | |
|---|
| 790 | #define SEQUENCE_NODE_INIT(node,node_tag,node_items_start,node_items_end, \ |
|---|
| 791 | node_style,start_mark,end_mark) \ |
|---|
| 792 | (NODE_INIT((node),YAML_SEQUENCE_NODE,(node_tag),(start_mark),(end_mark)), \ |
|---|
| 793 | (node).data.sequence.items.start = (node_items_start), \ |
|---|
| 794 | (node).data.sequence.items.end = (node_items_end), \ |
|---|
| 795 | (node).data.sequence.items.top = (node_items_start), \ |
|---|
| 796 | (node).data.sequence.style = (node_style)) |
|---|
| 797 | |
|---|
| 798 | #define MAPPING_NODE_INIT(node,node_tag,node_pairs_start,node_pairs_end, \ |
|---|
| 799 | node_style,start_mark,end_mark) \ |
|---|
| 800 | (NODE_INIT((node),YAML_MAPPING_NODE,(node_tag),(start_mark),(end_mark)), \ |
|---|
| 801 | (node).data.mapping.pairs.start = (node_pairs_start), \ |
|---|
| 802 | (node).data.mapping.pairs.end = (node_pairs_end), \ |
|---|
| 803 | (node).data.mapping.pairs.top = (node_pairs_start), \ |
|---|
| 804 | (node).data.mapping.style = (node_style)) |
|---|
| 805 | |
|---|
| 806 | #endif |
|---|
| 807 | |
|---|
| 808 | /* |
|---|
| 809 | * This structure holds information about a potential simple key. |
|---|
| 810 | */ |
|---|
| 811 | |
|---|
| 812 | typedef struct yaml_simple_key_s { |
|---|
| 813 | /* Is a simple key possible? */ |
|---|
| 814 | int is_possible; |
|---|
| 815 | /* Is a simple key required? */ |
|---|
| 816 | int is_required; |
|---|
| 817 | /* The number of the token. */ |
|---|
| 818 | size_t token_number; |
|---|
| 819 | /* The position mark. */ |
|---|
| 820 | yaml_mark_t mark; |
|---|
| 821 | } yaml_simple_key_t; |
|---|
| 822 | |
|---|
| 823 | /* |
|---|
| 824 | * The states of the parser. |
|---|
| 825 | */ |
|---|
| 826 | |
|---|
| 827 | typedef enum yaml_parser_state_e { |
|---|
| 828 | /* Expect STREAM-START. */ |
|---|
| 829 | YAML_PARSE_STREAM_START_STATE, |
|---|
| 830 | /* Expect the beginning of an implicit document. */ |
|---|
| 831 | YAML_PARSE_IMPLICIT_DOCUMENT_START_STATE, |
|---|
| 832 | /* Expect DOCUMENT-START. */ |
|---|
| 833 | YAML_PARSE_DOCUMENT_START_STATE, |
|---|
| 834 | /* Expect the content of a document. */ |
|---|
| 835 | YAML_PARSE_DOCUMENT_CONTENT_STATE, |
|---|
| 836 | /* Expect DOCUMENT-END. */ |
|---|
| 837 | YAML_PARSE_DOCUMENT_END_STATE, |
|---|
| 838 | /* Expect a block node. */ |
|---|
| 839 | YAML_PARSE_BLOCK_NODE_STATE, |
|---|
| 840 | /* Expect a block node or indentless sequence. */ |
|---|
| 841 | YAML_PARSE_BLOCK_NODE_OR_INDENTLESS_SEQUENCE_STATE, |
|---|
| 842 | /* Expect a flow node. */ |
|---|
| 843 | YAML_PARSE_FLOW_NODE_STATE, |
|---|
| 844 | /* Expect the first entry of a block sequence. */ |
|---|
| 845 | YAML_PARSE_BLOCK_SEQUENCE_FIRST_ENTRY_STATE, |
|---|
| 846 | /* Expect an entry of a block sequence. */ |
|---|
| 847 | YAML_PARSE_BLOCK_SEQUENCE_ENTRY_STATE, |
|---|
| 848 | /* Expect an entry of an indentless sequence. */ |
|---|
| 849 | YAML_PARSE_INDENTLESS_SEQUENCE_ENTRY_STATE, |
|---|
| 850 | /* Expect the first key of a block mapping. */ |
|---|
| 851 | YAML_PARSE_BLOCK_MAPPING_FIRST_KEY_STATE, |
|---|
| 852 | /* Expect a block mapping key. */ |
|---|
| 853 | YAML_PARSE_BLOCK_MAPPING_KEY_STATE, |
|---|
| 854 | /* Expect a block mapping value. */ |
|---|
| 855 | YAML_PARSE_BLOCK_MAPPING_VALUE_STATE, |
|---|
| 856 | /* Expect the first entry of a flow sequence. */ |
|---|
| 857 | YAML_PARSE_FLOW_SEQUENCE_FIRST_ENTRY_STATE, |
|---|
| 858 | /* Expect an entry of a flow sequence. */ |
|---|
| 859 | YAML_PARSE_FLOW_SEQUENCE_ENTRY_STATE, |
|---|
| 860 | /* Expect a key of an ordered mapping. */ |
|---|
| 861 | YAML_PARSE_FLOW_SEQUENCE_ENTRY_MAPPING_KEY_STATE, |
|---|
| 862 | /* Expect a value of an ordered mapping. */ |
|---|
| 863 | YAML_PARSE_FLOW_SEQUENCE_ENTRY_MAPPING_VALUE_STATE, |
|---|
| 864 | /* Expect the and of an ordered mapping entry. */ |
|---|
| 865 | YAML_PARSE_FLOW_SEQUENCE_ENTRY_MAPPING_END_STATE, |
|---|
| 866 | /* Expect the first key of a flow mapping. */ |
|---|
| 867 | YAML_PARSE_FLOW_MAPPING_FIRST_KEY_STATE, |
|---|
| 868 | /* Expect a key of a flow mapping. */ |
|---|
| 869 | YAML_PARSE_FLOW_MAPPING_KEY_STATE, |
|---|
| 870 | /* Expect a value of a flow mapping. */ |
|---|
| 871 | YAML_PARSE_FLOW_MAPPING_VALUE_STATE, |
|---|
| 872 | /* Expect an empty value of a flow mapping. */ |
|---|
| 873 | YAML_PARSE_FLOW_MAPPING_EMPTY_VALUE_STATE, |
|---|
| 874 | /* Expect nothing. */ |
|---|
| 875 | YAML_PARSE_END_STATE |
|---|
| 876 | } yaml_parser_state_t; |
|---|
| 877 | |
|---|
| 878 | /* |
|---|
| 879 | * This structure holds aliases data. |
|---|
| 880 | */ |
|---|
| 881 | |
|---|
| 882 | typedef struct yaml_alias_data_s { |
|---|
| 883 | /* The anchor. */ |
|---|
| 884 | yaml_char_t *anchor; |
|---|
| 885 | /* The node id. */ |
|---|
| 886 | int index; |
|---|
| 887 | /* The anchor mark. */ |
|---|
| 888 | yaml_mark_t mark; |
|---|
| 889 | } yaml_alias_data_t; |
|---|
| 890 | |
|---|
| 891 | /* |
|---|
| 892 | * The structure that holds data used by the file and string readers. |
|---|
| 893 | */ |
|---|
| 894 | |
|---|
| 895 | typedef struct yaml_standard_reader_data_t { |
|---|
| 896 | /* String input data. */ |
|---|
| 897 | yaml_istring_t string; |
|---|
| 898 | /* File input data. */ |
|---|
| 899 | FILE *file; |
|---|
| 900 | } yaml_standard_reader_data_t; |
|---|
| 901 | |
|---|
| 902 | /* |
|---|
| 903 | * The internal parser structure. |
|---|
| 904 | */ |
|---|
| 905 | |
|---|
| 906 | struct yaml_parser_s { |
|---|
| 907 | |
|---|
| 908 | /* |
|---|
| 909 | * Error stuff. |
|---|
| 910 | */ |
|---|
| 911 | |
|---|
| 912 | yaml_error_t error; |
|---|
| 913 | |
|---|
| 914 | /* |
|---|
| 915 | * Reader stuff. |
|---|
| 916 | */ |
|---|
| 917 | |
|---|
| 918 | /* The read handler. */ |
|---|
| 919 | yaml_reader_t *reader; |
|---|
| 920 | |
|---|
| 921 | /* The application data to be passed to the reader. */ |
|---|
| 922 | void *reader_data; |
|---|
| 923 | |
|---|
| 924 | /* Standard (string or file) input data. */ |
|---|
| 925 | yaml_standard_reader_data_t standard_reader_data; |
|---|
| 926 | |
|---|
| 927 | /* EOF flag. */ |
|---|
| 928 | int is_eof; |
|---|
| 929 | |
|---|
| 930 | /* The working buffer. */ |
|---|
| 931 | yaml_iostring_t input; |
|---|
| 932 | |
|---|
| 933 | /* The number of unread characters in the buffer. */ |
|---|
| 934 | size_t unread; |
|---|
| 935 | |
|---|
| 936 | /* The raw buffer. */ |
|---|
| 937 | yaml_raw_iostring_t raw_input; |
|---|
| 938 | |
|---|
| 939 | /* The input encoding. */ |
|---|
| 940 | yaml_encoding_t encoding; |
|---|
| 941 | |
|---|
| 942 | /* The offset of the current position (in bytes). */ |
|---|
| 943 | size_t offset; |
|---|
| 944 | |
|---|
| 945 | /* The mark of the current position. */ |
|---|
| 946 | yaml_mark_t mark; |
|---|
| 947 | |
|---|
| 948 | /* |
|---|
| 949 | * Scanner stuff. |
|---|
| 950 | */ |
|---|
| 951 | |
|---|
| 952 | /* Have we started to scan the input stream? */ |
|---|
| 953 | int is_stream_start_produced; |
|---|
| 954 | |
|---|
| 955 | /* Have we reached the end of the input stream? */ |
|---|
| 956 | int is_stream_end_produced; |
|---|
| 957 | |
|---|
| 958 | /* The number of unclosed '[' and '{' indicators. */ |
|---|
| 959 | int flow_level; |
|---|
| 960 | |
|---|
| 961 | /* The tokens queue. */ |
|---|
| 962 | struct { |
|---|
| 963 | yaml_token_t *list; |
|---|
| 964 | size_t head; |
|---|
| 965 | size_t tail; |
|---|
| 966 | size_t capacity; |
|---|
| 967 | } tokens; |
|---|
| 968 | |
|---|
| 969 | /* The number of tokens fetched from the queue. */ |
|---|
| 970 | size_t tokens_parsed; |
|---|
| 971 | |
|---|
| 972 | /* Does the tokens queue contain a token ready for dequeueing. */ |
|---|
| 973 | int is_token_available; |
|---|
| 974 | |
|---|
| 975 | /* The indentation levels stack. */ |
|---|
| 976 | struct { |
|---|
| 977 | int *list; |
|---|
| 978 | size_t length; |
|---|
| 979 | size_t capacity; |
|---|
| 980 | } indents; |
|---|
| 981 | |
|---|
| 982 | /* The current indentation level. */ |
|---|
| 983 | int indent; |
|---|
| 984 | |
|---|
| 985 | /* May a simple key occur at the current position? */ |
|---|
| 986 | int is_simple_key_allowed; |
|---|
| 987 | |
|---|
| 988 | /* The stack of simple keys. */ |
|---|
| 989 | struct { |
|---|
| 990 | yaml_simple_key_t *list; |
|---|
| 991 | size_t length; |
|---|
| 992 | size_t capacity; |
|---|
| 993 | } simple_keys; |
|---|
| 994 | |
|---|
| 995 | /* |
|---|
| 996 | * Parser stuff. |
|---|
| 997 | */ |
|---|
| 998 | |
|---|
| 999 | /* The parser states stack. */ |
|---|
| 1000 | struct { |
|---|
| 1001 | yaml_parser_state_t *list; |
|---|
| 1002 | size_t length; |
|---|
| 1003 | size_t capacity; |
|---|
| 1004 | } states; |
|---|
| 1005 | |
|---|
| 1006 | /* The current parser state. */ |
|---|
| 1007 | yaml_parser_state_t state; |
|---|
| 1008 | |
|---|
| 1009 | /* The stack of marks. */ |
|---|
| 1010 | struct { |
|---|
| 1011 | yaml_mark_t *list; |
|---|
| 1012 | size_t length; |
|---|
| 1013 | size_t capacity; |
|---|
| 1014 | } marks; |
|---|
| 1015 | |
|---|
| 1016 | /* The list of TAG directives. */ |
|---|
| 1017 | struct { |
|---|
| 1018 | yaml_tag_directive_t *list; |
|---|
| 1019 | size_t length; |
|---|
| 1020 | size_t capacity; |
|---|
| 1021 | } tag_directives; |
|---|
| 1022 | |
|---|
| 1023 | /* |
|---|
| 1024 | * Dumper stuff. |
|---|
| 1025 | */ |
|---|
| 1026 | |
|---|
| 1027 | /* The resolve handler. */ |
|---|
| 1028 | yaml_resolver_t *resolver; |
|---|
| 1029 | |
|---|
| 1030 | /* The application data to be passed to the resolver. */ |
|---|
| 1031 | void *resolver_data; |
|---|
| 1032 | |
|---|
| 1033 | /* The alias data. */ |
|---|
| 1034 | struct { |
|---|
| 1035 | yaml_alias_data_t *list; |
|---|
| 1036 | size_t length; |
|---|
| 1037 | size_t capacity; |
|---|
| 1038 | } aliases; |
|---|
| 1039 | |
|---|
| 1040 | /* The currently parsed document. */ |
|---|
| 1041 | yaml_document_t *document; |
|---|
| 1042 | |
|---|
| 1043 | }; |
|---|
| 1044 | |
|---|
| 1045 | /* |
|---|
| 1046 | * The emitter states. |
|---|
| 1047 | */ |
|---|
| 1048 | |
|---|
| 1049 | typedef enum yaml_emitter_state_e { |
|---|
| 1050 | /** Expect STREAM-START. */ |
|---|
| 1051 | YAML_EMIT_STREAM_START_STATE, |
|---|
| 1052 | /** Expect the first DOCUMENT-START or STREAM-END. */ |
|---|
| 1053 | YAML_EMIT_FIRST_DOCUMENT_START_STATE, |
|---|
| 1054 | /** Expect DOCUMENT-START or STREAM-END. */ |
|---|
| 1055 | YAML_EMIT_DOCUMENT_START_STATE, |
|---|
| 1056 | /** Expect the content of a document. */ |
|---|
| 1057 | YAML_EMIT_DOCUMENT_CONTENT_STATE, |
|---|
| 1058 | /** Expect DOCUMENT-END. */ |
|---|
| 1059 | YAML_EMIT_DOCUMENT_END_STATE, |
|---|
| 1060 | /** Expect the first item of a flow sequence. */ |
|---|
| 1061 | YAML_EMIT_FLOW_SEQUENCE_FIRST_ITEM_STATE, |
|---|
| 1062 | /** Expect an item of a flow sequence. */ |
|---|
| 1063 | YAML_EMIT_FLOW_SEQUENCE_ITEM_STATE, |
|---|
| 1064 | /** Expect the first key of a flow mapping. */ |
|---|
| 1065 | YAML_EMIT_FLOW_MAPPING_FIRST_KEY_STATE, |
|---|
| 1066 | /** Expect a key of a flow mapping. */ |
|---|
| 1067 | YAML_EMIT_FLOW_MAPPING_KEY_STATE, |
|---|
| 1068 | /** Expect a value for a simple key of a flow mapping. */ |
|---|
| 1069 | YAML_EMIT_FLOW_MAPPING_SIMPLE_VALUE_STATE, |
|---|
| 1070 | /** Expect a value of a flow mapping. */ |
|---|
| 1071 | YAML_EMIT_FLOW_MAPPING_VALUE_STATE, |
|---|
| 1072 | /** Expect the first item of a block sequence. */ |
|---|
| 1073 | YAML_EMIT_BLOCK_SEQUENCE_FIRST_ITEM_STATE, |
|---|
| 1074 | /** Expect an item of a block sequence. */ |
|---|
| 1075 | YAML_EMIT_BLOCK_SEQUENCE_ITEM_STATE, |
|---|
| 1076 | /** Expect the first key of a block mapping. */ |
|---|
| 1077 | YAML_EMIT_BLOCK_MAPPING_FIRST_KEY_STATE, |
|---|
| 1078 | /** Expect the key of a block mapping. */ |
|---|
| 1079 | YAML_EMIT_BLOCK_MAPPING_KEY_STATE, |
|---|
| 1080 | /** Expect a value for a simple key of a block mapping. */ |
|---|
| 1081 | YAML_EMIT_BLOCK_MAPPING_SIMPLE_VALUE_STATE, |
|---|
| 1082 | /** Expect a value of a block mapping. */ |
|---|
| 1083 | YAML_EMIT_BLOCK_MAPPING_VALUE_STATE, |
|---|
| 1084 | /** Expect nothing. */ |
|---|
| 1085 | YAML_EMIT_END_STATE |
|---|
| 1086 | } yaml_emitter_state_t; |
|---|
| 1087 | |
|---|
| 1088 | /* |
|---|
| 1089 | * The structure that holds data used by the file and string readers. |
|---|
| 1090 | */ |
|---|
| 1091 | |
|---|
| 1092 | typedef struct yaml_standard_writer_data_t { |
|---|
| 1093 | /* String output data. */ |
|---|
| 1094 | yaml_ostring_t string; |
|---|
| 1095 | size_t *length; |
|---|
| 1096 | /* File output data. */ |
|---|
| 1097 | FILE *file; |
|---|
| 1098 | } yaml_standard_writer_data_t; |
|---|
| 1099 | |
|---|
| 1100 | /* |
|---|
| 1101 | * The internals emitter structure. |
|---|
| 1102 | */ |
|---|
| 1103 | |
|---|
| 1104 | struct yaml_emitter_s { |
|---|
| 1105 | |
|---|
| 1106 | /* |
|---|
| 1107 | * Error stuff. |
|---|
| 1108 | */ |
|---|
| 1109 | |
|---|
| 1110 | yaml_error_t error; |
|---|
| 1111 | |
|---|
| 1112 | /* |
|---|
| 1113 | * Writer stuff. |
|---|
| 1114 | */ |
|---|
| 1115 | |
|---|
| 1116 | /* Write handler. */ |
|---|
| 1117 | yaml_writer_t *writer; |
|---|
| 1118 | |
|---|
| 1119 | /* A pointer for passing to the white handler. */ |
|---|
| 1120 | void *writer_data; |
|---|
| 1121 | |
|---|
| 1122 | /* Standard (string or file) output data. */ |
|---|
| 1123 | yaml_standard_writer_data_t standard_writer_data; |
|---|
| 1124 | |
|---|
| 1125 | /* The working buffer. */ |
|---|
| 1126 | yaml_iostring_t output; |
|---|
| 1127 | |
|---|
| 1128 | /* The raw buffer. */ |
|---|
| 1129 | yaml_raw_iostring_t raw_output; |
|---|
| 1130 | |
|---|
| 1131 | /* The offset of the current position (in bytes). */ |
|---|
| 1132 | size_t offset; |
|---|
| 1133 | |
|---|
| 1134 | /* The stream encoding. */ |
|---|
| 1135 | yaml_encoding_t encoding; |
|---|
| 1136 | |
|---|
| 1137 | /* |
|---|
| 1138 | * Emitter stuff. |
|---|
| 1139 | */ |
|---|
| 1140 | |
|---|
| 1141 | /* If the output is in the canonical style? */ |
|---|
| 1142 | int is_canonical; |
|---|
| 1143 | /* The number of indentation spaces. */ |
|---|
| 1144 | int best_indent; |
|---|
| 1145 | /* The preferred width of the output lines. */ |
|---|
| 1146 | int best_width; |
|---|
| 1147 | /* Allow unescaped non-ASCII characters? */ |
|---|
| 1148 | int is_unicode; |
|---|
| 1149 | /* The preferred line break. */ |
|---|
| 1150 | yaml_break_t line_break; |
|---|
| 1151 | |
|---|
| 1152 | /* The stack of states. */ |
|---|
| 1153 | struct { |
|---|
| 1154 | yaml_emitter_state_t *list; |
|---|
| 1155 | size_t length; |
|---|
| 1156 | size_t capacity; |
|---|
| 1157 | } states; |
|---|
| 1158 | |
|---|
| 1159 | /* The current emitter state. */ |
|---|
| 1160 | yaml_emitter_state_t state; |
|---|
| 1161 | |
|---|
| 1162 | /* The event queue. */ |
|---|
| 1163 | struct { |
|---|
| 1164 | yaml_event_t *list; |
|---|
| 1165 | size_t head; |
|---|
| 1166 | size_t tail; |
|---|
| 1167 | size_t capacity; |
|---|
| 1168 | } events; |
|---|
| 1169 | |
|---|
| 1170 | /* The stack of indentation levels. */ |
|---|
| 1171 | struct { |
|---|
| 1172 | int *list; |
|---|
| 1173 | size_t length; |
|---|
| 1174 | size_t capacity; |
|---|
| 1175 | } indents; |
|---|
| 1176 | |
|---|
| 1177 | /* The list of tag directives. */ |
|---|
| 1178 | struct { |
|---|
| 1179 | yaml_tag_directive_t *list; |
|---|
| 1180 | size_t length; |
|---|
| 1181 | size_t capacity; |
|---|
| 1182 | } tag_directives; |
|---|
| 1183 | |
|---|
| 1184 | /* The current indentation level. */ |
|---|
| 1185 | int indent; |
|---|
| 1186 | |
|---|
| 1187 | /* The current flow level. */ |
|---|
| 1188 | int flow_level; |
|---|
| 1189 | |
|---|
| 1190 | /* Is it the document root context? */ |
|---|
| 1191 | int is_root_context; |
|---|
| 1192 | /* Is it a sequence context? */ |
|---|
| 1193 | int is_sequence_context; |
|---|
| 1194 | /* Is it a mapping context? */ |
|---|
| 1195 | int is_mapping_context; |
|---|
| 1196 | /* Is it a simple mapping key context? */ |
|---|
| 1197 | int is_simple_key_context; |
|---|
| 1198 | |
|---|
| 1199 | /* The current line. */ |
|---|
| 1200 | int line; |
|---|
| 1201 | /* The current column. */ |
|---|
| 1202 | int column; |
|---|
| 1203 | /* If the last character was a whitespace? */ |
|---|
| 1204 | int is_whitespace; |
|---|
| 1205 | /* If the last character was an indentation character (' ', '-', '?', ':')? */ |
|---|
| 1206 | int is_indention; |
|---|
| 1207 | |
|---|
| 1208 | /* Anchor analysis. */ |
|---|
| 1209 | struct { |
|---|
| 1210 | /* The anchor value. */ |
|---|
| 1211 | const yaml_char_t *anchor; |
|---|
| 1212 | /* The anchor length. */ |
|---|
| 1213 | size_t anchor_length; |
|---|
| 1214 | /* Is it an alias? */ |
|---|
| 1215 | int is_alias; |
|---|
| 1216 | } anchor_data; |
|---|
| 1217 | |
|---|
| 1218 | /* Tag analysis. */ |
|---|
| 1219 | struct { |
|---|
| 1220 | /* The tag handle. */ |
|---|
| 1221 | const yaml_char_t *handle; |
|---|
| 1222 | /* The tag handle length. */ |
|---|
| 1223 | size_t handle_length; |
|---|
| 1224 | /* The tag suffix. */ |
|---|
| 1225 | const yaml_char_t *suffix; |
|---|
| 1226 | /* The tag suffix length. */ |
|---|
| 1227 | size_t suffix_length; |
|---|
| 1228 | } tag_data; |
|---|
| 1229 | |
|---|
| 1230 | /* Scalar analysis. */ |
|---|
| 1231 | struct { |
|---|
| 1232 | /* The scalar value. */ |
|---|
| 1233 | const yaml_char_t *value; |
|---|
| 1234 | /* The scalar length. */ |
|---|
| 1235 | size_t length; |
|---|
| 1236 | /* Does the scalar contain line breaks? */ |
|---|
| 1237 | int is_multiline; |
|---|
| 1238 | /* Can the scalar be expessed in the flow plain style? */ |
|---|
| 1239 | int is_flow_plain_allowed; |
|---|
| 1240 | /* Can the scalar be expressed in the block plain style? */ |
|---|
| 1241 | int is_block_plain_allowed; |
|---|
| 1242 | /* Can the scalar be expressed in the single quoted style? */ |
|---|
| 1243 | int is_single_quoted_allowed; |
|---|
| 1244 | /* Can the scalar be expressed in the literal or folded styles? */ |
|---|
| 1245 | int is_block_allowed; |
|---|
| 1246 | /* The output style. */ |
|---|
| 1247 | yaml_scalar_style_t style; |
|---|
| 1248 | } scalar_data; |
|---|
| 1249 | |
|---|
| 1250 | /* |
|---|
| 1251 | * Dumper stuff. |
|---|
| 1252 | */ |
|---|
| 1253 | |
|---|
| 1254 | /* If the stream was already opened? */ |
|---|
| 1255 | int is_opened; |
|---|
| 1256 | /* If the stream was already closed? */ |
|---|
| 1257 | int is_closed; |
|---|
| 1258 | |
|---|
| 1259 | /* The information associated with the document nodes. */ |
|---|
| 1260 | struct { |
|---|
| 1261 | /* The number of references. */ |
|---|
| 1262 | size_t references; |
|---|
| 1263 | /* The anchor id. */ |
|---|
| 1264 | int anchor; |
|---|
| 1265 | /* If the node has been emitted? */ |
|---|
| 1266 | int is_serialized; |
|---|
| 1267 | } *anchors; |
|---|
| 1268 | |
|---|
| 1269 | /* The last assigned anchor id. */ |
|---|
| 1270 | int last_anchor_id; |
|---|
| 1271 | |
|---|
| 1272 | /* The currently emitted document. */ |
|---|
| 1273 | yaml_document_t *document; |
|---|
| 1274 | |
|---|
| 1275 | }; |
|---|
| 1276 | |
|---|
| 1277 | /* |
|---|
| 1278 | * Reader: Ensure that the buffer contains at least `length` characters. |
|---|
| 1279 | */ |
|---|
| 1280 | |
|---|
| 1281 | YAML_DECLARE(int) |
|---|
| 1282 | yaml_parser_update_buffer(yaml_parser_t *parser, size_t length); |
|---|
| 1283 | |
|---|
| 1284 | /* |
|---|
| 1285 | * Scanner: Ensure that the token stack contains at least one token ready. |
|---|
| 1286 | */ |
|---|
| 1287 | |
|---|
| 1288 | YAML_DECLARE(int) |
|---|
| 1289 | yaml_parser_fetch_more_tokens(yaml_parser_t *parser); |
|---|
| 1290 | |
|---|