3 * @brief Public interface for libyaml.
5 * Include the header file with the code:
23 * @defgroup export Export Definitions
27 /** The public API declaration. */
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
35 # define YAML_DECLARE(type) __declspec(dllimport) type
38 # define YAML_DECLARE(type) type
44 * @defgroup version Version Information
49 * Get the library version as a string.
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.
56 YAML_DECLARE(const char *)
57 yaml_get_version_string(void);
60 * Get the library version numbers.
62 * @param[out] major Major version number.
63 * @param[out] minor Minor version number.
64 * @param[out] patch Patch version number.
68 yaml_get_version(int *major, int *minor, int *patch);
73 * @defgroup basic Basic Types
77 /** The character type (UTF-8 octet). */
78 typedef unsigned char yaml_char_t;
80 /** The version directive data. */
81 typedef struct yaml_version_directive_s {
82 /** The major version number. */
84 /** The minor version number. */
86 } yaml_version_directive_t;
88 /** The tag directive data. */
89 typedef struct yaml_tag_directive_s {
90 /** The tag handle. */
92 /** The tag prefix. */
94 } yaml_tag_directive_t;
96 /** The stream encoding. */
97 typedef enum yaml_encoding_e {
100 YAML_UTF16LE_ENCODING,
101 YAML_UTF16BE_ENCODING
104 /** Line break types. */
106 typedef enum yaml_break_e {
113 /** Many bad things could happen with the parser and emitter. */
114 typedef enum yaml_error_type_e {
128 /** The pointer position. */
129 typedef struct yaml_mark_s {
130 /** The position index. */
133 /** The position line. */
136 /** The position column. */
143 * @defgroup styles Node Styles
147 /** Scalar styles. */
148 typedef enum yaml_scalar_style_e {
149 YAML_ANY_SCALAR_STYLE,
151 YAML_PLAIN_SCALAR_STYLE,
153 YAML_SINGLE_QUOTED_SCALAR_STYLE,
154 YAML_DOUBLE_QUOTED_SCALAR_STYLE,
156 YAML_LITERAL_SCALAR_STYLE,
157 YAML_FOLDED_SCALAR_STYLE
158 } yaml_scalar_style_t;
160 /** Sequence styles. */
161 typedef enum yaml_sequence_style_e {
162 YAML_ANY_SEQUENCE_STYLE,
164 YAML_BLOCK_SEQUENCE_STYLE,
165 YAML_FLOW_SEQUENCE_STYLE
166 } yaml_sequence_style_t;
168 /** Mapping styles. */
169 typedef enum yaml_mapping_style_e {
170 YAML_ANY_MAPPING_STYLE,
172 YAML_BLOCK_MAPPING_STYLE,
173 YAML_FLOW_MAPPING_STYLE
174 /* YAML_FLOW_SET_MAPPING_STYLE */
175 } yaml_mapping_style_t;
180 * @defgroup tokens Tokens
185 typedef enum yaml_token_type_e {
188 YAML_STREAM_START_TOKEN,
189 YAML_STREAM_END_TOKEN,
191 YAML_VERSION_DIRECTIVE_TOKEN,
192 YAML_TAG_DIRECTIVE_TOKEN,
193 YAML_DOCUMENT_START_TOKEN,
194 YAML_DOCUMENT_END_TOKEN,
196 YAML_BLOCK_SEQUENCE_START_TOKEN,
197 YAML_BLOCK_MAPPING_START_TOKEN,
198 YAML_BLOCK_END_TOKEN,
200 YAML_FLOW_SEQUENCE_START_TOKEN,
201 YAML_FLOW_SEQUENCE_END_TOKEN,
202 YAML_FLOW_MAPPING_START_TOKEN,
203 YAML_FLOW_MAPPING_END_TOKEN,
205 YAML_BLOCK_ENTRY_TOKEN,
206 YAML_FLOW_ENTRY_TOKEN,
216 /** The token structure. */
217 typedef struct yaml_token_s {
219 /** The token type. */
220 yaml_token_type_t type;
222 /** The token data. */
225 /** The stream start (for @c YAML_STREAM_START_TOKEN). */
227 /** The stream encoding. */
228 yaml_encoding_t encoding;
231 /** The alias (for @c YAML_ALIAS_TOKEN). */
233 /** The alias value. */
237 /** The anchor (for @c YAML_ANCHOR_TOKEN). */
239 /** The anchor value. */
243 /** The tag (for @c YAML_TAG_TOKEN). */
245 /** The tag handle. */
247 /** The tag suffix. */
251 /** The scalar value (for @c YAML_SCALAR_TOKEN). */
253 /** The scalar value. */
255 /** The length of the scalar value. */
257 /** The scalar style. */
258 yaml_scalar_style_t style;
261 /** The version directive (for @c YAML_VERSION_DIRECTIVE_TOKEN). */
263 /** The major version number. */
265 /** The minor version number. */
269 /** The tag directive (for @c YAML_TAG_DIRECTIVE_TOKEN). */
271 /** The tag handle. */
273 /** The tag prefix. */
279 /** The beginning of the token. */
280 yaml_mark_t start_mark;
281 /** The end of the token. */
282 yaml_mark_t end_mark;
287 * Free any memory allocated for a token object.
289 * @param[in,out] token A token object.
293 yaml_token_delete(yaml_token_t *token);
298 * @defgroup events Events
303 typedef enum yaml_event_type_e {
306 YAML_STREAM_START_EVENT,
307 YAML_STREAM_END_EVENT,
309 YAML_DOCUMENT_START_EVENT,
310 YAML_DOCUMENT_END_EVENT,
315 YAML_SEQUENCE_START_EVENT,
316 YAML_SEQUENCE_END_EVENT,
318 YAML_MAPPING_START_EVENT,
319 YAML_MAPPING_END_EVENT
322 /** The event structure. */
323 typedef struct yaml_event_s {
325 /** The event type. */
326 yaml_event_type_t type;
328 /** The event data. */
331 /** The stream parameters (for @c YAML_STREAM_START_EVENT). */
333 /** The document encoding. */
334 yaml_encoding_t encoding;
337 /** The document parameters (for @c YAML_DOCUMENT_START_EVENT). */
339 /** The version directive. */
340 yaml_version_directive_t *version_directive;
342 /** The list of tag directives. */
344 /** The beginning of the tag directives list. */
345 yaml_tag_directive_t *start;
346 /** The end of the tag directives list. */
347 yaml_tag_directive_t *end;
350 /** Is the document indicator implicit? */
354 /** The document end parameters (for @c YAML_DOCUMENT_END_EVENT). */
356 /** Is the document end indicator implicit? */
360 /** The alias parameters (for @c YAML_ALIAS_EVENT). */
366 /** The scalar parameters (for @c YAML_SCALAR_EVENT). */
372 /** The scalar value. */
374 /** The length of the scalar value. */
376 /** Is the tag optional for the plain style? */
378 /** Is the tag optional for any non-plain style? */
380 /** The scalar style. */
381 yaml_scalar_style_t style;
384 /** The sequence parameters (for @c YAML_SEQUENCE_START_EVENT). */
390 /** Is the tag optional? */
392 /** The sequence style. */
393 yaml_sequence_style_t style;
396 /** The mapping parameters (for @c YAML_MAPPING_START_EVENT). */
402 /** Is the tag optional? */
404 /** The mapping style. */
405 yaml_mapping_style_t style;
410 /** The beginning of the event. */
411 yaml_mark_t start_mark;
412 /** The end of the event. */
413 yaml_mark_t end_mark;
418 * Create the STREAM-START event.
420 * @param[out] event An empty event object.
421 * @param[in] encoding The stream encoding.
423 * @returns @c 1 if the function succeeded, @c 0 on error.
427 yaml_stream_start_event_initialize(yaml_event_t *event,
428 yaml_encoding_t encoding);
431 * Create the STREAM-END event.
433 * @param[out] event An empty event object.
435 * @returns @c 1 if the function succeeded, @c 0 on error.
439 yaml_stream_end_event_initialize(yaml_event_t *event);
442 * Create the DOCUMENT-START event.
444 * The @a implicit argument is considered as a stylistic parameter and may be
445 * ignored by the emitter.
447 * @param[out] event An empty event object.
448 * @param[in] version_directive The %YAML directive value or
450 * @param[in] tag_directives_start The beginning of the %TAG
452 * @param[in] tag_directives_end The end of the %TAG directives
454 * @param[in] implicit If the document start indicator is
457 * @returns @c 1 if the function succeeded, @c 0 on error.
461 yaml_document_start_event_initialize(yaml_event_t *event,
462 yaml_version_directive_t *version_directive,
463 yaml_tag_directive_t *tag_directives_start,
464 yaml_tag_directive_t *tag_directives_end,
468 * Create the DOCUMENT-END event.
470 * The @a implicit argument is considered as a stylistic parameter and may be
471 * ignored by the emitter.
473 * @param[out] event An empty event object.
474 * @param[in] implicit If the document end indicator is implicit.
476 * @returns @c 1 if the function succeeded, @c 0 on error.
480 yaml_document_end_event_initialize(yaml_event_t *event, int implicit);
483 * Create an ALIAS event.
485 * @param[out] event An empty event object.
486 * @param[in] anchor The anchor value.
488 * @returns @c 1 if the function succeeded, @c 0 on error.
492 yaml_alias_event_initialize(yaml_event_t *event, yaml_char_t *anchor);
495 * Create a SCALAR event.
497 * The @a style argument may be ignored by the emitter.
499 * Either the @a tag attribute or one of the @a plain_implicit and
500 * @a quoted_implicit flags must be set.
502 * @param[out] event An empty event object.
503 * @param[in] anchor The scalar anchor or @c NULL.
504 * @param[in] tag The scalar tag or @c NULL.
505 * @param[in] value The scalar value.
506 * @param[in] length The length of the scalar value.
507 * @param[in] plain_implicit If the tag may be omitted for the plain
509 * @param[in] quoted_implicit If the tag may be omitted for any
511 * @param[in] style The scalar style.
513 * @returns @c 1 if the function succeeded, @c 0 on error.
517 yaml_scalar_event_initialize(yaml_event_t *event,
518 yaml_char_t *anchor, yaml_char_t *tag,
519 yaml_char_t *value, int length,
520 int plain_implicit, int quoted_implicit,
521 yaml_scalar_style_t style);
524 * Create a SEQUENCE-START event.
526 * The @a style argument may be ignored by the emitter.
528 * Either the @a tag attribute or the @a implicit flag must be set.
530 * @param[out] event An empty event object.
531 * @param[in] anchor The sequence anchor or @c NULL.
532 * @param[in] tag The sequence tag or @c NULL.
533 * @param[in] implicit If the tag may be omitted.
534 * @param[in] style The sequence style.
536 * @returns @c 1 if the function succeeded, @c 0 on error.
540 yaml_sequence_start_event_initialize(yaml_event_t *event,
541 yaml_char_t *anchor, yaml_char_t *tag, int implicit,
542 yaml_sequence_style_t style);
545 * Create a SEQUENCE-END event.
547 * @param[out] event An empty event object.
549 * @returns @c 1 if the function succeeded, @c 0 on error.
553 yaml_sequence_end_event_initialize(yaml_event_t *event);
556 * Create a MAPPING-START event.
558 * The @a style argument may be ignored by the emitter.
560 * Either the @a tag attribute or the @a implicit flag must be set.
562 * @param[out] event An empty event object.
563 * @param[in] anchor The mapping anchor or @c NULL.
564 * @param[in] tag The mapping tag or @c NULL.
565 * @param[in] implicit If the tag may be omitted.
566 * @param[in] style The mapping style.
568 * @returns @c 1 if the function succeeded, @c 0 on error.
572 yaml_mapping_start_event_initialize(yaml_event_t *event,
573 yaml_char_t *anchor, yaml_char_t *tag, int implicit,
574 yaml_mapping_style_t style);
577 * Create a MAPPING-END event.
579 * @param[out] event An empty event object.
581 * @returns @c 1 if the function succeeded, @c 0 on error.
585 yaml_mapping_end_event_initialize(yaml_event_t *event);
588 * Free any memory allocated for an event object.
590 * @param[in,out] event An event object.
594 yaml_event_delete(yaml_event_t *event);
597 * @defgroup nodes Nodes
601 #define YAML_NULL_TAG "tag:yaml.org,2002:null"
602 #define YAML_BOOL_TAG "tag:yaml.org,2002:bool"
603 #define YAML_STR_TAG "tag:yaml.org,2002:str"
604 #define YAML_INT_TAG "tag:yaml.org,2002:int"
605 #define YAML_FLOAT_TAG "tag:yaml.org,2002:float"
606 #define YAML_TIMESTAMP_TAG "tag:yaml.org,2002:timestamp"
608 #define YAML_SEQ_TAG "tag:yaml.org,2002:seq"
609 #define YAML_MAP_TAG "tag:yaml.org,2002:map"
611 #define YAML_DEFAULT_SCALAR_TAG YAML_STR_TAG
612 #define YAML_DEFAULT_SEQUENCE_TAG YAML_SEQ_TAG
613 #define YAML_DEFAULT_MAPPING_TAG YAML_MAP_TAG
616 typedef enum yaml_node_type_e {
624 /** The forward definition of a document node structure. */
625 typedef struct yaml_node_s yaml_node_t;
627 /** An element of a sequence node. */
628 typedef int yaml_node_item_t;
630 /** An element of a mapping node. */
631 typedef struct yaml_node_pair_s {
632 /** The key of the element. */
634 /** The value of the element. */
638 /** The node structure. */
641 /** The node type. */
642 yaml_node_type_t type;
647 /** The node data. */
650 /** The scalar parameters (for @c YAML_SCALAR_NODE). */
652 /** The scalar value. */
654 /** The length of the scalar value. */
656 /** The scalar style. */
657 yaml_scalar_style_t style;
660 /** The sequence parameters (for @c YAML_SEQUENCE_NODE). */
662 /** The stack of sequence items. */
664 /** The beginning of the stack. */
665 yaml_node_item_t *start;
666 /** The end of the stack. */
667 yaml_node_item_t *end;
668 /** The top of the stack. */
669 yaml_node_item_t *top;
671 /** The sequence style. */
672 yaml_sequence_style_t style;
675 /** The mapping parameters (for @c YAML_MAPPING_NODE). */
677 /** The stack of mapping pairs (key, value). */
679 /** The beginning of the stack. */
680 yaml_node_pair_t *start;
681 /** The end of the stack. */
682 yaml_node_pair_t *end;
683 /** The top of the stack. */
684 yaml_node_pair_t *top;
686 /** The mapping style. */
687 yaml_mapping_style_t style;
692 /** The beginning of the node. */
693 yaml_mark_t start_mark;
694 /** The end of the node. */
695 yaml_mark_t end_mark;
699 /** The document structure. */
700 typedef struct yaml_document_s {
702 /** The document nodes. */
704 /** The beginning of the stack. */
706 /** The end of the stack. */
708 /** The top of the stack. */
712 /** The version directive. */
713 yaml_version_directive_t *version_directive;
715 /** The list of tag directives. */
717 /** The beginning of the tag directives list. */
718 yaml_tag_directive_t *start;
719 /** The end of the tag directives list. */
720 yaml_tag_directive_t *end;
723 /** Is the document start indicator implicit? */
725 /** Is the document end indicator implicit? */
728 /** The beginning of the document. */
729 yaml_mark_t start_mark;
730 /** The end of the document. */
731 yaml_mark_t end_mark;
736 * Create a YAML document.
738 * @param[out] document An empty document object.
739 * @param[in] version_directive The %YAML directive value or
741 * @param[in] tag_directives_start The beginning of the %TAG
743 * @param[in] tag_directives_end The end of the %TAG directives
745 * @param[in] start_implicit If the document start indicator is
747 * @param[in] end_implicit If the document end indicator is
750 * @returns @c 1 if the function succeeded, @c 0 on error.
754 yaml_document_initialize(yaml_document_t *document,
755 yaml_version_directive_t *version_directive,
756 yaml_tag_directive_t *tag_directives_start,
757 yaml_tag_directive_t *tag_directives_end,
758 int start_implicit, int end_implicit);
761 * Delete a YAML document and all its nodes.
763 * @param[in,out] document A document object.
767 yaml_document_delete(yaml_document_t *document);
770 * Get a node of a YAML document.
772 * The pointer returned by this function is valid until any of the functions
773 * modifying the documents are called.
775 * @param[in] document A document object.
776 * @param[in] node The node id.
778 * @returns the node objct or @c NULL if @c node_id is out of range.
781 YAML_DECLARE(yaml_node_t *)
782 yaml_document_get_node(yaml_document_t *document, int node_id);
785 * Get the root of a YAML document node.
787 * The root object is the first object added to the document.
789 * The pointer returned by this function is valid until any of the functions
790 * modifying the documents are called.
792 * An empty document produced by the parser signifies the end of a YAML
795 * @param[in] document A document object.
797 * @returns the node object or @c NULL if the document is empty.
800 YAML_DECLARE(yaml_node_t *)
801 yaml_document_get_root_node(yaml_document_t *document);
804 * Create a SCALAR node and attach it to the document.
806 * The @a style argument may be ignored by the emitter.
808 * @param[in,out] document A document object.
809 * @param[in] tag The scalar tag.
810 * @param[in] value The scalar value.
811 * @param[in] length The length of the scalar value.
812 * @param[in] style The scalar style.
814 * @returns the node id or @c 0 on error.
818 yaml_document_add_scalar(yaml_document_t *document,
819 yaml_char_t *tag, yaml_char_t *value, int length,
820 yaml_scalar_style_t style);
823 * Create a SEQUENCE node and attach it to the document.
825 * The @a style argument may be ignored by the emitter.
827 * @param[in,out] document A document object.
828 * @param[in] tag The sequence tag.
829 * @param[in] style The sequence style.
831 * @returns the node id or @c 0 on error.
835 yaml_document_add_sequence(yaml_document_t *document,
836 yaml_char_t *tag, yaml_sequence_style_t style);
839 * Create a MAPPING node and attach it to the document.
841 * The @a style argument may be ignored by the emitter.
843 * @param[in,out] document A document object.
844 * @param[in] tag The sequence tag.
845 * @param[in] style The sequence style.
847 * @returns the node id or @c 0 on error.
851 yaml_document_add_mapping(yaml_document_t *document,
852 yaml_char_t *tag, yaml_mapping_style_t style);
855 * Add an item to a SEQUENCE node.
857 * @param[in,out] document A document object.
858 * @param[in] sequence The sequence node id.
859 * @param[in] item The item node id.
861 * @returns @c 1 if the function succeeded, @c 0 on error.
865 yaml_document_append_sequence_item(yaml_document_t *document,
866 int sequence, int item);
869 * Add a pair of a key and a value to a MAPPING node.
871 * @param[in,out] document A document object.
872 * @param[in] mapping The mapping node id.
873 * @param[in] key The key node id.
874 * @param[in] value The value node id.
876 * @returns @c 1 if the function succeeded, @c 0 on error.
880 yaml_document_append_mapping_pair(yaml_document_t *document,
881 int mapping, int key, int value);
886 * @defgroup parser Parser Definitions
891 * The prototype of a read handler.
893 * The read handler is called when the parser needs to read more bytes from the
894 * source. The handler should write not more than @a size bytes to the @a
895 * buffer. The number of written bytes should be set to the @a length variable.
897 * @param[in,out] data A pointer to an application data specified by
898 * yaml_parser_set_input().
899 * @param[out] buffer The buffer to write the data from the source.
900 * @param[in] size The size of the buffer.
901 * @param[out] size_read The actual number of bytes read from the source.
903 * @returns On success, the handler should return @c 1. If the handler failed,
904 * the returned value should be @c 0. On EOF, the handler should set the
905 * @a size_read to @c 0 and return @c 1.
908 typedef int yaml_read_handler_t(void *data, unsigned char *buffer, size_t size,
912 * This structure holds information about a potential simple key.
915 typedef struct yaml_simple_key_s {
916 /** Is a simple key possible? */
919 /** Is a simple key required? */
922 /** The number of the token. */
925 /** The position mark. */
930 * The states of the parser.
932 typedef enum yaml_parser_state_e {
933 YAML_PARSE_STREAM_START_STATE,
934 YAML_PARSE_IMPLICIT_DOCUMENT_START_STATE,
935 YAML_PARSE_DOCUMENT_START_STATE,
936 YAML_PARSE_DOCUMENT_CONTENT_STATE,
937 YAML_PARSE_DOCUMENT_END_STATE,
938 YAML_PARSE_BLOCK_NODE_STATE,
939 YAML_PARSE_BLOCK_NODE_OR_INDENTLESS_SEQUENCE_STATE,
940 YAML_PARSE_FLOW_NODE_STATE,
941 YAML_PARSE_BLOCK_SEQUENCE_FIRST_ENTRY_STATE,
942 YAML_PARSE_BLOCK_SEQUENCE_ENTRY_STATE,
943 YAML_PARSE_INDENTLESS_SEQUENCE_ENTRY_STATE,
944 YAML_PARSE_BLOCK_MAPPING_FIRST_KEY_STATE,
945 YAML_PARSE_BLOCK_MAPPING_KEY_STATE,
946 YAML_PARSE_BLOCK_MAPPING_VALUE_STATE,
947 YAML_PARSE_FLOW_SEQUENCE_FIRST_ENTRY_STATE,
948 YAML_PARSE_FLOW_SEQUENCE_ENTRY_STATE,
949 YAML_PARSE_FLOW_SEQUENCE_ENTRY_MAPPING_KEY_STATE,
950 YAML_PARSE_FLOW_SEQUENCE_ENTRY_MAPPING_VALUE_STATE,
951 YAML_PARSE_FLOW_SEQUENCE_ENTRY_MAPPING_END_STATE,
952 YAML_PARSE_FLOW_MAPPING_FIRST_KEY_STATE,
953 YAML_PARSE_FLOW_MAPPING_KEY_STATE,
954 YAML_PARSE_FLOW_MAPPING_VALUE_STATE,
955 YAML_PARSE_FLOW_MAPPING_EMPTY_VALUE_STATE,
957 } yaml_parser_state_t;
960 * This structure holds aliases data.
963 typedef struct yaml_alias_data_s {
968 /** The anchor mark. */
973 * The parser structure.
975 * All members are internal. Manage the structure using the @c yaml_parser_
976 * family of functions.
979 typedef struct yaml_parser_s {
982 * @name Error handling
987 yaml_error_type_t error;
988 /** Error description. */
990 /** The byte about which the problem occured. */
991 size_t problem_offset;
992 /** The problematic value (@c -1 is none). */
994 /** The problem position. */
995 yaml_mark_t problem_mark;
996 /** The error context. */
998 /** The context position. */
999 yaml_mark_t context_mark;
1006 * @name Reader stuff
1010 /** Read handler. */
1011 yaml_read_handler_t *read_handler;
1013 /** A pointer for passing to the read handler. */
1014 void *read_handler_data;
1016 /** Standard (string or file) input data. */
1018 /** String input data. */
1020 /** The string start pointer. */
1021 const unsigned char *start;
1022 /** The string end pointer. */
1023 const unsigned char *end;
1024 /** The string current position. */
1025 const unsigned char *current;
1028 /** File input data. */
1035 /** The working buffer. */
1037 /** The beginning of the buffer. */
1039 /** The end of the buffer. */
1041 /** The current position of the buffer. */
1042 yaml_char_t *pointer;
1043 /** The last filled position of the buffer. */
1047 /* The number of unread characters in the buffer. */
1050 /** The raw buffer. */
1052 /** The beginning of the buffer. */
1053 unsigned char *start;
1054 /** The end of the buffer. */
1056 /** The current position of the buffer. */
1057 unsigned char *pointer;
1058 /** The last filled position of the buffer. */
1059 unsigned char *last;
1062 /** The input encoding. */
1063 yaml_encoding_t encoding;
1065 /** The offset of the current position (in bytes). */
1068 /** The mark of the current position. */
1076 * @name Scanner stuff
1080 /** Have we started to scan the input stream? */
1081 int stream_start_produced;
1083 /** Have we reached the end of the input stream? */
1084 int stream_end_produced;
1086 /** The number of unclosed '[' and '{' indicators. */
1089 /** The tokens queue. */
1091 /** The beginning of the tokens queue. */
1092 yaml_token_t *start;
1093 /** The end of the tokens queue. */
1095 /** The head of the tokens queue. */
1097 /** The tail of the tokens queue. */
1101 /** The number of tokens fetched from the queue. */
1102 size_t tokens_parsed;
1104 /* Does the tokens queue contain a token ready for dequeueing. */
1105 int token_available;
1107 /** The indentation levels stack. */
1109 /** The beginning of the stack. */
1111 /** The end of the stack. */
1113 /** The top of the stack. */
1117 /** The current indentation level. */
1120 /** May a simple key occur at the current position? */
1121 int simple_key_allowed;
1123 /** The stack of simple keys. */
1125 /** The beginning of the stack. */
1126 yaml_simple_key_t *start;
1127 /** The end of the stack. */
1128 yaml_simple_key_t *end;
1129 /** The top of the stack. */
1130 yaml_simple_key_t *top;
1138 * @name Parser stuff
1142 /** The parser states stack. */
1144 /** The beginning of the stack. */
1145 yaml_parser_state_t *start;
1146 /** The end of the stack. */
1147 yaml_parser_state_t *end;
1148 /** The top of the stack. */
1149 yaml_parser_state_t *top;
1152 /** The current parser state. */
1153 yaml_parser_state_t state;
1155 /** The stack of marks. */
1157 /** The beginning of the stack. */
1159 /** The end of the stack. */
1161 /** The top of the stack. */
1165 /** The list of TAG directives. */
1167 /** The beginning of the list. */
1168 yaml_tag_directive_t *start;
1169 /** The end of the list. */
1170 yaml_tag_directive_t *end;
1171 /** The top of the list. */
1172 yaml_tag_directive_t *top;
1180 * @name Dumper stuff
1184 /** The alias data. */
1186 /** The beginning of the list. */
1187 yaml_alias_data_t *start;
1188 /** The end of the list. */
1189 yaml_alias_data_t *end;
1190 /** The top of the list. */
1191 yaml_alias_data_t *top;
1194 /** The currently parsed document. */
1195 yaml_document_t *document;
1204 * Initialize a parser.
1206 * This function creates a new parser object. An application is responsible
1207 * for destroying the object using the yaml_parser_delete() function.
1209 * @param[out] parser An empty parser object.
1211 * @returns @c 1 if the function succeeded, @c 0 on error.
1215 yaml_parser_initialize(yaml_parser_t *parser);
1220 * @param[in,out] parser A parser object.
1224 yaml_parser_delete(yaml_parser_t *parser);
1227 * Set a string input.
1229 * Note that the @a input pointer must be valid while the @a parser object
1230 * exists. The application is responsible for destroing @a input after
1231 * destroying the @a parser.
1233 * @param[in,out] parser A parser object.
1234 * @param[in] input A source data.
1235 * @param[in] size The length of the source data in bytes.
1239 yaml_parser_set_input_string(yaml_parser_t *parser,
1240 const unsigned char *input, size_t size);
1245 * @a file should be a file object open for reading. The application is
1246 * responsible for closing the @a file.
1248 * @param[in,out] parser A parser object.
1249 * @param[in] file An open file.
1253 yaml_parser_set_input_file(yaml_parser_t *parser, FILE *file);
1256 * Set a generic input handler.
1258 * @param[in,out] parser A parser object.
1259 * @param[in] handler A read handler.
1260 * @param[in] data Any application data for passing to the read
1265 yaml_parser_set_input(yaml_parser_t *parser,
1266 yaml_read_handler_t *handler, void *data);
1269 * Set the source encoding.
1271 * @param[in,out] parser A parser object.
1272 * @param[in] encoding The source encoding.
1276 yaml_parser_set_encoding(yaml_parser_t *parser, yaml_encoding_t encoding);
1279 * Scan the input stream and produce the next token.
1281 * Call the function subsequently to produce a sequence of tokens corresponding
1282 * to the input stream. The initial token has the type
1283 * @c YAML_STREAM_START_TOKEN while the ending token has the type
1284 * @c YAML_STREAM_END_TOKEN.
1286 * An application is responsible for freeing any buffers associated with the
1287 * produced token object using the @c yaml_token_delete function.
1289 * An application must not alternate the calls of yaml_parser_scan() with the
1290 * calls of yaml_parser_parse() or yaml_parser_load(). Doing this will break
1293 * @param[in,out] parser A parser object.
1294 * @param[out] token An empty token object.
1296 * @returns @c 1 if the function succeeded, @c 0 on error.
1300 yaml_parser_scan(yaml_parser_t *parser, yaml_token_t *token);
1303 * Parse the input stream and produce the next parsing event.
1305 * Call the function subsequently to produce a sequence of events corresponding
1306 * to the input stream. The initial event has the type
1307 * @c YAML_STREAM_START_EVENT while the ending event has the type
1308 * @c YAML_STREAM_END_EVENT.
1310 * An application is responsible for freeing any buffers associated with the
1311 * produced event object using the yaml_event_delete() function.
1313 * An application must not alternate the calls of yaml_parser_parse() with the
1314 * calls of yaml_parser_scan() or yaml_parser_load(). Doing this will break the
1317 * @param[in,out] parser A parser object.
1318 * @param[out] event An empty event object.
1320 * @returns @c 1 if the function succeeded, @c 0 on error.
1324 yaml_parser_parse(yaml_parser_t *parser, yaml_event_t *event);
1327 * Parse the input stream and produce the next YAML document.
1329 * Call this function subsequently to produce a sequence of documents
1330 * constituting the input stream.
1332 * If the produced document has no root node, it means that the document
1333 * end has been reached.
1335 * An application is responsible for freeing any data associated with the
1336 * produced document object using the yaml_document_delete() function.
1338 * An application must not alternate the calls of yaml_parser_load() with the
1339 * calls of yaml_parser_scan() or yaml_parser_parse(). Doing this will break
1342 * @param[in,out] parser A parser object.
1343 * @param[out] document An empty document object.
1345 * @return @c 1 if the function succeeded, @c 0 on error.
1349 yaml_parser_load(yaml_parser_t *parser, yaml_document_t *document);
1354 * @defgroup emitter Emitter Definitions
1359 * The prototype of a write handler.
1361 * The write handler is called when the emitter needs to flush the accumulated
1362 * characters to the output. The handler should write @a size bytes of the
1363 * @a buffer to the output.
1365 * @param[in,out] data A pointer to an application data specified by
1366 * yaml_emitter_set_output().
1367 * @param[in] buffer The buffer with bytes to be written.
1368 * @param[in] size The size of the buffer.
1370 * @returns On success, the handler should return @c 1. If the handler failed,
1371 * the returned value should be @c 0.
1374 typedef int yaml_write_handler_t(void *data, unsigned char *buffer, size_t size);
1376 /** The emitter states. */
1377 typedef enum yaml_emitter_state_e {
1378 YAML_EMIT_STREAM_START_STATE,
1379 YAML_EMIT_FIRST_DOCUMENT_START_STATE,
1380 YAML_EMIT_DOCUMENT_START_STATE,
1381 YAML_EMIT_DOCUMENT_CONTENT_STATE,
1382 YAML_EMIT_DOCUMENT_END_STATE,
1383 YAML_EMIT_FLOW_SEQUENCE_FIRST_ITEM_STATE,
1384 YAML_EMIT_FLOW_SEQUENCE_ITEM_STATE,
1385 YAML_EMIT_FLOW_MAPPING_FIRST_KEY_STATE,
1386 YAML_EMIT_FLOW_MAPPING_KEY_STATE,
1387 YAML_EMIT_FLOW_MAPPING_SIMPLE_VALUE_STATE,
1388 YAML_EMIT_FLOW_MAPPING_VALUE_STATE,
1389 YAML_EMIT_BLOCK_SEQUENCE_FIRST_ITEM_STATE,
1390 YAML_EMIT_BLOCK_SEQUENCE_ITEM_STATE,
1391 YAML_EMIT_BLOCK_MAPPING_FIRST_KEY_STATE,
1392 YAML_EMIT_BLOCK_MAPPING_KEY_STATE,
1393 YAML_EMIT_BLOCK_MAPPING_SIMPLE_VALUE_STATE,
1394 YAML_EMIT_BLOCK_MAPPING_VALUE_STATE,
1396 } yaml_emitter_state_t;
1399 * The emitter structure.
1401 * All members are internal. Manage the structure using the @c yaml_emitter_
1402 * family of functions.
1405 typedef struct yaml_emitter_s {
1408 * @name Error handling
1413 yaml_error_type_t error;
1414 /** Error description. */
1415 const char *problem;
1422 * @name Writer stuff
1426 /** Write handler. */
1427 yaml_write_handler_t *write_handler;
1429 /** A pointer for passing to the white handler. */
1430 void *write_handler_data;
1432 /** Standard (string or file) output data. */
1434 /** String output data. */
1436 /** The buffer pointer. */
1437 unsigned char *buffer;
1438 /** The buffer size. */
1440 /** The number of written bytes. */
1441 size_t *size_written;
1444 /** File output data. */
1448 /** The working buffer. */
1450 /** The beginning of the buffer. */
1452 /** The end of the buffer. */
1454 /** The current position of the buffer. */
1455 yaml_char_t *pointer;
1456 /** The last filled position of the buffer. */
1460 /** The raw buffer. */
1462 /** The beginning of the buffer. */
1463 unsigned char *start;
1464 /** The end of the buffer. */
1466 /** The current position of the buffer. */
1467 unsigned char *pointer;
1468 /** The last filled position of the buffer. */
1469 unsigned char *last;
1472 /** The stream encoding. */
1473 yaml_encoding_t encoding;
1480 * @name Emitter stuff
1484 /** If the output is in the canonical style? */
1486 /** The number of indentation spaces. */
1488 /** The preferred width of the output lines. */
1490 /** Allow unescaped non-ASCII characters? */
1492 /** The preferred line break. */
1493 yaml_break_t line_break;
1495 /** The stack of states. */
1497 /** The beginning of the stack. */
1498 yaml_emitter_state_t *start;
1499 /** The end of the stack. */
1500 yaml_emitter_state_t *end;
1501 /** The top of the stack. */
1502 yaml_emitter_state_t *top;
1505 /** The current emitter state. */
1506 yaml_emitter_state_t state;
1508 /** The event queue. */
1510 /** The beginning of the event queue. */
1511 yaml_event_t *start;
1512 /** The end of the event queue. */
1514 /** The head of the event queue. */
1516 /** The tail of the event queue. */
1520 /** The stack of indentation levels. */
1522 /** The beginning of the stack. */
1524 /** The end of the stack. */
1526 /** The top of the stack. */
1530 /** The list of tag directives. */
1532 /** The beginning of the list. */
1533 yaml_tag_directive_t *start;
1534 /** The end of the list. */
1535 yaml_tag_directive_t *end;
1536 /** The top of the list. */
1537 yaml_tag_directive_t *top;
1540 /** The current indentation level. */
1543 /** The current flow level. */
1546 /** Is it the document root context? */
1548 /** Is it a sequence context? */
1549 int sequence_context;
1550 /** Is it a mapping context? */
1551 int mapping_context;
1552 /** Is it a simple mapping key context? */
1553 int simple_key_context;
1555 /** The current line. */
1557 /** The current column. */
1559 /** If the last character was a whitespace? */
1561 /** If the last character was an indentation character (' ', '-', '?', ':')? */
1564 /** Anchor analysis. */
1566 /** The anchor value. */
1567 yaml_char_t *anchor;
1568 /** The anchor length. */
1569 size_t anchor_length;
1570 /** Is it an alias? */
1574 /** Tag analysis. */
1576 /** The tag handle. */
1577 yaml_char_t *handle;
1578 /** The tag handle length. */
1579 size_t handle_length;
1580 /** The tag suffix. */
1581 yaml_char_t *suffix;
1582 /** The tag suffix length. */
1583 size_t suffix_length;
1586 /** Scalar analysis. */
1588 /** The scalar value. */
1590 /** The scalar length. */
1592 /** Does the scalar contain line breaks? */
1594 /** Can the scalar be expessed in the flow plain style? */
1595 int flow_plain_allowed;
1596 /** Can the scalar be expressed in the block plain style? */
1597 int block_plain_allowed;
1598 /** Can the scalar be expressed in the single quoted style? */
1599 int single_quoted_allowed;
1600 /** Can the scalar be expressed in the literal or folded styles? */
1602 /** The output style. */
1603 yaml_scalar_style_t style;
1611 * @name Dumper stuff
1615 /** If the stream was already opened? */
1617 /** If the stream was already closed? */
1620 /** The information associated with the document nodes. */
1622 /** The number of references. */
1624 /** The anchor id. */
1626 /** If the node has been emitted? */
1630 /** The last assigned anchor id. */
1633 /** The currently emitted document. */
1634 yaml_document_t *document;
1643 * Initialize an emitter.
1645 * This function creates a new emitter object. An application is responsible
1646 * for destroying the object using the yaml_emitter_delete() function.
1648 * @param[out] emitter An empty parser object.
1650 * @returns @c 1 if the function succeeded, @c 0 on error.
1654 yaml_emitter_initialize(yaml_emitter_t *emitter);
1657 * Destroy an emitter.
1659 * @param[in,out] emitter An emitter object.
1663 yaml_emitter_delete(yaml_emitter_t *emitter);
1666 * Set a string output.
1668 * The emitter will write the output characters to the @a output buffer of the
1669 * size @a size. The emitter will set @a size_written to the number of written
1670 * bytes. If the buffer is smaller than required, the emitter produces the
1671 * YAML_WRITE_ERROR error.
1673 * @param[in,out] emitter An emitter object.
1674 * @param[in] output An output buffer.
1675 * @param[in] size The buffer size.
1676 * @param[in] size_written The pointer to save the number of written
1681 yaml_emitter_set_output_string(yaml_emitter_t *emitter,
1682 unsigned char *output, size_t size, size_t *size_written);
1685 * Set a file output.
1687 * @a file should be a file object open for writing. The application is
1688 * responsible for closing the @a file.
1690 * @param[in,out] emitter An emitter object.
1691 * @param[in] file An open file.
1695 yaml_emitter_set_output_file(yaml_emitter_t *emitter, FILE *file);
1698 * Set a generic output handler.
1700 * @param[in,out] emitter An emitter object.
1701 * @param[in] handler A write handler.
1702 * @param[in] data Any application data for passing to the write
1707 yaml_emitter_set_output(yaml_emitter_t *emitter,
1708 yaml_write_handler_t *handler, void *data);
1711 * Set the output encoding.
1713 * @param[in,out] emitter An emitter object.
1714 * @param[in] encoding The output encoding.
1718 yaml_emitter_set_encoding(yaml_emitter_t *emitter, yaml_encoding_t encoding);
1721 * Set if the output should be in the "canonical" format as in the YAML
1724 * @param[in,out] emitter An emitter object.
1725 * @param[in] canonical If the output is canonical.
1729 yaml_emitter_set_canonical(yaml_emitter_t *emitter, int canonical);
1732 * Set the intendation increment.
1734 * @param[in,out] emitter An emitter object.
1735 * @param[in] indent The indentation increment (1 < . < 10).
1739 yaml_emitter_set_indent(yaml_emitter_t *emitter, int indent);
1742 * Set the preferred line width. @c -1 means unlimited.
1744 * @param[in,out] emitter An emitter object.
1745 * @param[in] width The preferred line width.
1749 yaml_emitter_set_width(yaml_emitter_t *emitter, int width);
1752 * Set if unescaped non-ASCII characters are allowed.
1754 * @param[in,out] emitter An emitter object.
1755 * @param[in] unicode If unescaped Unicode characters are allowed.
1759 yaml_emitter_set_unicode(yaml_emitter_t *emitter, int unicode);
1762 * Set the preferred line break.
1764 * @param[in,out] emitter An emitter object.
1765 * @param[in] line_break The preferred line break.
1769 yaml_emitter_set_break(yaml_emitter_t *emitter, yaml_break_t line_break);
1774 * The event object may be generated using the yaml_parser_parse() function.
1775 * The emitter takes the responsibility for the event object and destroys its
1776 * content after it is emitted. The event object is destroyed even if the
1779 * @param[in,out] emitter An emitter object.
1780 * @param[in,out] event An event object.
1782 * @returns @c 1 if the function succeeded, @c 0 on error.
1786 yaml_emitter_emit(yaml_emitter_t *emitter, yaml_event_t *event);
1789 * Start a YAML stream.
1791 * This function should be used before yaml_emitter_dump() is called.
1793 * @param[in,out] emitter An emitter object.
1795 * @returns @c 1 if the function succeeded, @c 0 on error.
1799 yaml_emitter_open(yaml_emitter_t *emitter);
1802 * Finish a YAML stream.
1804 * This function should be used after yaml_emitter_dump() is called.
1806 * @param[in,out] emitter An emitter object.
1808 * @returns @c 1 if the function succeeded, @c 0 on error.
1812 yaml_emitter_close(yaml_emitter_t *emitter);
1815 * Emit a YAML document.
1817 * The documen object may be generated using the yaml_parser_load() function
1818 * or the yaml_document_initialize() function. The emitter takes the
1819 * responsibility for the document object and destoys its content after
1820 * it is emitted. The document object is destroyedeven if the function fails.
1822 * @param[in,out] emitter An emitter object.
1823 * @param[in,out] document A document object.
1825 * @returns @c 1 if the function succeeded, @c 0 on error.
1829 yaml_emitter_dump(yaml_emitter_t *emitter, yaml_document_t *document);
1832 * Flush the accumulated characters to the output.
1834 * @param[in,out] emitter An emitter object.
1836 * @returns @c 1 if the function succeeded, @c 0 on error.
1840 yaml_emitter_flush(yaml_emitter_t *emitter);
1848 #endif /* #ifndef YAML_H */