Changeset 266
- Timestamp:
- 01/03/08 22:33:04 (9 months ago)
- Files:
-
- libyaml/trunk/README (modified) (3 diffs)
- libyaml/trunk/doc (deleted)
- libyaml/trunk/include/Makefile.am (modified) (1 diff)
- libyaml/trunk/include/yaml.h (modified) (60 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
libyaml/trunk/README
r220 r266 1 1 LibYAML - A C library for parsing and emitting YAML. 2 3 The project is in an early stage of development.4 2 5 3 To build and install the library, run: … … 14 12 # make install 15 13 16 For more information, check the LibYAML homepage: 14 For the API reference, check the file 'include/yaml.h'. Examples on how to use 15 LibYAML could be found in the 'tests' directory. 16 17 Check the LibYAML homepage for more information: 17 18 'http://pyyaml.org/wiki/LibYAML'. 18 19 … … 26 27 under the MIT license. See the file LICENSE for more details. 27 28 28 This project is developed for Python Software Foundation as a part of 29 Google Summer of Code under the mentorship of Clark Evans. 29 The initial version of this project was developed for Python Software 30 Foundation under the mentorshipf of Clark Evans as a part of Google Summer of 31 Code 2006. libyaml/trunk/include/Makefile.am
r200 r266 1 1 INCLUDES = yaml.h 2 DOXYGEN_CFG = $(top_srcdir)/doc/doxygen.cfg3 2 4 3 nobase_include_HEADERS = $(INCLUDES) 5 4 6 if DOXYGEN7 8 html: $(INCLUDES) $(DOXYGEN_CFG)9 PACKAGE=$(PACKAGE) VERSION=$(VERSION) top_srcdir=$(top_srcdir) top_builddir=$(top_builddir) doxygen $(DOXYGEN_CFG)10 11 endif12 13 distclean-local:14 -rm -rf $(top_builddir)/doc/html15 16 dist-hook: html17 cp -a $(top_builddir)/doc/html $(top_distdir)/doclibyaml/trunk/include/yaml.h
r265 r266 1 /** 2 * @file yaml.h 3 * @brief Public interface for libyaml. 4 * 5 * Include the header file with the code: 6 * @code 7 * #include <yaml.h> 8 * @endcode 9 */ 1 /***************************************************************************** 2 * Public Interface for LibYAML 3 * 4 * Copyright (c) 2006 Kirill Simonov 5 * 6 * LibYAML is free software; you can use, modify and/or redistribute it under 7 * the terms of the MIT license; see the file LICENCE for more details. 8 *****************************************************************************/ 9 10 /* 11 * General guidelines. 12 * 13 * Naming conventions: all functions exported by LibYAML starts with the `yaml_` prefix; 14 * types starts with `yaml_` and ends with `_t`; macros and enumerations starts 15 * with `YAML_`. 16 * 17 * FIXME: Calling conventions. 18 * FIXME: Memory allocation. 19 * FIXME: Errors and exceptions. 20 * FIXME: And so on, and so forth. 21 */ 22 10 23 11 24 #ifndef YAML_H … … 20 33 #include <string.h> 21 34 22 /** 23 * @defgroup export Export Definitions 24 * @{ 25 */ 26 27 /** The public API declaration. */ 35 /***************************************************************************** 36 * Export Definitions 37 *****************************************************************************/ 38 39 /* 40 * Public API declarations. 41 * 42 * The following definitions are relevant only for the Win32 platform. If you 43 * are building LibYAML as a static library or linking your application against 44 * LibYAML compiled as a static library, define the macro 45 * `YAML_DECLARE_STATIC`. If you are building LibYAML as a dynamic library 46 * (DLL), you need to define `YAML_DECLARE_EXPORT`. You don't need to define 47 * any macros in case you are linking your application against LibYAML compiled 48 * as DLL. 49 * 50 * There is no need to define any macros if you use LibYAML on non-Win32 51 * platform. 52 */ 28 53 29 54 #ifdef WIN32 … … 39 64 #endif 40 65 41 /** @} */42 43 /** 44 * @defgroup version Version Information 45 * @{ 46 * /47 48 /** The major version number. */ 66 /***************************************************************************** 67 * Version Information 68 *****************************************************************************/ 69 70 /* 71 * The major, minor and patch version numbers of LibYAML. 72 */ 73 49 74 #define YAML_VERSION_MAJOR 0 50 51 /** The minor version number. */52 75 #define YAML_VERSION_MINOR 2 53 54 /** The patch version number. */55 76 #define YAML_VERSION_PATCH 0 56 77 57 /** The version string generator macro. */ 58 #define YAML_VERSION_STRING_GENERATOR(major,minor,patch) \ 59 (#major "." #minor "." #patch) 60 61 /** The version string. */ 62 #define YAML_VERSION_STRING \ 63 YAML_VERSION_STRING_GENERATOR(YAML_VERSION_MAJOR,YAML_VERSION_MINOR,YAML_VERSION_PATCH) 64 65 /** 78 /* 79 * The version of LibYAML as a string. 80 */ 81 82 #define YAML_VERSION_STRING "0.2.0" 83 84 /* 66 85 * Get the library version numbers at runtime. 67 86 * 68 * @param[out] major Major version number. 69 * @param[out] minor Minor version number. 70 * @param[out] patch Patch version number. 87 * Arguments: 88 * 89 * - `major`: a pointer to store the major version number. 90 * 91 * - `minor`: a pointer to store the minor version number. 92 * 93 * - `patch`: a pointer to store the patch version number. 71 94 */ 72 95 … … 74 97 yaml_get_version(int *major, int *minor, int *patch); 75 98 76 /* *99 /* 77 100 * Get the library version as a string at runtime. 78 101 * 79 * @returns The function returns the pointer to a static string of the form 80 * @c "X.Y.Z", where @c X is the major version number, @c Y is the minor version 81 * number, and @c Z is the patch version number. 102 * Returns: the version of LibYAML as a static string. 82 103 */ 83 104 … … 85 106 yaml_get_version_string(void); 86 107 87 /** @} */ 88 89 /** 90 * @defgroup styles Error Handling 91 * @{ 92 */ 93 94 /** Many bad things could happen with the parser and the emitter. */ 108 /***************************************************************************** 109 * Error Handling 110 *****************************************************************************/ 111 112 /* 113 * The type of the error. 114 * 115 * The YAML parser and emitter reports any error details using the 116 * `yaml_error_t` structure. The error type shows what subsystem generated the 117 * error and what additional information about the error is available. 118 */ 119 95 120 typedef enum yaml_error_type_e { 96 /* * No error is produced. */121 /* No error was produced. */ 97 122 YAML_NO_ERROR, 98 123 99 /* *Cannot allocate or reallocate a block of memory. */124 /* Cannot allocate or reallocate a block of memory. */ 100 125 YAML_MEMORY_ERROR, 101 126 102 /* *Cannot read from the input stream. */127 /* Cannot read from the input stream. */ 103 128 YAML_READER_ERROR, 104 /* * Cannot decodethe input stream. */129 /* Cannot decode a character in the input stream. */ 105 130 YAML_DECODER_ERROR, 106 /* *Cannot scan a YAML token. */131 /* Cannot scan a YAML token. */ 107 132 YAML_SCANNER_ERROR, 108 /* * Cannot parse a YAML production. */133 /* Cannot parse a YAML event. */ 109 134 YAML_PARSER_ERROR, 110 /* *Cannot compose a YAML document. */135 /* Cannot compose a YAML document. */ 111 136 YAML_COMPOSER_ERROR, 112 137 113 /* *Cannot write into the output stream. */138 /* Cannot write into the output stream. */ 114 139 YAML_WRITER_ERROR, 115 /* *Cannot emit a YAML event. */140 /* Cannot emit a YAML event. */ 116 141 YAML_EMITTER_ERROR, 117 /* *Cannot serialize a YAML document. */142 /* Cannot serialize a YAML document. */ 118 143 YAML_SERIALIZER_ERROR, 119 144 120 /* * Cannot resolve an implicittag. */145 /* Cannot resolve an implicit YAML node tag. */ 121 146 YAML_RESOLVER_ERROR 122 147 } yaml_error_type_t; 123 148 124 /** The pointer position. */ 149 /* 150 * Position in the input stream. 151 * 152 * Marks are used to indicate the position of YAML tokens, events and documents 153 * in the input stream as well as to point to the place where a parser error has 154 * occured. 155 */ 156 125 157 typedef struct yaml_mark_s { 126 /* * The character number(starting from zero). */158 /* The number of the character in the input stream (starting from zero). */ 127 159 size_t index; 128 129 /** The mark line (starting from zero). */ 160 /* The line in the input stream (starting from zero). */ 130 161 size_t line; 131 132 /** The mark column (starting from zero). */ 162 /* The column in the input stream (starting from zero). */ 133 163 size_t column; 134 164 } yaml_mark_t; 135 165 136 /** The error details. */ 166 /* 167 * Error details. 168 * 169 * The structure gives detailed information on any problem that occured during 170 * parsing or emitting. 171 */ 172 137 173 typedef struct yaml_error_s { 138 174 139 /* *The error type. */175 /* The error type. */ 140 176 yaml_error_type_t type; 141 177 142 /* * The detailed error information. */178 /* The specific information for each error type. */ 143 179 union { 144 180 145 /* *146 * A problem while reading the stream (@c YAML_READER_ERRORor147 * @c YAML_DECODER_ERROR).181 /* 182 * A problem occured while reading the input stream (relevant for 183 * `YAML_READER_ERROR` and `YAML_DECODER_ERROR`). 148 184 */ 149 185 struct { 150 /* *The problem description. */186 /* The problem description. */ 151 187 const char *problem; 152 /* * The stream offset. */188 /* The position in the input stream, in bytes. */ 153 189 size_t offset; 154 /* * The problematic octet or character (@c -1if not applicable). */190 /* The problematic octet or character (`-1` if not applicable). */ 155 191 int value; 156 192 } reading; 157 193 158 /** 159 * A problem while loading the stream (@c YAML_SCANNER_ERROR, 160 * @c YAML_PARSER_ERROR, or @c YAML_COMPOSER_ERROR). 194 /* 195 * A problem occured while loading YAML data from the input stream 196 * (relevant for `YAML_SCANNER_ERROR`, `YAML_PARSER_ERROR`, and 197 * `YAML_COMPOSER_ERROR`). 161 198 */ 162 199 struct { 163 /** The context in which the problem occured 164 * (@c NULL if not applicable). 165 */ 200 /* The description of the context in which the problem occured 201 (`NULL` if not applicable). */ 166 202 const char *context; 167 /* * The context mark (if @c problem_mark is not @c NULL). **/203 /* The context mark (if `context` is not `NULL`). */ 168 204 yaml_mark_t context_mark; 169 /* *The problem description. */205 /* The problem description. */ 170 206 const char *problem; 171 /* *The problem mark. */207 /* The problem mark. */ 172 208 yaml_mark_t problem_mark; 173 209 } loading; 174 210 175 /** A problem while writing into the stream (@c YAML_WRITER_ERROR). */ 211 /* 212 * A problem occured while writing into the output stream (relevant for 213 * `YAML_WRITER_ERROR`). 214 */ 176 215 struct { 177 /* *The problem description. */216 /* The problem description. */ 178 217 const char *problem; 179 /* * The stream offset. */218 /* The position in the output stream, in bytes. */ 180 219 size_t offset; 181 220 } writing; 182 221 183 /** A problem while dumping into the stream (@c YAML_EMITTER_ERROR and 184 * @c YAML_SERIALIZER_ERROR). 222 /* 223 * A problem while dumping YAML data into the output stream (relevant 224 * for `YAML_EMITTER_ERROR` and `YAML_SERIALIZER_ERROR`). 185 225 */ 186 226 struct { 187 /* *The problem description. */227 /* The problem description. */ 188 228 const char *problem; 189 229 } dumping; 190 230 191 /** A problem while resolving an implicit tag (@c YAML_RESOLVER_ERROR). */ 231 /* 232 * A problem occured while resolving an implicit YAML node tag 233 * (relevant for `YAML_RESOLVER_ERROR`). 234 */ 192 235 struct { 193 /* *The problem description. */236 /* The problem description. */ 194 237 const char *problem; 195 238 } resolving; … … 199 242 } yaml_error_t; 200 243 201 /** 202 * Create an error message. 203 * 204 * @param[in] error An error object. 205 * @param[out] buffer model A token to copy. 206 * 207 * @returns @c 1 if the function succeeded, @c 0 on error. The function may 208 * fail if the buffer is not large enough to contain the whole message. 244 /* 245 * Generate an error message. 246 * 247 * Given an instance of the `yaml_error_t` structure and a buffer, the function 248 * fills the buffer with a message describing the error. The generated message 249 * follows the pattern: `"Error type: error details"`. If the buffer is not 250 * large enough to hold the whole message, the function fails. 251 * 252 * Arguments: 253 * 254 * - `error`: an error object obtained using `yaml_parser_get_error()` or 255 * `yaml_emitter_get_error()`. 256 * 257 * - `buffer`: a pointer to a character buffer to be filled with a generated 258 * error message. 259 * 260 * - `capacity`: the size of the buffer. 261 * 262 * Returns: `1` if the function succeeded, `0` on error. The function may fail 263 * if the provided buffer is not large enough to hold the whole buffer, in 264 * which case an application may increase the size of the buffer and call the 265 * function again. If the function fails, the content of the buffer is 266 * undefined. 209 267 */ 210 268 … … 212 270 yaml_error_message(yaml_error_t *error, char *buffer, size_t capacity); 213 271 214 /** @} */ 215 216 /** 217 * @defgroup basic Basic Types 218 * @{ 219 */ 220 221 /** The character type (UTF-8 octet). */ 272 /****************************************************************************** 273 * Basic Types 274 ******************************************************************************/ 275 276 /* 277 * The character type (UTF-8 octet). 278 * 279 * Usage of the string type `(yaml_char_t *)` in the LibYAML API indicates that 280 * the string is encoded in UTF-8. 281 */ 282 222 283 typedef unsigned char yaml_char_t; 223 284 224 /** The version directive data. */ 285 /* 286 * The version directive information. 287 * 288 * Note that LibYAML only supports YAML 1.1. 289 */ 290 225 291 typedef struct yaml_version_directive_s { 226 /* *The major version number. */292 /* The major version number. */ 227 293 int major; 228 /* *The minor version number. */294 /* The minor version number. */ 229 295 int minor; 230 296 } yaml_version_directive_t; 231 297 232 /** The tag directive data. */ 298 /* 299 * The tag directive information. 300 */ 301 233 302 typedef struct yaml_tag_directive_s { 234 /* *The tag handle. */303 /* The tag handle. */ 235 304 yaml_char_t *handle; 236 /* *The tag prefix. */305 /* The tag prefix. */ 237 306 yaml_char_t *prefix; 238 307 } yaml_tag_directive_t; 239 308 240 /** The stream encoding. */ 309 /* 310 * The stream encoding. 311 * 312 * An application may explicitly specify the encoding in the input stream or 313 * let the parser to detect the input stream encoding from a BOM mark. If the 314 * stream does not start with a BOM mark, UTF-8 is assumed. 315 * 316 * An application may specify the encoding of the output stream or let the 317 * emitter to choose a suitable encoding, in which case, UTF-8 is used. 318 */ 319 241 320 typedef enum yaml_encoding_e { 242 /* * Let the parser choose theencoding. */321 /* The default/autodetected encoding. */ 243 322 YAML_ANY_ENCODING, 244 /* * The defaultUTF-8 encoding. */323 /* The UTF-8 encoding. */ 245 324 YAML_UTF8_ENCODING, 246 /* * The UTF-16-LE encoding with BOM. */325 /* The UTF-16-LE encoding. */ 247 326 YAML_UTF16LE_ENCODING, 248 /* * The UTF-16-BE encoding with BOM. */327 /* The UTF-16-BE encoding. */ 249 328 YAML_UTF16BE_ENCODING 250 329 } yaml_encoding_t; 251 330 252 /** Line break types. */ 331 /* 332 * Line break types. 333 * 334 * An application may specify the line break type the emitter should use or 335 * leave it to the emitter discretion. In the latter case, LN (Unix style) is 336 * used. 337 */ 338 253 339 typedef enum yaml_break_e { 254 /* *Let the parser choose the break type. */340 /* Let the parser choose the break type. */ 255 341 YAML_ANY_BREAK, 256 /* *Use CR for line breaks (Mac style). */342 /* Use CR for line breaks (Mac style). */ 257 343 YAML_CR_BREAK, 258 /* *Use LN for line breaks (Unix style). */344 /* Use LN for line breaks (Unix style). */ 259 345 YAML_LN_BREAK, 260 /* *Use CR LN for line breaks (DOS style). */346 /* Use CR LN for line breaks (DOS style). */ 261 347 YAML_CRLN_BREAK 262 348 } yaml_break_t; 263 349 264 /** @} */ 265 266 /** 267 * @defgroup styles Node Styles 268 * @{ 269 */ 270 271 /** Scalar styles. */ 350 /****************************************************************************** 351 * Node Styles 352 ******************************************************************************/ 353 354 /* 355 * Scalar styles. 356 * 357 * There are two groups of scalar types in YAML: flow and block. Flow scalars 358 * are divided into three styles: plain, single-quoted, and double-quoted; 359 * block scalars are divided into two styles: literal and folded. 360 * 361 * The parser reports the style in which a scalar node is represented, however 362 * it is a purely presentation details that must not be used in interpreting 363 * the node content. 364 * 365 * An application may suggest a preferred node style or leave it completely 366 * to the emitter discretion. Note that the emitter may ignore any stylistic 367 * suggestions. 368 */ 369 272 370 typedef enum yaml_scalar_style_e { 273 /* *Let the emitter choose the style. */371 /* Let the emitter choose the style. */ 274 372 YAML_ANY_SCALAR_STYLE, 275 373 276 /* * The plainscalar style. */374 /* The plain flow scalar style. */ 277 375 YAML_PLAIN_SCALAR_STYLE, 278 376 279 /* * The single-quotedscalar style. */377 /* The single-quoted flow scalar style. */ 280 378 YAML_SINGLE_QUOTED_SCALAR_STYLE, 281 /* * The double-quotedscalar style. */379 /* The double-quoted flow scalar style. */ 282 380 YAML_DOUBLE_QUOTED_SCALAR_STYLE, 283 381 284 /* * The literalscalar style. */382 /* The literal block scalar style. */ 285 383 YAML_LITERAL_SCALAR_STYLE, 286 /* * The foldedscalar style. */384 /* The folded block scalar style. */ 287 385 YAML_FOLDED_SCALAR_STYLE 288 386 } yaml_scalar_style_t; 289 387 290 /** Sequence styles. */ 388 /* 389 * Sequence styles. 390 * 391 * YAML supports two sequence styles: flow and block. 392 * 393 * The parser reports the style of a sequence node, but this information should 394 * not be used in interpreting the sequence content. 395 * 396 * An application may suggest a preferred sequence style or leave it completely 397 * to the emitter discretion. Note that the emitter may ignore any stylistic 398 * hints. 399 */ 291 400 typedef enum yaml_sequence_style_e { 292 /* *Let the emitter choose the style. */401 /* Let the emitter choose the style. */ 293 402 YAML_ANY_SEQUENCE_STYLE, 294 403 295 /** The block sequence style. */ 404 /* The flow sequence style. */ 405 YAML_FLOW_SEQUENCE_STYLE 406 /* The block sequence style. */ 296 407 YAML_BLOCK_SEQUENCE_STYLE, 297 /** The flow sequence style. */298 YAML_FLOW_SEQUENCE_STYLE299 408 } yaml_sequence_style_t; 300 409 301 /** Mapping styles. */ 410 /* 411 * Mapping styles. 412 * 413 * YAML supports two mapping styles: flow and block. 414 * 415 * The parser reports the style of a mapping node, but this information should 416 * not be used in interpreting the mapping content. 417 * 418 * An application may suggest a preferred mapping style or leave it completely 419 * to the emitter discretion. Note that the emitter may ignore any stylistic 420 * hints. 421 */ 422 302 423 typedef enum yaml_mapping_style_e { 303 /* *Let the emitter choose the style. */424 /* Let the emitter choose the style. */ 304 425 YAML_ANY_MAPPING_STYLE, 305 426 306 /* *The block mapping style. */427 /* The block mapping style. */ 307 428 YAML_BLOCK_MAPPING_STYLE, 308 /* *The flow mapping style. */429 /* The flow mapping style. */ 309 430 YAML_FLOW_MAPPING_STYLE 310 /* YAML_FLOW_SET_MAPPING_STYLE */311 431 } yaml_mapping_style_t; 312 432 313 /** @} */ 314 315 /** 316 * @defgroup tokens Tokens 317 * @{ 318 */ 319 320 /** Token types. */ 433 /****************************************************************************** 434 * Tokens 435 ******************************************************************************/ 436 437 /* 438 * Token types. 439 * 440 * The LibYAML scanner generates the following types of tokens: 441 * 442 * - STREAM-START: indicates the beginning of the stream. 443 * 444 * - STREAM-END: indicates the end of the stream. 445 * 446 * - VERSION-DIRECTIVE: describes the `%YAML` directive. 447 * 448 * - TAG-DIRECTIVE: describes the `%TAG` directive. 449 * 450 * - DOCUMENT-START: the indicator `---`. 451 * 452 * - DOCUMENT-END: the indicator `...`. 453 * 454 * - BLOCK-SEQUENCE-START: indentation increase indicating the beginning of a 455 * block sequence node. 456 * 457 * - BLOCK-MAPPING-START: indentation increase indicating the beginning of a 458 * block mapping node. 459 * 460 * - BLOCK-END: indentation decrease indicating the end of a block collection 461 * node. 462 * 463 * - FLOW-SEQUENCE-START: the indicator `[`. 464 * 465 * - FLOW-SEQUENCE-END: the indicator `]`. 466 * 467 * - FLOW-MAPPING-START: the indicator `{`. 468 * 469 * - FLOW-MAPPING-END: the indicator `}`. 470 * 471 * - BLOCK-ENTRY: the beginning of an item of a block sequence. 472 * 473 * - FLOW-ENTRY: the beginning of an item of a flow sequence. 474 * 475 * - KEY: the beginning of a simple key, or the indicator `?`. 476 * 477 * - VALUE: the indicator `:`. 478 * 479 * - ALIAS: an alias of a node. 480 * 481 * - ANCHOR: a node anchor. 482 * 483 * - TAG: a node tag. 484 * 485 * - SCALAR: the content of a scalar node. 486 */ 487 321 488 typedef enum yaml_token_type_e { 322 /* * An emptytoken. */489 /* An empty unitialized token. */ 323 490 YAML_NO_TOKEN, 324 491 325 /* *A STREAM-START token. */492 /* A STREAM-START token. */ 326 493 YAML_STREAM_START_TOKEN, 327 /* *A STREAM-END token. */494 /* A STREAM-END token. */ 328 495 YAML_STREAM_END_TOKEN, 329 496 330 /* *A VERSION-DIRECTIVE token. */497 /* A VERSION-DIRECTIVE token. */ 331 498 YAML_VERSION_DIRECTIVE_TOKEN, 332 /* *A TAG-DIRECTIVE token. */499 /* A TAG-DIRECTIVE token. */ 333 500 YAML_TAG_DIRECTIVE_TOKEN, 334 /* *A DOCUMENT-START token. */501 /* A DOCUMENT-START token. */ 335 502 YAML_DOCUMENT_START_TOKEN, 336 /* *A DOCUMENT-END token. */503 /* A DOCUMENT-END token. */ 337 504 YAML_DOCUMENT_END_TOKEN, 338 505 339 /* *A BLOCK-SEQUENCE-START token. */506 /* A BLOCK-SEQUENCE-START token. */ 340 507 YAML_BLOCK_SEQUENCE_START_TOKEN, 341 /* *A BLOCK-SEQUENCE-END token. */508 /* A BLOCK-SEQUENCE-END token. */ 342 509 YAML_BLOCK_MAPPING_START_TOKEN, 343 /* *A BLOCK-END token. */510 /* A BLOCK-END token. */ 344 511 YAML_BLOCK_END_TOKEN, 345 512 346 /* *A FLOW-SEQUENCE-START token. */513 /* A FLOW-SEQUENCE-START token. */ 347 514 YAML_FLOW_SEQUENCE_START_TOKEN, 348 /* *A FLOW-SEQUENCE-END token. */515 /* A FLOW-SEQUENCE-END token. */ 349 516 YAML_FLOW_SEQUENCE_END_TOKEN, 350 /* *A FLOW-MAPPING-START token. */517 /* A FLOW-MAPPING-START token. */ 351 518 YAML_FLOW_MAPPING_START_TOKEN, 352 /* *A FLOW-MAPPING-END token. */519 /* A FLOW-MAPPING-END token. */ 353 520 YAML_FLOW_MAPPING_END_TOKEN, 354 521 355 /* *A BLOCK-ENTRY token. */522 /* A BLOCK-ENTRY token. */ 356 523 YAML_BLOCK_ENTRY_TOKEN, 357 /* *A FLOW-ENTRY token. */524 /* A FLOW-ENTRY token. */ 358 525 YAML_FLOW_ENTRY_TOKEN, 359 /* *A KEY token. */526 /* A KEY token. */ 360 527 YAML_KEY_TOKEN, 361 /* *A VALUE token. */528 /* A VALUE token. */ 362 529 YAML_VALUE_TOKEN, 363 530 364 /* *An ALIAS token. */531 /* An ALIAS token. */ 365 532 YAML_ALIAS_TOKEN, 366 /* *An ANCHOR token. */533 /* An ANCHOR token. */ 367 534 YAML_ANCHOR_TOKEN, 368 /* *A TAG token. */535 /* A TAG token. */ 369 536 YAML_TAG_TOKEN, 370 /* *A SCALAR token. */537 /* A SCALAR token. */ 371 538 YAML_SCALAR_TOKEN 372 539 } yaml_token_type_t; 373 540 374 /** The token structure. */ 541 /* 542 * The token object. 543 * 544 * Typically the token API is too low-level to be used directly by 545 * applications. A possible user of the token API is a syntax highlighting 546 * application. 547 */ 548 375 549 typedef struct yaml_token_s { 376 550 377 /* *The token type. */551 /* The token type. */ 378 552 yaml_token_type_t type; 379 553 380 /* *The token data. */554 /* The token data. */ 381 555 union { 382 556 383 /* * The stream start (for @c YAML_STREAM_START_TOKEN). */557 /* Extra data associated with a STREAM-START token. */ 384 558 struct { 385 /* *The stream encoding. */559 /* The stream encoding. */ 386 560 yaml_encoding_t encoding; 387 561 } stream_start; 388 562 389 /* * The version directive (for @c YAML_VERSION_DIRECTIVE_TOKEN). */563 /* Extra data associated with a VERSION-DIRECTIVE token. */ 390 564 struct { 391 /* *The major version number. */565 /* The major version number. */ 392 566 int major; 393 /* *The minor version number. */567 /* The minor version number. */ 394 568 int minor; 395 569 } version_directive; 396 570 397 /* * The tag directive (for @c YAML_TAG_DIRECTIVE_TOKEN). */571 /* Extra data associated with a TAG-DIRECTIVE token. */ 398 572 struct { 399 /* *The tag handle. */573 /* The tag handle. */ 400 574 yaml_char_t *handle; 401 /* *The tag prefix. */575 /* The tag prefix. */ 402 576 yaml_char_t *prefix; 403 577 } tag_directive; 404 578 405 /* * The alias (for @c YAML_ALIAS_TOKEN). */579 /* Extra data associated with an ALIAS token. */ 406 580 struct { 407 /* *The alias value. */581 /* The alias value. */ 408 582 yaml_char_t *value; 409 583 } alias; 410 584 411 /* * The anchor (for @c YAML_ANCHOR_TOKEN). */585 /* Extra data associated with an ANCHOR token. */ 412 586 struct { 413 /* *The anchor value. */587 /* The anchor value. */ 414 588 yaml_char_t *value; 415 589 } anchor; 416 590 417 /* * The tag (for @c YAML_TAG_TOKEN). */591 /* Extra data associated with a TAG token. */ 418 592 struct { 419 /* *The tag handle. */593 /* The tag handle. */ 420 594 yaml_char_t *handle; 421 /* *The tag suffix. */595 /* The tag suffix. */ 422 596 yaml_char_t *suffix; 423 597 } tag; 424 598 425 /* * The scalar value (for @c YAML_SCALAR_TOKEN). */599 /* Extra data associated with a SCALAR token. */ 426 600 struct { 427 /* *The scalar value. */601 /* The scalar value. */ 428 602 yaml_char_t *value; 429 /* *The length of the scalar value. */603 /* The length of the scalar value. */ 430 604 size_t length; 431 /* *The scalar style. */605 /* The scalar style. */ 432 606 yaml_scalar_style_t style; 433 607 } scalar; … … 435 609 } data; 436 610 437 /* *The beginning of the token. */611 /* The beginning of the token. */ 438 612 yaml_mark_t start_mark; 439 /* *The end of the token. */613 /* The end of the token. */ 440 614 yaml_mark_t end_mark; 441 615 442 616 } yaml_token_t; 443 617 444 /* *618 /* 445 619 * Allocate a new empty token object. 446 620 * 447 * @returns a new token object or @c NULL on error. 621 * A token object allocated using this function must be deleted with 622 * `yaml_token_delete()`. 623 * 624 * Returns: a new empty token object or `NULL` on error. The function may fail 625 * if it cannot allocate memory for a new token object. 448 626 */ 449 627 … … 451 629 yaml_token_new(void); 452 630 453 /** 454 * Delete and deallocate a token object. 455 * 456 * @param[in,out] token A token object. 631 /* 632 * Deallocate a token object and free the associated data. 633 * 634 * A token object must be previously allocated with `yaml_token_new()`. 635 * 636 * Arguments: 637 * 638 * - `token`: a token object to be deallocated. 457 639 */ 458 640 … … 460 642 yaml_token_delete(yaml_token_t *token); 461 643 462 /* *644 /* 463 645 * Duplicate a token object. 464 646 * 465 * @param[in,out] token An empty token object. 466 * @param[in] model A token to copy. 467 * 468 * @returns @c 1 if the function succeeded, @c 0 on error. 647 * This function creates a deep copy of an existing token object. It accepts 648 * two token objects: an empty token and a model token. The latter is supposed 649 * to be initialized with `yaml_parser_parse_token()`. The function assigns 650 * the type of the model to the empty token as well as duplicates and copies 651 * the internal state associated with the model token. 652 * 653 * Arguments: 654 * 655 * - `token`: an empty token object. 656 * 657 * - `model`: a token to be copied. 658 * 659 * Returns: `1` on success, `0` on error. The function may fail if it cannot 660 * allocate memory for duplicating the state of the model token. In that case, 661 * the token remains empty. 469 662 */ 470 663 … … 472 665 yaml_token_duplicate(yaml_token_t *token, const yaml_token_t *model); 473 666 474 /** 475 * Free any memory allocated for a token object. 476 * 477 * @param[in,out] token A token object. 667 /* 668 * Clear the token state. 669 * 670 * This function clears the type and the internal state of a token object 671 * freeing any associated data. After applying this function to a token, it 672 * becomes empty. It is supposed that the token was previously initialized 673 * using `yaml_parser_parse_token()` or `yaml_token_duplicate()`. 674 * 675 * Arguments: 676 * 677 * - `token`: a token object. 478 678 */ 479 679 480 680 YAML_DECLARE(void) 481 yaml_token_destroy(yaml_token_t *token); 482 483 /** @} */ 484 485 /** 486 * @defgroup events Events 487 * @{ 488 */ 489 490 /** Event types. */ 681 yaml_token_clear(yaml_token_t *token); 682 683 /****************************************************************************** 684 * Events 685 ******************************************************************************/ 686 687 /* 688 * Event types. 689 * 690 * The LibYAML parser generates, while the LibYAML emitter accepts, YAML events 691 * of the following types: 692 * 693 * - STREAM-START: indicates the beginning of the stream. 694 * 695 * - STREAM-END: indicates the end of the stream. 696 * 697 * - DOCUMENT-START: indicates the beginning of the document. 698 * 699 * - DOCUMENT-END: indicates the end of the document. 700 * 701 * - ALIAS: an alias to an already produced node. 702 * 703 * - SCALAR: a scalar node. 704 * 705 * - SEQUENCE-START: indicates the beginning of a sequence node. 706 * 707 * - SEQUENCE-END: indicates the end of a sequence node. 708 * 709 * - MAPPING-START: indicates the beginning of a mapping node. 710 * 711 * - MAPPING-END: indicates the end of a mapping node. 712 * 713 * A valid sequence of events obeys the grammar: 714 * 715 * stream ::= STREAM-START document* STREAM-END 716 * document ::= DOCUMENT-START node DOCUMENT-END 717 * node ::= ALIAS | SCALAR | sequence | mapping 718 * sequence ::= SEQUENCE-START node* SEQUENCE-END 719 * mapping ::= MAPPING-START (node node)* MAPPING-END 720 */ 721 491 722 typedef enum yaml_event_type_e { 492 /* * An emptyevent. */723 /* An empty unitialized event. */ 493 724 YAML_NO_EVENT, 494 725 495 /* *A STREAM-START event. */726 /* A STREAM-START event. */ 496 727 YAML_STREAM_START_EVENT, 497 /* *A STREAM-END event. */728 /* A STREAM-END event. */ 498 729 YAML_STREAM_END_EVENT, 499 730 500 /* *A DOCUMENT-START event. */731 /* A DOCUMENT-START event. */ 501 732 YAML_DOCUMENT_START_EVENT, 502 /* *A DOCUMENT-END event. */733 /* A DOCUMENT-END event. */ 503 734 YAML_DOCUMENT_END_EVENT, 504 735 505 /* *An ALIAS event. */736 /* An ALIAS event. */ 506 737 YAML_ALIAS_EVENT, 507 /* *A SCALAR event. */738 /* A SCALAR event. */ 508 739 YAML_SCALAR_EVENT, 509 740 510 /* *A SEQUENCE-START event. */741 /* A SEQUENCE-START event. */ 511 742 YAML_SEQUENCE_START_EVENT, 512 /* *A SEQUENCE-END event. */743 /* A SEQUENCE-END event. */ 513 744 YAML_SEQUENCE_END_EVENT, 514 745 515 /* *A MAPPING-START event. */746 /* A MAPPING-START event. */ 516 747 YAML_MAPPING_START_EVENT, 517 /* *A MAPPING-END event. */748 /* A MAPPING-END event. */ 518 749 YAML_MAPPING_END_EVENT 519 750 } yaml_event_type_t; 520 751 521 /** The event structure. */ 752 /* 753 * The event object. 754 * 755 * The event-level API of LibYAML should be used for streaming applications. 756 */ 757 522 758 typedef struct yaml_event_s { 523 759 524 /* *The event type. */760 /* The event type. */ 525 761 yaml_event_type_t type; 526 762 527 /* *The event data. */763 /* The event data. */ 528 764 union { 529 765 530 /* * The stream parameters (for @c YAML_STREAM_START_EVENT). */766 /* The stream parameters (for `YAML_STREAM_START_EVENT`). */ 531 767 struct { 532 /* *The document encoding. */768 /* The document encoding. */ 533 769 yaml_encoding_t encoding; 534 770 } stream_start; 535 771 536 /* * The document parameters (for @c YAML_DOCUMENT_START_EVENT). */772 /* The document parameters (for `YAML_DOCUMENT_START_EVENT`). */ 537 773 struct { 538 /* * The version directive. */774 /* The version directive or `NULL` if not present. */ 539 775 yaml_version_directive_t *version_directive; 540 776 541 /* *The list of tag directives. */777 /* The list of tag directives. */ 542 778 struct { 543 /* * The beginning of the list. */779 /* The beginning of the list or `NULL`. */ 544 780 yaml_tag_directive_t *list; 545 /* *The length of the list. */781 /* The length of the list. */ 546 782 size_t length; 547 /* * The capacity of the list. */783 /* The capacity of the list (used internally). */ 548 784 size_t capacity; 549 785 } tag_directives; 550 786 551 /* * Is the document indicator implicit?*/787 /* Set if the document indicator is omitted. */ 552 788 int is_implicit; 553 789 } document_start; 554 790 555 /* * The document end parameters (for @c YAML_DOCUMENT_END_EVENT). */791 /* The document end parameters (for `YAML_DOCUMENT_END_EVENT`). */ 556 792 struct { 557 &nbs
