| [172] | 1 | /** |
|---|
| 2 | * @file yaml.h |
|---|
| 3 | * @brief Public interface for libyaml. |
|---|
| 4 | * |
|---|
| [178] | 5 | * Include the header file with the code: |
|---|
| [172] | 6 | * @code |
|---|
| 7 | * #include <yaml/yaml.h> |
|---|
| 8 | * @endcode |
|---|
| 9 | */ |
|---|
| [162] | 10 | |
|---|
| [169] | 11 | #ifndef YAML_H |
|---|
| 12 | #define YAML_H |
|---|
| [162] | 13 | |
|---|
| 14 | #ifdef __cplusplus |
|---|
| 15 | extern "C" { |
|---|
| 16 | #endif |
|---|
| 17 | |
|---|
| [169] | 18 | #include <stdlib.h> |
|---|
| [179] | 19 | #include <stdio.h> |
|---|
| 20 | #include <string.h> |
|---|
| [162] | 21 | |
|---|
| [178] | 22 | /** |
|---|
| [184] | 23 | * @defgroup export Export Definitions |
|---|
| [183] | 24 | * @{ |
|---|
| 25 | */ |
|---|
| 26 | |
|---|
| 27 | /** The public API declaration. */ |
|---|
| 28 | |
|---|
| 29 | #ifdef WIN32 |
|---|
| 30 | # if defined(YAML_DECLARE_STATIC) |
|---|
| 31 | # define YAML_DECLARE(type) type |
|---|
| 32 | # elif defined(YAML_DECLARE_EXPORT) |
|---|
| 33 | # define YAML_DECLARE(type) __declspec(dllexport) type |
|---|
| 34 | # else |
|---|
| 35 | # define YAML_DECLARE(type) __declspec(dllimport) type |
|---|
| 36 | # endif |
|---|
| 37 | #else |
|---|
| 38 | # define YAML_DECLARE(type) type |
|---|
| 39 | #endif |
|---|
| 40 | |
|---|
| 41 | /** @} */ |
|---|
| 42 | |
|---|
| 43 | /** |
|---|
| [178] | 44 | * @defgroup version Version Information |
|---|
| 45 | * @{ |
|---|
| 46 | */ |
|---|
| [169] | 47 | |
|---|
| [178] | 48 | /** |
|---|
| 49 | * Get the library version as a string. |
|---|
| 50 | * |
|---|
| 51 | * @returns The function returns the pointer to a static string of the form |
|---|
| 52 | * @c "X.Y.Z", where @c X is the major version number, @c Y is a minor version |
|---|
| 53 | * number, and @c Z is the patch version number. |
|---|
| 54 | */ |
|---|
| 55 | |
|---|
| [183] | 56 | YAML_DECLARE(const char *) |
|---|
| [178] | 57 | yaml_get_version_string(void); |
|---|
| 58 | |
|---|
| 59 | /** |
|---|
| 60 | * Get the library version numbers. |
|---|
| 61 | * |
|---|
| 62 | * @param[out] major Major version number. |
|---|
| 63 | * @param[out] minor Minor version number. |
|---|
| 64 | * @param[out] patch Patch version number. |
|---|
| 65 | */ |
|---|
| 66 | |
|---|
| [183] | 67 | YAML_DECLARE(void) |
|---|
| [178] | 68 | yaml_get_version(int *major, int *minor, int *patch); |
|---|
| 69 | |
|---|
| 70 | /** @} */ |
|---|
| 71 | |
|---|
| 72 | /** |
|---|
| 73 | * @defgroup basic Basic Types |
|---|
| 74 | * @{ |
|---|
| 75 | */ |
|---|
| 76 | |
|---|
| [183] | 77 | /** The character type (UTF-8 octet). */ |
|---|
| [178] | 78 | typedef unsigned char yaml_char_t; |
|---|
| 79 | |
|---|
| 80 | /** The stream encoding. */ |
|---|
| [162] | 81 | typedef enum { |
|---|
| [178] | 82 | YAML_ANY_ENCODING, |
|---|
| [162] | 83 | YAML_UTF8_ENCODING, |
|---|
| 84 | YAML_UTF16LE_ENCODING, |
|---|
| 85 | YAML_UTF16BE_ENCODING |
|---|
| 86 | } yaml_encoding_t; |
|---|
| 87 | |
|---|
| [179] | 88 | /** Many bad things could happen with the parser and emitter. */ |
|---|
| [162] | 89 | typedef enum { |
|---|
| [178] | 90 | YAML_NO_ERROR, |
|---|
| 91 | |
|---|
| 92 | YAML_MEMORY_ERROR, |
|---|
| 93 | |
|---|
| 94 | YAML_READER_ERROR, |
|---|
| 95 | YAML_SCANNER_ERROR, |
|---|
| 96 | YAML_PARSER_ERROR, |
|---|
| 97 | |
|---|
| 98 | YAML_WRITER_ERROR, |
|---|
| 99 | YAML_EMITTER_ERROR |
|---|
| 100 | } yaml_error_type_t; |
|---|
| 101 | |
|---|
| [183] | 102 | /** The pointer position. */ |
|---|
| 103 | typedef struct { |
|---|
| 104 | /** The position index. */ |
|---|
| 105 | size_t index; |
|---|
| 106 | |
|---|
| 107 | /** The position line. */ |
|---|
| 108 | size_t line; |
|---|
| 109 | |
|---|
| 110 | /** The position column. */ |
|---|
| 111 | size_t column; |
|---|
| 112 | } yaml_mark_t; |
|---|
| 113 | |
|---|
| [179] | 114 | /** @} */ |
|---|
| 115 | |
|---|
| [183] | 116 | /** |
|---|
| [184] | 117 | * @defgroup styles Node Styles |
|---|
| [183] | 118 | * @{ |
|---|
| 119 | */ |
|---|
| [179] | 120 | |
|---|
| [183] | 121 | /** Scalar styles. */ |
|---|
| [178] | 122 | typedef enum { |
|---|
| [169] | 123 | YAML_ANY_SCALAR_STYLE, |
|---|
| [183] | 124 | |
|---|
| [162] | 125 | YAML_PLAIN_SCALAR_STYLE, |
|---|
| [183] | 126 | |
|---|
| [162] | 127 | YAML_SINGLE_QUOTED_SCALAR_STYLE, |
|---|
| 128 | YAML_DOUBLE_QUOTED_SCALAR_STYLE, |
|---|
| [183] | 129 | |
|---|
| [162] | 130 | YAML_LITERAL_SCALAR_STYLE, |
|---|
| 131 | YAML_FOLDED_SCALAR_STYLE |
|---|
| 132 | } yaml_scalar_style_t; |
|---|
| 133 | |
|---|
| [183] | 134 | |
|---|
| 135 | /** Sequence styles. */ |
|---|
| [162] | 136 | typedef enum { |
|---|
| [169] | 137 | YAML_ANY_SEQUENCE_STYLE, |
|---|
| [183] | 138 | |
|---|
| [162] | 139 | YAML_BLOCK_SEQUENCE_STYLE, |
|---|
| 140 | YAML_FLOW_SEQUENCE_STYLE |
|---|
| 141 | } yaml_sequence_style_t; |
|---|
| 142 | |
|---|
| [183] | 143 | /** Mapping styles. */ |
|---|
| [162] | 144 | typedef enum { |
|---|
| [169] | 145 | YAML_ANY_MAPPING_STYLE, |
|---|
| [183] | 146 | |
|---|
| [162] | 147 | YAML_BLOCK_MAPPING_STYLE, |
|---|
| 148 | YAML_FLOW_MAPPING_STYLE |
|---|
| 149 | } yaml_mapping_style_t; |
|---|
| 150 | |
|---|
| [183] | 151 | /** @} */ |
|---|
| 152 | |
|---|
| 153 | /** |
|---|
| [184] | 154 | * @defgroup tokens Tokens |
|---|
| [183] | 155 | * @{ |
|---|
| 156 | */ |
|---|
| 157 | |
|---|
| 158 | /** Token types. */ |
|---|
| [162] | 159 | typedef enum { |
|---|
| 160 | YAML_STREAM_START_TOKEN, |
|---|
| 161 | YAML_STREAM_END_TOKEN, |
|---|
| [169] | 162 | |
|---|
| [162] | 163 | YAML_VERSION_DIRECTIVE_TOKEN, |
|---|
| 164 | YAML_TAG_DIRECTIVE_TOKEN, |
|---|
| 165 | YAML_DOCUMENT_START_TOKEN, |
|---|
| 166 | YAML_DOCUMENT_END_TOKEN, |
|---|
| [169] | 167 | |
|---|
| [162] | 168 | YAML_BLOCK_SEQUENCE_START_TOKEN, |
|---|
| 169 | YAML_BLOCK_MAPPING_START_TOKEN, |
|---|
| 170 | YAML_BLOCK_END_TOKEN, |
|---|
| [169] | 171 | |
|---|
| [162] | 172 | YAML_FLOW_SEQUENCE_START_TOKEN, |
|---|
| 173 | YAML_FLOW_SEQUENCE_END_TOKEN, |
|---|
| 174 | YAML_FLOW_MAPPING_START_TOKEN, |
|---|
| 175 | YAML_FLOW_MAPPING_END_TOKEN, |
|---|
| [169] | 176 | |
|---|
| [162] | 177 | YAML_BLOCK_ENTRY_TOKEN, |
|---|
| 178 | YAML_FLOW_ENTRY_TOKEN, |
|---|
| 179 | YAML_KEY_TOKEN, |
|---|
| 180 | YAML_VALUE_TOKEN, |
|---|
| [169] | 181 | |
|---|
| [162] | 182 | YAML_ALIAS_TOKEN, |
|---|
| 183 | YAML_ANCHOR_TOKEN, |
|---|
| 184 | YAML_TAG_TOKEN, |
|---|
| 185 | YAML_SCALAR_TOKEN |
|---|
| 186 | } yaml_token_type_t; |
|---|
| 187 | |
|---|
| [183] | 188 | /** The token structure. */ |
|---|
| 189 | typedef struct { |
|---|
| [169] | 190 | |
|---|
| [183] | 191 | /** The token type. */ |
|---|
| 192 | yaml_token_type_t type; |
|---|
| [169] | 193 | |
|---|
| [183] | 194 | /** The token data. */ |
|---|
| 195 | union { |
|---|
| [169] | 196 | |
|---|
| [183] | 197 | /** The stream encoding (for @c YAML_STREAM_START_TOKEN). */ |
|---|
| 198 | yaml_encoding_t encoding; |
|---|
| [169] | 199 | |
|---|
| [183] | 200 | /** The anchor (for @c YAML_ALIAS_TOKEN and @c YAML_ANCHOR_TOKEN). */ |
|---|
| 201 | yaml_char_t *anchor; |
|---|
| [162] | 202 | |
|---|
| [183] | 203 | /** The tag (for @c YAML_TAG_TOKEN). */ |
|---|
| 204 | struct { |
|---|
| 205 | /** The tag handle. */ |
|---|
| 206 | yaml_char_t *handle; |
|---|
| [162] | 207 | |
|---|
| [183] | 208 | /** The tag suffix. */ |
|---|
| 209 | yaml_char_t *suffix; |
|---|
| 210 | } tag; |
|---|
| [162] | 211 | |
|---|
| [183] | 212 | /** The scalar value (for @c YAML_SCALAR_TOKEN). */ |
|---|
| [162] | 213 | struct { |
|---|
| [183] | 214 | |
|---|
| 215 | /** The scalar value. */ |
|---|
| 216 | yaml_char_t *value; |
|---|
| 217 | |
|---|
| 218 | /** The length of the scalar value. */ |
|---|
| [169] | 219 | size_t length; |
|---|
| [183] | 220 | |
|---|
| 221 | /** The scalar style. */ |
|---|
| [162] | 222 | yaml_scalar_style_t style; |
|---|
| 223 | } scalar; |
|---|
| [183] | 224 | |
|---|
| 225 | /** The version directive (for @c YAML_VERSION_DIRECTIVE_TOKEN). */ |
|---|
| [162] | 226 | struct { |
|---|
| [183] | 227 | /** The major version number. */ |
|---|
| [162] | 228 | int major; |
|---|
| [183] | 229 | |
|---|
| 230 | /** The minor version number. */ |
|---|
| [162] | 231 | int minor; |
|---|
| [183] | 232 | } version_directive; |
|---|
| 233 | |
|---|
| 234 | /** The tag directive (for @c YAML_TAG_DIRECTIVE_TOKEN). */ |
|---|
| [162] | 235 | struct { |
|---|
| [183] | 236 | /** The tag handle. */ |
|---|
| 237 | yaml_char_t *handle; |
|---|
| 238 | |
|---|
| 239 | /** The tag prefix. */ |
|---|
| 240 | yaml_char_t *prefix; |
|---|
| 241 | } tag_directive; |
|---|
| [162] | 242 | } data; |
|---|
| [183] | 243 | |
|---|
| 244 | /** The beginning of the token. */ |
|---|
| [162] | 245 | yaml_mark_t start_mark; |
|---|
| [183] | 246 | |
|---|
| 247 | /** The end of the token. */ |
|---|
| [162] | 248 | yaml_mark_t end_mark; |
|---|
| [183] | 249 | |
|---|
| [162] | 250 | } yaml_token_t; |
|---|
| 251 | |
|---|
| [183] | 252 | /** |
|---|
| 253 | * Create a new token without assigning any data. |
|---|
| 254 | * |
|---|
| 255 | * This function can be used for constructing indicator tokens: |
|---|
| 256 | * @c YAML_DOCUMENT_START, @c YAML_DOCUMENT_END, |
|---|
| 257 | * @c YAML_BLOCK_SEQUENCE_START_TOKEN, @c YAML_BLOCK_MAPPING_START_TOKEN, |
|---|
| 258 | * @c YAML_BLOCK_END_TOKEN, |
|---|
| 259 | * @c YAML_FLOW_SEQUENCE_START_TOKEN, @c YAML_FLOW_SEQUENCE_END_TOKEN, |
|---|
| 260 | * @c YAML_FLOW_MAPPING_START_TOKEN, @c YAML_FLOW_MAPPING_END_TOKEN, |
|---|
| 261 | * @c YAML_BLOCK_ENTRY_TOKEN, @c YAML_FLOW_ENTRY_TOKEN, |
|---|
| 262 | * @c YAML_KEY_TOKEN, @c YAML_VALUE_TOKEN. |
|---|
| 263 | * |
|---|
| 264 | * @param[in] type The token type. |
|---|
| 265 | * @param[in] start_mark The beginning of the token. |
|---|
| 266 | * @param[in] end_mark The end of the token. |
|---|
| 267 | * |
|---|
| 268 | * @returns A new token object, or @c NULL on error. |
|---|
| 269 | */ |
|---|
| 270 | |
|---|
| 271 | YAML_DECLARE(yaml_token_t *) |
|---|
| 272 | yaml_token_new(yaml_token_type_t type, |
|---|
| 273 | yaml_mark_t start_mark, yaml_mark_t end_mark); |
|---|
| 274 | |
|---|
| 275 | /** |
|---|
| 276 | * Create a new @c YAML_STREAM_START_TOKEN token with the specified encoding. |
|---|
| 277 | * |
|---|
| 278 | * @param[in] encoding The stream encoding. |
|---|
| 279 | * @param[in] start_mark The beginning of the token. |
|---|
| 280 | * @param[in] end_mark The end of the token. |
|---|
| 281 | * |
|---|
| 282 | * @returns A new token object, or @c NULL on error. |
|---|
| 283 | */ |
|---|
| 284 | |
|---|
| 285 | YAML_DECLARE(yaml_token_t *) |
|---|
| 286 | yaml_stream_start_token_new(yaml_encoding_t encoding, |
|---|
| 287 | yaml_mark_t start_mark, yaml_mark_t end_mark); |
|---|
| 288 | |
|---|
| 289 | /** |
|---|
| 290 | * Create a new @c YAML_STREAM_END_TOKEN token. |
|---|
| 291 | * |
|---|
| 292 | * @param[in] start_mark The beginning of the token. |
|---|
| 293 | * @param[in] end_mark The end of the token. |
|---|
| 294 | * |
|---|
| 295 | * @returns A new token object, or @c NULL on error. |
|---|
| 296 | */ |
|---|
| 297 | |
|---|
| 298 | YAML_DECLARE(yaml_token_t *) |
|---|
| 299 | yaml_stream_end_token_new(yaml_mark_t start_mark, yaml_mark_t end_mark); |
|---|
| 300 | |
|---|
| 301 | /** |
|---|
| 302 | * Create a new @c YAML_VERSION_DIRECTIVE_TOKEN token with the specified |
|---|
| 303 | * version numbers. |
|---|
| 304 | * |
|---|
| 305 | * @param[in] major The major version number. |
|---|
| 306 | * @param[in] minor The minor version number. |
|---|
| 307 | * @param[in] start_mark The beginning of the token. |
|---|
| 308 | * @param[in] end_mark The end of the token. |
|---|
| 309 | * |
|---|
| 310 | * @returns A new token object, or @c NULL on error. |
|---|
| 311 | */ |
|---|
| 312 | |
|---|
| 313 | YAML_DECLARE(yaml_token_t *) |
|---|
| 314 | yaml_version_directive_token_new(int major, int minor, |
|---|
| 315 | yaml_mark_t start_mark, yaml_mark_t end_mark); |
|---|
| 316 | |
|---|
| 317 | /** |
|---|
| 318 | * Create a new @c YAML_TAG_DIRECTIVE_TOKEN token with the specified tag |
|---|
| 319 | * handle and prefix. |
|---|
| 320 | * |
|---|
| 321 | * Note that the @a handle and the @a prefix pointers will be freed by |
|---|
| 322 | * the token descructor. |
|---|
| 323 | * |
|---|
| 324 | * @param[in] handle The tag handle. |
|---|
| 325 | * @param[in] prefix The tag prefix. |
|---|
| 326 | * @param[in] start_mark The beginning of the token. |
|---|
| 327 | * @param[in] end_mark The end of the token. |
|---|
| 328 | * |
|---|
| 329 | * @returns A new token object, or @c NULL on error. |
|---|
| 330 | */ |
|---|
| 331 | |
|---|
| 332 | YAML_DECLARE(yaml_token_t *) |
|---|
| 333 | yaml_tag_directive_token_new(yaml_char_t *handle, yaml_char_t *prefix, |
|---|
| 334 | yaml_mark_t start_mark, yaml_mark_t end_mark); |
|---|
| 335 | |
|---|
| 336 | /** |
|---|
| 337 | * Create a new @c YAML_ALIAS_TOKEN token with the specified anchor. |
|---|
| 338 | * |
|---|
| 339 | * Note that the @a anchor pointer will be freed by the token descructor. |
|---|
| 340 | * |
|---|
| 341 | * @param[in] anchor The anchor. |
|---|
| 342 | * @param[in] start_mark The beginning of the token. |
|---|
| 343 | * @param[in] end_mark The end of the token. |
|---|
| 344 | * |
|---|
| 345 | * @returns A new token object, or @c NULL on error. |
|---|
| 346 | */ |
|---|
| 347 | |
|---|
| 348 | YAML_DECLARE(yaml_token_t *) |
|---|
| 349 | yaml_alias_token_new(yaml_char_t *anchor, |
|---|
| 350 | yaml_mark_t start_mark, yaml_mark_t end_mark); |
|---|
| 351 | |
|---|
| 352 | /** |
|---|
| 353 | * Create a new @c YAML_ANCHOR_TOKEN token with the specified anchor. |
|---|
| 354 | * |
|---|
| 355 | * Note that the @a anchor pointer will be freed by the token descructor. |
|---|
| 356 | * |
|---|
| 357 | * @param[in] anchor The anchor. |
|---|
| 358 | * @param[in] start_mark The beginning of the token. |
|---|
| 359 | * @param[in] end_mark The end of the token. |
|---|
| 360 | * |
|---|
| 361 | * @returns A new token object, or @c NULL on error. |
|---|
| 362 | */ |
|---|
| 363 | |
|---|
| 364 | YAML_DECLARE(yaml_token_t *) |
|---|
| 365 | yaml_anchor_token_new(yaml_char_t *anchor, |
|---|
| 366 | yaml_mark_t start_mark, yaml_mark_t end_mark); |
|---|
| 367 | |
|---|
| 368 | /** |
|---|
| 369 | * Create a new @c YAML_TAG_TOKEN token with the specified tag handle and |
|---|
| 370 | * suffix. |
|---|
| 371 | * |
|---|
| 372 | * Note that the @a handle and the @a suffix pointers will be freed by |
|---|
| 373 | * the token descructor. |
|---|
| 374 | * |
|---|
| 375 | * @param[in] handle The tag handle. |
|---|
| 376 | * @param[in] suffix The tag suffix. |
|---|
| 377 | * @param[in] start_mark The beginning of the token. |
|---|
| 378 | * @param[in] end_mark The end of the token. |
|---|
| 379 | * |
|---|
| 380 | * @returns A new token object, or @c NULL on error. |
|---|
| 381 | */ |
|---|
| 382 | |
|---|
| 383 | YAML_DECLARE(yaml_token_t *) |
|---|
| 384 | yaml_tag_token_new(yaml_char_t *handle, yaml_char_t *suffix, |
|---|
| 385 | yaml_mark_t start_mark, yaml_mark_t end_mark); |
|---|
| 386 | |
|---|
| 387 | /** |
|---|
| 388 | * Create a new @c YAML_SCALAR_TOKEN token with the specified scalar value, |
|---|
| 389 | * length, and style. |
|---|
| 390 | * |
|---|
| 391 | * Note that the scalar value may contain the @c NUL character, therefore |
|---|
| 392 | * the value length is also required. The scalar value always ends with |
|---|
| 393 | * @c NUL. |
|---|
| 394 | * |
|---|
| 395 | * Note that the @a value pointer will be freed by the token descructor. |
|---|
| 396 | * |
|---|
| 397 | * @param[in] value The scalar value. |
|---|
| 398 | * @param[in] length The value length. |
|---|
| 399 | * @param[in] style The scalar style. |
|---|
| 400 | * @param[in] start_mark The beginning of the token. |
|---|
| 401 | * @param[in] end_mark The end of the token. |
|---|
| 402 | * |
|---|
| 403 | * @returns A new token object, or @c NULL on error. |
|---|
| 404 | */ |
|---|
| 405 | |
|---|
| 406 | YAML_DECLARE(yaml_token_t *) |
|---|
| 407 | yaml_scalar_token_new(yaml_char_t *value, size_t length, |
|---|
| 408 | yaml_scalar_style_t style, |
|---|
| 409 | yaml_mark_t start_mark, yaml_mark_t end_mark); |
|---|
| 410 | |
|---|
| 411 | /** |
|---|
| 412 | * Destroy a token object. |
|---|
| 413 | * |
|---|
| 414 | * @param[in] token A token object. |
|---|
| 415 | */ |
|---|
| 416 | |
|---|
| 417 | YAML_DECLARE(void) |
|---|
| 418 | yaml_token_delete(yaml_token_t *token); |
|---|
| 419 | |
|---|
| 420 | /** @} */ |
|---|
| 421 | |
|---|
| 422 | /* |
|---|
| 423 | |
|---|
| 424 | typedef enum { |
|---|
| 425 | YAML_STREAM_START_EVENT, |
|---|
| 426 | YAML_STREAM_END_EVENT, |
|---|
| 427 | |
|---|
| 428 | YAML_DOCUMENT_START_EVENT, |
|---|
| 429 | YAML_DOCUMENT_END_EVENT, |
|---|
| 430 | |
|---|
| 431 | YAML_ALIAS_EVENT, |
|---|
| 432 | YAML_SCALAR_EVENT, |
|---|
| 433 | |
|---|
| 434 | YAML_SEQUENCE_START_EVENT, |
|---|
| 435 | YAML_SEQUENCE_END_EVENT, |
|---|
| 436 | |
|---|
| 437 | YAML_MAPPING_START_EVENT, |
|---|
| 438 | YAML_MAPPING_END_EVENT |
|---|
| 439 | } yaml_event_type_t; |
|---|
| 440 | |
|---|
| [162] | 441 | typedef struct { |
|---|
| 442 | yaml_event_type_t type; |
|---|
| 443 | union { |
|---|
| 444 | struct { |
|---|
| 445 | yaml_encoding_t encoding; |
|---|
| 446 | } stream_start; |
|---|
| 447 | struct { |
|---|
| 448 | struct { |
|---|
| 449 | int major; |
|---|
| 450 | int minor; |
|---|
| 451 | } version; |
|---|
| 452 | struct { |
|---|
| [169] | 453 | char *handle; |
|---|
| 454 | char *prefix; |
|---|
| [162] | 455 | } **tag_pairs; |
|---|
| 456 | int implicit; |
|---|
| 457 | } document_start; |
|---|
| 458 | struct { |
|---|
| 459 | int implicit; |
|---|
| 460 | } document_end; |
|---|
| 461 | struct { |
|---|
| [169] | 462 | char *anchor; |
|---|
| [162] | 463 | } alias; |
|---|
| 464 | struct { |
|---|
| [169] | 465 | char *anchor; |
|---|
| 466 | char *tag; |
|---|
| 467 | char *value; |
|---|
| 468 | size_t length; |
|---|
| [162] | 469 | int plain_implicit; |
|---|
| 470 | int quoted_implicit; |
|---|
| 471 | yaml_scalar_style_t style; |
|---|
| 472 | } scalar; |
|---|
| 473 | struct { |
|---|
| [169] | 474 | char *anchor; |
|---|
| 475 | char *tag; |
|---|
| [162] | 476 | int implicit; |
|---|
| 477 | yaml_sequence_style_t style; |
|---|
| 478 | } sequence_start; |
|---|
| 479 | struct { |
|---|
| [169] | 480 | char *anchor; |
|---|
| 481 | char *tag; |
|---|
| [162] | 482 | int implicit; |
|---|
| 483 | yaml_mapping_style_t style; |
|---|
| 484 | } mapping_start; |
|---|
| 485 | } data; |
|---|
| 486 | yaml_mark_t start_mark; |
|---|
| 487 | yaml_mark_t end_mark; |
|---|
| 488 | } yaml_event_t; |
|---|
| 489 | |
|---|
| [178] | 490 | */ |
|---|
| 491 | |
|---|
| 492 | |
|---|
| 493 | /** |
|---|
| 494 | * @defgroup parser Parser Definitions |
|---|
| 495 | * @{ |
|---|
| 496 | */ |
|---|
| 497 | |
|---|
| 498 | /** |
|---|
| 499 | * The prototype of a read handler. |
|---|
| 500 | * |
|---|
| 501 | * The read handler is called when the parser needs to read more bytes from the |
|---|
| 502 | * source. The handler should write not more than @a size bytes to the @a |
|---|
| 503 | * buffer. The number of written bytes should be set to the @a length variable. |
|---|
| 504 | * |
|---|
| [180] | 505 | * @param[in] data A pointer to an application data specified by |
|---|
| [179] | 506 | * @c yaml_parser_set_read_handler. |
|---|
| 507 | * @param[out] buffer The buffer to write the data from the source. |
|---|
| 508 | * @param[in] size The size of the buffer. |
|---|
| 509 | * @param[out] size_read The actual number of bytes read from the source. |
|---|
| [178] | 510 | * |
|---|
| 511 | * @returns On success, the handler should return @c 1. If the handler failed, |
|---|
| 512 | * the returned value should be @c 0. On EOF, the handler should set the |
|---|
| 513 | * @a length to @c 0 and return @c 1. |
|---|
| 514 | */ |
|---|
| [180] | 515 | |
|---|
| 516 | typedef int yaml_read_handler_t(void *data, unsigned char *buffer, size_t size, |
|---|
| [179] | 517 | size_t *size_read); |
|---|
| [178] | 518 | |
|---|
| 519 | /** |
|---|
| [180] | 520 | * This structure holds a string input specified by |
|---|
| 521 | * @c yaml_parser_set_input_string. |
|---|
| 522 | */ |
|---|
| 523 | |
|---|
| 524 | typedef struct { |
|---|
| [183] | 525 | /** The string start pointer. */ |
|---|
| [180] | 526 | unsigned char *start; |
|---|
| [183] | 527 | |
|---|
| 528 | /** The string end pointer. */ |
|---|
| [180] | 529 | unsigned char *end; |
|---|
| [183] | 530 | |
|---|
| 531 | /** The string current position. */ |
|---|
| [180] | 532 | unsigned char *current; |
|---|
| 533 | } yaml_string_input_t; |
|---|
| 534 | |
|---|
| 535 | /** |
|---|
| [184] | 536 | * This structure holds information about a potential simple key. |
|---|
| 537 | */ |
|---|
| 538 | |
|---|
| 539 | typedef struct { |
|---|
| 540 | /** Is a simple key required? */ |
|---|
| 541 | int required; |
|---|
| 542 | |
|---|
| 543 | /** The number of the token. */ |
|---|
| 544 | size_t token_number; |
|---|
| 545 | |
|---|
| 546 | /** The position index. */ |
|---|
| 547 | size_t index; |
|---|
| 548 | |
|---|
| 549 | /** The position line. */ |
|---|
| 550 | size_t line; |
|---|
| 551 | |
|---|
| 552 | /** The position column. */ |
|---|
| 553 | size_t column; |
|---|
| 554 | |
|---|
| 555 | /** The position mark. */ |
|---|
| 556 | yaml_mark_t mark; |
|---|
| 557 | } yaml_simple_key_t; |
|---|
| 558 | |
|---|
| 559 | /** |
|---|
| [178] | 560 | * The parser structure. |
|---|
| 561 | * |
|---|
| 562 | * All members are internal. Manage the structure using the @c yaml_parser_ |
|---|
| 563 | * family of functions. |
|---|
| 564 | */ |
|---|
| 565 | |
|---|
| [162] | 566 | typedef struct { |
|---|
| [178] | 567 | |
|---|
| 568 | /** |
|---|
| [179] | 569 | * @name Error handling |
|---|
| 570 | * @{ |
|---|
| 571 | */ |
|---|
| 572 | |
|---|
| [181] | 573 | /** Error type. */ |
|---|
| [180] | 574 | yaml_error_type_t error; |
|---|
| [179] | 575 | |
|---|
| [181] | 576 | /** Error description. */ |
|---|
| 577 | const char *problem; |
|---|
| 578 | |
|---|
| 579 | /** The byte about which the problem occured. */ |
|---|
| 580 | size_t problem_offset; |
|---|
| 581 | |
|---|
| [182] | 582 | /** The problematic value (@c -1 is none). */ |
|---|
| 583 | int problem_value; |
|---|
| 584 | |
|---|
| [185] | 585 | /** The problem position. */ |
|---|
| 586 | yaml_mark_t problem_mark; |
|---|
| 587 | |
|---|
| 588 | /** The error context. */ |
|---|
| 589 | const char *context; |
|---|
| 590 | |
|---|
| 591 | /** The context position. */ |
|---|
| 592 | yaml_mark_t context_mark; |
|---|
| 593 | |
|---|
| [179] | 594 | /** |
|---|
| 595 | * @} |
|---|
| 596 | */ |
|---|
| 597 | |
|---|
| 598 | /** |
|---|
| [178] | 599 | * @name Reader stuff |
|---|
| 600 | * @{ |
|---|
| 601 | */ |
|---|
| 602 | |
|---|
| [181] | 603 | /** Read handler. */ |
|---|
| [179] | 604 | yaml_read_handler_t *read_handler; |
|---|
| [178] | 605 | |
|---|
| 606 | /** A pointer for passing to the read handler. */ |
|---|
| [179] | 607 | void *read_handler_data; |
|---|
| [178] | 608 | |
|---|
| 609 | /** EOF flag */ |
|---|
| 610 | int eof; |
|---|
| 611 | |
|---|
| 612 | /** The pointer to the beginning of the working buffer. */ |
|---|
| 613 | yaml_char_t *buffer; |
|---|
| 614 | |
|---|
| [180] | 615 | /** The pointer to the end of the working buffer. */ |
|---|
| 616 | yaml_char_t *buffer_end; |
|---|
| [179] | 617 | |
|---|
| [178] | 618 | /** The pointer to the current character in the working buffer. */ |
|---|
| [180] | 619 | yaml_char_t *pointer; |
|---|
| [178] | 620 | |
|---|
| [180] | 621 | /** The number of unread characters in the working buffer. */ |
|---|
| 622 | size_t unread; |
|---|
| [179] | 623 | |
|---|
| [180] | 624 | /** The pointer to the beginning of the raw buffer. */ |
|---|
| [178] | 625 | unsigned char *raw_buffer; |
|---|
| 626 | |
|---|
| [180] | 627 | /** The pointer to the current character in the raw buffer. */ |
|---|
| 628 | unsigned char *raw_pointer; |
|---|
| [178] | 629 | |
|---|
| [180] | 630 | /** The number of unread bytes in the raw buffer. */ |
|---|
| 631 | size_t raw_unread; |
|---|
| [179] | 632 | |
|---|
| [178] | 633 | /** The input encoding. */ |
|---|
| 634 | yaml_encoding_t encoding; |
|---|
| 635 | |
|---|
| [179] | 636 | /** The offset of the current position (in bytes). */ |
|---|
| 637 | size_t offset; |
|---|
| 638 | |
|---|
| 639 | /** The index of the current position (in characters). */ |
|---|
| 640 | size_t index; |
|---|
| 641 | |
|---|
| 642 | /** The line of the current position (starting from @c 0). */ |
|---|
| 643 | size_t line; |
|---|
| 644 | |
|---|
| 645 | /** The column of the current position (starting from @c 0). */ |
|---|
| 646 | size_t column; |
|---|
| 647 | |
|---|
| [180] | 648 | /* String input structure. */ |
|---|
| 649 | yaml_string_input_t string_input; |
|---|
| 650 | |
|---|
| [178] | 651 | /** |
|---|
| 652 | * @} |
|---|
| 653 | */ |
|---|
| 654 | |
|---|
| [184] | 655 | /** |
|---|
| 656 | * @name Scanner stuff |
|---|
| 657 | * @{ |
|---|
| 658 | */ |
|---|
| 659 | |
|---|
| 660 | /** Have we started to scan the input stream? */ |
|---|
| 661 | int stream_start_produced; |
|---|
| 662 | |
|---|
| 663 | /** Have we reached the end of the input stream? */ |
|---|
| 664 | int stream_end_produced; |
|---|
| 665 | |
|---|
| 666 | /** The number of unclosed '[' and '{' indicators. */ |
|---|
| 667 | int flow_level; |
|---|
| 668 | |
|---|
| 669 | /** The tokens queue, which contains the current produced tokens. */ |
|---|
| [185] | 670 | yaml_token_t **tokens; |
|---|
| [184] | 671 | |
|---|
| 672 | /** The size of the tokens queue. */ |
|---|
| 673 | size_t tokens_size; |
|---|
| 674 | |
|---|
| 675 | /** The head of the tokens queue. */ |
|---|
| 676 | size_t tokens_head; |
|---|
| 677 | |
|---|
| 678 | /** The tail of the tokens queue. */ |
|---|
| 679 | size_t tokens_tail; |
|---|
| 680 | |
|---|
| 681 | /** The number of tokens fetched from the tokens queue. */ |
|---|
| 682 | size_t tokens_parsed; |
|---|
| 683 | |
|---|
| 684 | /** The stack of indentation levels. */ |
|---|
| 685 | int *indents; |
|---|
| 686 | |
|---|
| 687 | /** The size of the indents stack. */ |
|---|
| 688 | size_t indents_size; |
|---|
| 689 | |
|---|
| 690 | /** The number of items in the indents stack. */ |
|---|
| 691 | size_t indents_length; |
|---|
| 692 | |
|---|
| 693 | /** The current indentation level. */ |
|---|
| 694 | int indent; |
|---|
| 695 | |
|---|
| 696 | /** May a simple key occur at the current position? */ |
|---|
| 697 | int simple_key_allowed; |
|---|
| 698 | |
|---|
| 699 | /** The stack of potential simple keys. */ |
|---|
| [185] | 700 | yaml_simple_key_t **simple_keys; |
|---|
| [184] | 701 | |
|---|
| 702 | /** The size of the simple keys stack. */ |
|---|
| 703 | size_t simple_keys_size; |
|---|
| 704 | |
|---|
| 705 | /** |
|---|
| 706 | * @} |
|---|
| 707 | */ |
|---|
| 708 | |
|---|
| [162] | 709 | } yaml_parser_t; |
|---|
| 710 | |
|---|
| [178] | 711 | /** |
|---|
| 712 | * Create a new parser. |
|---|
| 713 | * |
|---|
| 714 | * This function creates a new parser object. An application is responsible |
|---|
| 715 | * for destroying the object using the @c yaml_parser_delete function. |
|---|
| 716 | * |
|---|
| 717 | * @returns A new parser object; @c NULL on error. |
|---|
| 718 | */ |
|---|
| 719 | |
|---|
| [183] | 720 | YAML_DECLARE(yaml_parser_t *) |
|---|
| [178] | 721 | yaml_parser_new(void); |
|---|
| 722 | |
|---|
| 723 | /** |
|---|
| 724 | * Destroy a parser. |
|---|
| 725 | * |
|---|
| 726 | * @param[in] parser A parser object. |
|---|
| 727 | */ |
|---|
| 728 | |
|---|
| [183] | 729 | YAML_DECLARE(void) |
|---|
| [178] | 730 | yaml_parser_delete(yaml_parser_t *parser); |
|---|
| 731 | |
|---|
| [179] | 732 | /** |
|---|
| 733 | * Set a string input. |
|---|
| 734 | * |
|---|
| 735 | * Note that the @a input pointer must be valid while the @a parser object |
|---|
| 736 | * exists. The application is responsible for destroing @a input after |
|---|
| 737 | * destroying the @a parser. |
|---|
| 738 | * |
|---|
| 739 | * @param[in] parser A parser object. |
|---|
| 740 | * @param[in] input A source data. |
|---|
| [183] | 741 | * @param[in] size The length of the source data in bytes. |
|---|
| [179] | 742 | */ |
|---|
| 743 | |
|---|
| [183] | 744 | YAML_DECLARE(void) |
|---|
| [179] | 745 | yaml_parser_set_input_string(yaml_parser_t *parser, |
|---|
| 746 | unsigned char *input, size_t size); |
|---|
| 747 | |
|---|
| 748 | |
|---|
| 749 | /** |
|---|
| 750 | * Set a file input. |
|---|
| 751 | * |
|---|
| 752 | * @a file should be a file object open for reading. The application is |
|---|
| 753 | * responsible for closing the @a file. |
|---|
| 754 | * |
|---|
| 755 | * @param[in] parser A parser object. |
|---|
| 756 | * @param[in] file An open file. |
|---|
| 757 | */ |
|---|
| 758 | |
|---|
| [183] | 759 | YAML_DECLARE(void) |
|---|
| [179] | 760 | yaml_parser_set_input_file(yaml_parser_t *parser, FILE *file); |
|---|
| 761 | |
|---|
| 762 | /** |
|---|
| 763 | * Set a generic input handler. |
|---|
| 764 | * |
|---|
| 765 | * @param[in] parser A parser object. |
|---|
| 766 | * @param[in] handler A read handler. |
|---|
| 767 | * @param[in] data Any application data for passing to the read handler. |
|---|
| 768 | */ |
|---|
| 769 | |
|---|
| [183] | 770 | YAML_DECLARE(void) |
|---|
| [179] | 771 | yaml_parser_set_input(yaml_parser_t *parser, |
|---|
| 772 | yaml_read_handler_t *handler, void *data); |
|---|
| 773 | |
|---|
| 774 | /** |
|---|
| 775 | * Set the source encoding. |
|---|
| 776 | * |
|---|
| [183] | 777 | * @param[in] parser A parser object. |
|---|
| [179] | 778 | * @param[in] encoding The source encoding. |
|---|
| 779 | */ |
|---|
| 780 | |
|---|
| [183] | 781 | YAML_DECLARE(void) |
|---|
| [179] | 782 | yaml_parser_set_encoding(yaml_parser_t *parser, yaml_encoding_t encoding); |
|---|
| 783 | |
|---|
| [184] | 784 | /** |
|---|
| 785 | * Get the next token. |
|---|
| 786 | * |
|---|
| 787 | * The token is removed from the internal token queue and the application is |
|---|
| 788 | * responsible for destroing the token object. |
|---|
| 789 | * |
|---|
| 790 | * @param[in] parser A parser object. |
|---|
| 791 | * |
|---|
| 792 | * @returns A token object, or @c NULL on error. |
|---|
| 793 | */ |
|---|
| 794 | |
|---|
| 795 | YAML_DECLARE(yaml_token_t *) |
|---|
| 796 | yaml_parser_get_token(yaml_parser_t *parser); |
|---|
| 797 | |
|---|
| 798 | /** |
|---|
| 799 | * Peek the next token. |
|---|
| 800 | * |
|---|
| 801 | * The token is not removed from the internal token queue and will be returned |
|---|
| 802 | * again on a subsequent call of @c yaml_parser_get_token or |
|---|
| 803 | * @c yaml_parser_peek_token. The application should not destroy the token |
|---|
| 804 | * object. |
|---|
| 805 | * |
|---|
| 806 | * @param[in] parser A parser object. |
|---|
| 807 | * |
|---|
| 808 | * @returns A token object, or @c NULL on error. |
|---|
| 809 | */ |
|---|
| 810 | |
|---|
| 811 | YAML_DECLARE(yaml_token_t *) |
|---|
| 812 | yaml_parser_peek_token(yaml_parser_t *parser); |
|---|
| 813 | |
|---|
| [178] | 814 | /** @} */ |
|---|
| 815 | |
|---|
| 816 | /* |
|---|
| [162] | 817 | typedef struct { |
|---|
| 818 | } yaml_emitter_t; |
|---|
| [169] | 819 | */ |
|---|
| [162] | 820 | |
|---|
| [179] | 821 | /** |
|---|
| 822 | * @defgroup internal Internal Definitions |
|---|
| 823 | * @{ |
|---|
| 824 | */ |
|---|
| 825 | |
|---|
| 826 | /** |
|---|
| 827 | * Allocate a dynamic memory block. |
|---|
| 828 | * |
|---|
| 829 | * @param[in] size Size of a memory block, \c 0 is valid. |
|---|
| 830 | * |
|---|
| 831 | * @returns @c yaml_malloc returns a pointer to a newly allocated memory block, |
|---|
| 832 | * or @c NULL if it failed. |
|---|
| 833 | */ |
|---|
| 834 | |
|---|
| [183] | 835 | YAML_DECLARE(void *) |
|---|
| [179] | 836 | yaml_malloc(size_t size); |
|---|
| 837 | |
|---|
| 838 | /** |
|---|
| 839 | * Reallocate a dynamic memory block. |
|---|
| 840 | * |
|---|
| 841 | * @param[in] ptr A pointer to an existing memory block, \c NULL is |
|---|
| 842 | * valid. |
|---|
| 843 | * @param[in] size A size of a new block, \c 0 is valid. |
|---|
| 844 | * |
|---|
| 845 | * @returns @c yaml_realloc returns a pointer to a reallocated memory block, |
|---|
| 846 | * or @c NULL if it failed. |
|---|
| 847 | */ |
|---|
| 848 | |
|---|
| [183] | 849 | YAML_DECLARE(void *) |
|---|
| [179] | 850 | yaml_realloc(void *ptr, size_t size); |
|---|
| 851 | |
|---|
| 852 | /** |
|---|
| 853 | * Free a dynamic memory block. |
|---|
| 854 | * |
|---|
| 855 | * @param[in] ptr A pointer to an existing memory block, \c NULL is |
|---|
| 856 | * valid. |
|---|
| 857 | */ |
|---|
| 858 | |
|---|
| [183] | 859 | YAML_DECLARE(void) |
|---|
| [179] | 860 | yaml_free(void *ptr); |
|---|
| 861 | |
|---|
| [185] | 862 | /** The initial size for various buffers. */ |
|---|
| 863 | |
|---|
| 864 | #define YAML_DEFAULT_SIZE 16 |
|---|
| 865 | |
|---|
| [180] | 866 | /** The size of the raw buffer. */ |
|---|
| 867 | |
|---|
| 868 | #define YAML_RAW_BUFFER_SIZE 16384 |
|---|
| 869 | |
|---|
| 870 | /** |
|---|
| 871 | * The size of the buffer. |
|---|
| 872 | * |
|---|
| 873 | * We allocate enough space for decoding the whole raw buffer. |
|---|
| 874 | */ |
|---|
| 875 | |
|---|
| 876 | #define YAML_BUFFER_SIZE (YAML_RAW_BUFFER_SIZE*3) |
|---|
| 877 | |
|---|
| [181] | 878 | /** |
|---|
| 879 | * Ensure that the buffer contains at least @a length characters. |
|---|
| 880 | * |
|---|
| 881 | * @param[in] parser A parser object. |
|---|
| 882 | * @param[in] length The number of characters in the buffer. |
|---|
| 883 | * |
|---|
| 884 | * @returns @c 1 on success, @c 0 on error. |
|---|
| 885 | */ |
|---|
| 886 | |
|---|
| [183] | 887 | YAML_DECLARE(int) |
|---|
| [181] | 888 | yaml_parser_update_buffer(yaml_parser_t *parser, size_t length); |
|---|
| 889 | |
|---|
| [179] | 890 | /** @} */ |
|---|
| 891 | |
|---|
| 892 | |
|---|
| [162] | 893 | #ifdef __cplusplus |
|---|
| 894 | } |
|---|
| 895 | #endif |
|---|
| 896 | |
|---|
| [169] | 897 | #endif /* #ifndef YAML_H */ |
|---|
| [162] | 898 | |
|---|