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. */
82 /** The major version number. */
84 /** The minor version number. */
86 } yaml_version_directive_t;
88 /** The tag directive data. */
90 /** The tag handle. */
92 /** The tag prefix. */
94 } yaml_tag_directive_t;
96 /** The stream encoding. */
100 YAML_UTF16LE_ENCODING,
101 YAML_UTF16BE_ENCODING
104 /** Line break types. */
113 /** Many bad things could happen with the parser and emitter. */
127 /** The pointer position. */
129 /** The position index. */
132 /** The position line. */
135 /** The position column. */
142 * @defgroup styles Node Styles
146 /** Scalar styles. */
148 YAML_ANY_SCALAR_STYLE,
150 YAML_PLAIN_SCALAR_STYLE,
152 YAML_SINGLE_QUOTED_SCALAR_STYLE,
153 YAML_DOUBLE_QUOTED_SCALAR_STYLE,
155 YAML_LITERAL_SCALAR_STYLE,
156 YAML_FOLDED_SCALAR_STYLE
157 } yaml_scalar_style_t;
159 /** Sequence styles. */
161 YAML_ANY_SEQUENCE_STYLE,
163 YAML_BLOCK_SEQUENCE_STYLE,
164 YAML_FLOW_SEQUENCE_STYLE
165 } yaml_sequence_style_t;
167 /** Mapping styles. */
169 YAML_ANY_MAPPING_STYLE,
171 YAML_BLOCK_MAPPING_STYLE,
172 YAML_FLOW_MAPPING_STYLE
173 /* YAML_FLOW_SET_MAPPING_STYLE */
174 } yaml_mapping_style_t;
179 * @defgroup tokens Tokens
187 YAML_STREAM_START_TOKEN,
188 YAML_STREAM_END_TOKEN,
190 YAML_VERSION_DIRECTIVE_TOKEN,
191 YAML_TAG_DIRECTIVE_TOKEN,
192 YAML_DOCUMENT_START_TOKEN,
193 YAML_DOCUMENT_END_TOKEN,
195 YAML_BLOCK_SEQUENCE_START_TOKEN,
196 YAML_BLOCK_MAPPING_START_TOKEN,
197 YAML_BLOCK_END_TOKEN,
199 YAML_FLOW_SEQUENCE_START_TOKEN,
200 YAML_FLOW_SEQUENCE_END_TOKEN,
201 YAML_FLOW_MAPPING_START_TOKEN,
202 YAML_FLOW_MAPPING_END_TOKEN,
204 YAML_BLOCK_ENTRY_TOKEN,
205 YAML_FLOW_ENTRY_TOKEN,
215 /** The token structure. */
218 /** The token type. */
219 yaml_token_type_t type;
221 /** The token data. */
224 /** The stream start (for @c YAML_STREAM_START_TOKEN). */
226 /** The stream encoding. */
227 yaml_encoding_t encoding;
230 /** The alias (for @c YAML_ALIAS_TOKEN). */
232 /** The alias value. */
236 /** The anchor (for @c YAML_ANCHOR_TOKEN). */
238 /** The anchor value. */
242 /** The tag (for @c YAML_TAG_TOKEN). */
244 /** The tag handle. */
246 /** The tag suffix. */
250 /** The scalar value (for @c YAML_SCALAR_TOKEN). */
252 /** The scalar value. */
254 /** The length of the scalar value. */
256 /** The scalar style. */
257 yaml_scalar_style_t style;
260 /** The version directive (for @c YAML_VERSION_DIRECTIVE_TOKEN). */
262 /** The major version number. */
264 /** The minor version number. */
268 /** The tag directive (for @c YAML_TAG_DIRECTIVE_TOKEN). */
270 /** The tag handle. */
272 /** The tag prefix. */
278 /** The beginning of the token. */
279 yaml_mark_t start_mark;
280 /** The end of the token. */
281 yaml_mark_t end_mark;
286 * Free any memory allocated for a token object.
288 * @param[in,out] token A token object.
292 yaml_token_delete(yaml_token_t *token);
297 * @defgroup events Events
305 YAML_STREAM_START_EVENT,
306 YAML_STREAM_END_EVENT,
308 YAML_DOCUMENT_START_EVENT,
309 YAML_DOCUMENT_END_EVENT,
314 YAML_SEQUENCE_START_EVENT,
315 YAML_SEQUENCE_END_EVENT,
317 YAML_MAPPING_START_EVENT,
318 YAML_MAPPING_END_EVENT
321 /** The event structure. */
324 /** The event type. */
325 yaml_event_type_t type;
327 /** The event data. */
330 /** The stream parameters (for @c YAML_STREAM_START_EVENT). */
332 /** The document encoding. */
333 yaml_encoding_t encoding;
336 /** The document parameters (for @c YAML_DOCUMENT_START_EVENT). */
338 /** The version directive. */
339 yaml_version_directive_t *version_directive;
341 /** The list of tag directives. */
343 /** The beginning of the tag directives list. */
344 yaml_tag_directive_t *start;
345 /** The end of the tag directives list. */
346 yaml_tag_directive_t *end;
349 /** Is the document indicator implicit? */
353 /** The document end parameters (for @c YAML_DOCUMENT_END_EVENT). */
355 /** Is the document end indicator implicit? */
359 /** The alias parameters (for @c YAML_ALIAS_EVENT). */
365 /** The scalar parameters (for @c YAML_SCALAR_EVENT). */
371 /** The scalar value. */
373 /** The length of the scalar value. */
375 /** Is the tag optional for the plain style? */
377 /** Is the tag optional for any non-plain style? */
379 /** The scalar style. */
380 yaml_scalar_style_t style;
383 /** The sequence parameters (for @c YAML_SEQUENCE_START_EVENT). */
389 /** Is the tag optional? */
391 /** The sequence style. */
392 yaml_sequence_style_t style;
395 /** The mapping parameters (for @c YAML_MAPPING_START_EVENT). */
401 /** Is the tag optional? */
403 /** The mapping style. */
404 yaml_mapping_style_t style;
409 /** The beginning of the event. */
410 yaml_mark_t start_mark;
411 /** The end of the event. */
412 yaml_mark_t end_mark;
417 * Create the STREAM-START event.
419 * @param[out] event An empty event object.
420 * @param[in] encoding The stream encoding.
422 * @returns @c 1 if the function succeeded, @c 0 on error.
426 yaml_stream_start_event_initialize(yaml_event_t *event,
427 yaml_encoding_t encoding);
430 * Create the STREAM-END event.
432 * @param[out] event An empty event object.
434 * @returns @c 1 if the function succeeded, @c 0 on error.
438 yaml_stream_end_event_initialize(yaml_event_t *event);
441 * Create the DOCUMENT-START event.
443 * The @a implicit argument is considered as a stylistic parameter and may be
444 * ignored by the emitter.
446 * @param[out] event An empty event object.
447 * @param[in] version_directive The %YAML directive value or @c NULL.
448 * @param[in] tag_directives_start The beginning of the %TAG directives list.
449 * @param[in] tag_directives_end The end of the %TAG directives list.
450 * @param[in] implicit If the document start indicator is implicit.
452 * @returns @c 1 if the function succeeded, @c 0 on error.
456 yaml_document_start_event_initialize(yaml_event_t *event,
457 yaml_version_directive_t *version_directive,
458 yaml_tag_directive_t *tag_directives_start,
459 yaml_tag_directive_t *tag_directives_end,
463 * Create the DOCUMENT-END event.
465 * The @a implicit argument is considered as a stylistic parameter and may be
466 * ignored by the emitter.
468 * @param[out] event An empty event object.
469 * @param[in] implicit If the document end indicator is implicit.
471 * @returns @c 1 if the function succeeded, @c 0 on error.
475 yaml_document_end_event_initialize(yaml_event_t *event, int implicit);
478 * Create an ALIAS event.
480 * @param[out] event An empty event object.
481 * @param[in] anchor The anchor value.
483 * @returns @c 1 if the function succeeded, @c 0 on error.
487 yaml_alias_event_initialize(yaml_event_t *event, yaml_char_t *anchor);
490 * Create a SCALAR event.
492 * The @a style argument may be ignored by the emitter.
494 * Either the @a tag attribute or one of the @a plain_implicit and
495 * @a quoted_implicit flags must be set.
497 * @param[out] event An empty event object.
498 * @param[in] anchor The scalar anchor or @c NULL.
499 * @param[in] tag The scalar tag or @c NULL.
500 * @param[in] value The scalar value.
501 * @param[in] length The length of the scalar value.
502 * @param[in] plain_implicit If the tag may be omitted for the plain style.
503 * @param[in] quoted_implicit If the tag may be omitted for any non-plain style.
504 * @param[in] style The scalar style.
506 * @returns @c 1 if the function succeeded, @c 0 on error.
510 yaml_scalar_event_initialize(yaml_event_t *event,
511 yaml_char_t *anchor, yaml_char_t *tag,
512 yaml_char_t *value, int length,
513 int plain_implicit, int quoted_implicit,
514 yaml_scalar_style_t style);
517 * Create a SEQUENCE-START event.
519 * The @a style argument may be ignored by the emitter.
521 * Either the @a tag attribute or the @a implicit flag must be set.
523 * @param[out] event An empty event object.
524 * @param[in] anchor The sequence anchor or @c NULL.
525 * @param[in] tag The sequence tag or @c NULL.
526 * @param[in] implicit If the tag may be omitted.
527 * @param[in] style The sequence style.
529 * @returns @c 1 if the function succeeded, @c 0 on error.
533 yaml_sequence_start_event_initialize(yaml_event_t *event,
534 yaml_char_t *anchor, yaml_char_t *tag, int implicit,
535 yaml_sequence_style_t style);
538 * Create a SEQUENCE-END event.
540 * @param[out] event An empty event object.
542 * @returns @c 1 if the function succeeded, @c 0 on error.
546 yaml_sequence_end_event_initialize(yaml_event_t *event);
549 * Create a MAPPING-START event.
551 * The @a style argument may be ignored by the emitter.
553 * Either the @a tag attribute or the @a implicit flag must be set.
555 * @param[out] event An empty event object.
556 * @param[in] anchor The mapping anchor or @c NULL.
557 * @param[in] tag The mapping tag or @c NULL.
558 * @param[in] implicit If the tag may be omitted.
559 * @param[in] style The mapping style.
561 * @returns @c 1 if the function succeeded, @c 0 on error.
565 yaml_mapping_start_event_initialize(yaml_event_t *event,
566 yaml_char_t *anchor, yaml_char_t *tag, int implicit,
567 yaml_mapping_style_t style);
570 * Create a MAPPING-END event.
572 * @param[out] event An empty event object.
574 * @returns @c 1 if the function succeeded, @c 0 on error.
578 yaml_mapping_end_event_initialize(yaml_event_t *event);
581 * Free any memory allocated for an event object.
583 * @param[out] event An event object.
587 yaml_event_delete(yaml_event_t *event);
590 * @defgroup nodes Nodes
594 #define YAML_NULL_TAG "tag:yaml.org,2002:null"
595 #define YAML_BOOL_TAG "tag:yaml.org,2002:bool"
596 #define YAML_STR_TAG "tag:yaml.org,2002:str"
597 #define YAML_INT_TAG "tag:yaml.org,2002:int"
598 #define YAML_FLOAT_TAG "tag:yaml.org,2002:float"
599 #define YAML_TIMESTAMP_TAG "tag:yaml.org,2002:timestamp"
601 #define YAML_SEQ_TAG "tag:yaml.org,2002:seq"
602 #define YAML_MAP_TAG "tag:yaml.org,2002:map"
604 #define YAML_DEFAULT_SCALAR_TAG YAML_STR_TAG
605 #define YAML_DEFAULT_SEQUENCE_TAG YAML_SEQ_TAG
606 #define YAML_DEFAULT_MAPPING_STYLE YAML_MAP_TAG
619 typedef struct _yaml_node_t yaml_node_item_t;
622 yaml_node_item_t key;
623 yaml_node_item_t value;
626 /** The node structure. */
627 typedef struct _yaml_node_t {
629 /** The node type. */
630 yaml_node_type_t type;
632 /* The reference counter. */
635 /** The node data. */
638 /** The scalar parameters (for @c YAML_SCALAR_NODE). */
642 /** The scalar value. */
644 /** The length of the scalar value. */
646 /** The scalar style. */
647 yaml_scalar_style_t style;
650 /** The sequence parameters (for @c YAML_SEQUENCE_NODE). */
654 /** The stack of sequence items. */
656 /** The beginning of the stack. */
657 struct yaml_node_item_t *start;
658 /** The end of the stack. */
659 struct yaml_node_item_t *end;
660 /** The top of the stack. */
661 struct yaml_node_item_t *top;
663 /** The sequence style. */
664 yaml_sequence_style_t style;
667 /** The mapping parameters (for @c YAML_MAPPING_NODE). */
671 /** The stack of mapping pairs. */
673 /** The beginning of the stack. */
674 struct yaml_node_pair_t *start;
675 /** The end of the stack. */
676 struct yaml_node_pair_t *end;
677 /** The top of the stack. */
678 struct yaml_node_pair_t *top;
680 /** The mapping style. */
681 yaml_mapping_style_t style;
686 /** The beginning of the node. */
687 yaml_mark_t start_mark;
688 /** The end of the node. */
689 yaml_mark_t end_mark;
694 * Create a SCALAR node.
696 * The @a style argument may be ignored by the emitter.
698 * @param[out] node An empty node object.
699 * @param[in] tag The scalar tag.
700 * @param[in] value The scalar value.
701 * @param[in] length The length of the scalar value.
702 * @param[in] style The scalar style.
704 * @returns @c 1 if the function succeeded, @c 0 on error.
708 yaml_scalar_node_initialize(yaml_node_t *node,
709 yaml_char_t *tag, yaml_char_t *value, int length,
710 yaml_scalar_style_t style);
713 * Create a SEQUENCE node.
715 * The @a style argument may be ignored by the emitter.
717 * @param[out] node An empty node object.
718 * @param[in] tag The sequence tag.
719 * @param[in] style The sequence style.
721 * @returns @c 1 if the function succeeded, @c 0 on error.
725 yaml_sequence_node_initialize(yaml_node_t *node,
726 yaml_char_t *tag, yaml_sequence_style_t style);
729 * Add an item to a SEQUENCE node
731 * @param[out] node A sequence node.
732 * @param[in] item An item node.
734 * @returns @c 1 if the function succeeded, @c 0 on error.
738 yaml_sequence_node_add_item(yaml_node_t *node, yaml_node_t *item)
741 * Create a SCALAR node and add it to a SEQUENCE node.
743 * @param[out] node A sequence node.
744 * @param[in] tag The scalar tag.
745 * @param[in] value The scalar value.
746 * @param[in] length The length of the scalar value.
747 * @param[in] style The scalar style.
749 * @returns @c 1 if the function succeeded, @c 0 on error.
753 yaml_sequence_node_add_scalar_item(yaml_node_t *node,
754 yaml_char_t *tag, yaml_char_t *value, int length,
755 yaml_scalar_style_t style);
758 * Get the number of subnodes of a SEQUENCE node.
760 * @param[in] node A sequence node.
762 * @returns the number of subnodes.
766 yaml_sequence_node_get_length(yaml_node_t *node);
769 * Get a subnode of a SEQUENCE node.
771 * @param[in] node A sequence node.
772 * @param[in] index The index of a subnode.
773 * @param[out] item A subnode.
777 yaml_sequence_node_get_item(yaml_node_t *node, size_t index,
781 * Create a MAPPING node.
783 * The @a style argument may be ignored by the emitter.
785 * @param[out] node An empty node object.
786 * @param[in] tag The mapping tag.
787 * @param[in] style The mapping style.
789 * @returns @c 1 if the function succeeded, @c 0 on error.
793 yaml_mapping_node_initialize(yaml_node_t *node,
794 yaml_char_t *tag, yaml_mapping_style_t style);
797 * Add a key/value pair of nodes to a MAPPING node.
799 * @param[out] node A mapping node.
800 * @param[in] key A key node.
801 * @param[in] value A value node.
803 * @returns @c 1 if the function succeeded, @c 0 on error.
807 yaml_mapping_node_add_pair(yaml_node_t *node,
808 yaml_node_t *key, yaml_node_t *value)
811 * Create a scalar key and add the key/value pair to a MAPPING node.
813 * @param[out] node A mapping node.
814 * @param[in] key_tag The key node tag.
815 * @param[in] key_value The key node value.
816 * @param[in] key_length The length of the key node value.
817 * @param[in] key_style The key node style.
818 * @param[in] value A value node.
820 * @returns @c 1 if the function succeeded, @c 0 on error.
824 yaml_sequence_node_add_scalar_key_pair(yaml_node_t *node,
825 yaml_char_t *key_tag, yaml_char_t *key_value, int key_length,
826 yaml_scalar_style_t key_style,
830 * Create a scalar key/value nodes and add the pair to a MAPPING node.
832 * @param[out] node A mapping node.
833 * @param[in] key_tag The key node tag.
834 * @param[in] key_value The key node value.
835 * @param[in] key_length The length of the key node value.
836 * @param[in] key_style The key node style.
837 * @param[in] value_tag The value node tag.
838 * @param[in] value_value The value node value.
839 * @param[in] value_length The length of the value node value.
840 * @param[in] value_style The value node style.
842 * @returns @c 1 if the function succeeded, @c 0 on error.
846 yaml_sequence_node_add_scalar_pair(yaml_node_t *node,
847 yaml_char_t *key_tag, yaml_char_t *key_value, int key_length,
848 yaml_scalar_style_t key_style,
849 yaml_char_t *value_tag, yaml_char_t *value_value, int value_length,
850 yaml_scalar_style_t value_style);
853 * Get the number of subnode pairs of a MAPPING node.
855 * @param[in] node A mapping node.
857 * @returns the number of pairs.
861 yaml_mapping_node_get_length(yaml_node_t *node);
864 * Get a subnode of a SEQUENCE node.
866 * @param[in] node A sequence node.
867 * @param[in] index The index of a subnode.
868 * @param[out] key The key subnode.
869 * @param[out] value The value subnode.
873 yaml_mapping_node_get_pair(yaml_node_t *node, size_t index,
874 yaml_node_t *key, yaml_node_t *value);
877 * Delete a node and its subnodes.
879 * @param[out] node A node object.
883 yaml_node_delete(yaml_node_t *node);
890 * @defgroup parser Parser Definitions
895 * The prototype of a read handler.
897 * The read handler is called when the parser needs to read more bytes from the
898 * source. The handler should write not more than @a size bytes to the @a
899 * buffer. The number of written bytes should be set to the @a length variable.
901 * @param[in,out] data A pointer to an application data specified by
902 * yaml_parser_set_input().
903 * @param[out] buffer The buffer to write the data from the source.
904 * @param[in] size The size of the buffer.
905 * @param[out] size_read The actual number of bytes read from the source.
907 * @returns On success, the handler should return @c 1. If the handler failed,
908 * the returned value should be @c 0. On EOF, the handler should set the
909 * @a size_read to @c 0 and return @c 1.
912 typedef int yaml_read_handler_t(void *data, unsigned char *buffer, size_t size,
916 * This structure holds information about a potential simple key.
920 /** Is a simple key possible? */
923 /** Is a simple key required? */
926 /** The number of the token. */
929 /** The position mark. */
934 * The states of the parser.
937 YAML_PARSE_STREAM_START_STATE,
938 YAML_PARSE_IMPLICIT_DOCUMENT_START_STATE,
939 YAML_PARSE_DOCUMENT_START_STATE,
940 YAML_PARSE_DOCUMENT_CONTENT_STATE,
941 YAML_PARSE_DOCUMENT_END_STATE,
942 YAML_PARSE_BLOCK_NODE_STATE,
943 YAML_PARSE_BLOCK_NODE_OR_INDENTLESS_SEQUENCE_STATE,
944 YAML_PARSE_FLOW_NODE_STATE,
945 YAML_PARSE_BLOCK_SEQUENCE_FIRST_ENTRY_STATE,
946 YAML_PARSE_BLOCK_SEQUENCE_ENTRY_STATE,
947 YAML_PARSE_INDENTLESS_SEQUENCE_ENTRY_STATE,
948 YAML_PARSE_BLOCK_MAPPING_FIRST_KEY_STATE,
949 YAML_PARSE_BLOCK_MAPPING_KEY_STATE,
950 YAML_PARSE_BLOCK_MAPPING_VALUE_STATE,
951 YAML_PARSE_FLOW_SEQUENCE_FIRST_ENTRY_STATE,
952 YAML_PARSE_FLOW_SEQUENCE_ENTRY_STATE,
953 YAML_PARSE_FLOW_SEQUENCE_ENTRY_MAPPING_KEY_STATE,
954 YAML_PARSE_FLOW_SEQUENCE_ENTRY_MAPPING_VALUE_STATE,
955 YAML_PARSE_FLOW_SEQUENCE_ENTRY_MAPPING_END_STATE,
956 YAML_PARSE_FLOW_MAPPING_FIRST_KEY_STATE,
957 YAML_PARSE_FLOW_MAPPING_KEY_STATE,
958 YAML_PARSE_FLOW_MAPPING_VALUE_STATE,
959 YAML_PARSE_FLOW_MAPPING_EMPTY_VALUE_STATE,
961 } yaml_parser_state_t;
964 * The parser structure.
966 * All members are internal. Manage the structure using the @c yaml_parser_
967 * family of functions.
973 * @name Error handling
978 yaml_error_type_t error;
979 /** Error description. */
981 /** The byte about which the problem occured. */
982 size_t problem_offset;
983 /** The problematic value (@c -1 is none). */
985 /** The problem position. */
986 yaml_mark_t problem_mark;
987 /** The error context. */
989 /** The context position. */
990 yaml_mark_t context_mark;
1001 /** Read handler. */
1002 yaml_read_handler_t *read_handler;
1004 /** A pointer for passing to the read handler. */
1005 void *read_handler_data;
1007 /** Standard (string or file) input data. */
1009 /** String input data. */
1011 /** The string start pointer. */
1012 const unsigned char *start;
1013 /** The string end pointer. */
1014 const unsigned char *end;
1015 /** The string current position. */
1016 const unsigned char *current;
1019 /** File input data. */
1026 /** The working buffer. */
1028 /** The beginning of the buffer. */
1030 /** The end of the buffer. */
1032 /** The current position of the buffer. */
1033 yaml_char_t *pointer;
1034 /** The last filled position of the buffer. */
1038 /* The number of unread characters in the buffer. */
1041 /** The raw buffer. */
1043 /** The beginning of the buffer. */
1044 unsigned char *start;
1045 /** The end of the buffer. */
1047 /** The current position of the buffer. */
1048 unsigned char *pointer;
1049 /** The last filled position of the buffer. */
1050 unsigned char *last;
1053 /** The input encoding. */
1054 yaml_encoding_t encoding;
1056 /** The offset of the current position (in bytes). */
1059 /** The mark of the current position. */
1067 * @name Scanner stuff
1071 /** Have we started to scan the input stream? */
1072 int stream_start_produced;
1074 /** Have we reached the end of the input stream? */
1075 int stream_end_produced;
1077 /** The number of unclosed '[' and '{' indicators. */
1080 /** The tokens queue. */
1082 /** The beginning of the tokens queue. */
1083 yaml_token_t *start;
1084 /** The end of the tokens queue. */
1086 /** The head of the tokens queue. */
1088 /** The tail of the tokens queue. */
1092 /** The number of tokens fetched from the queue. */
1093 size_t tokens_parsed;
1095 /* Does the tokens queue contain a token ready for dequeueing. */
1096 int token_available;
1098 /** The indentation levels stack. */
1100 /** The beginning of the stack. */
1102 /** The end of the stack. */
1104 /** The top of the stack. */
1108 /** The current indentation level. */
1111 /** May a simple key occur at the current position? */
1112 int simple_key_allowed;
1114 /** The stack of simple keys. */
1116 /** The beginning of the stack. */
1117 yaml_simple_key_t *start;
1118 /** The end of the stack. */
1119 yaml_simple_key_t *end;
1120 /** The top of the stack. */
1121 yaml_simple_key_t *top;
1129 * @name Parser stuff
1133 /** The parser states stack. */
1135 /** The beginning of the stack. */
1136 yaml_parser_state_t *start;
1137 /** The end of the stack. */
1138 yaml_parser_state_t *end;
1139 /** The top of the stack. */
1140 yaml_parser_state_t *top;
1143 /** The current parser state. */
1144 yaml_parser_state_t state;
1146 /** The stack of marks. */
1148 /** The beginning of the stack. */
1150 /** The end of the stack. */
1152 /** The top of the stack. */
1156 /** The list of TAG directives. */
1158 /** The beginning of the list. */
1159 yaml_tag_directive_t *start;
1160 /** The end of the list. */
1161 yaml_tag_directive_t *end;
1162 /** The top of the list. */
1163 yaml_tag_directive_t *top;
1173 * Initialize a parser.
1175 * This function creates a new parser object. An application is responsible
1176 * for destroying the object using the yaml_parser_delete() function.
1178 * @param[out] parser An empty parser object.
1180 * @returns @c 1 if the function succeeded, @c 0 on error.
1184 yaml_parser_initialize(yaml_parser_t *parser);
1189 * @param[in,out] parser A parser object.
1193 yaml_parser_delete(yaml_parser_t *parser);
1196 * Set a string input.
1198 * Note that the @a input pointer must be valid while the @a parser object
1199 * exists. The application is responsible for destroing @a input after
1200 * destroying the @a parser.
1202 * @param[in,out] parser A parser object.
1203 * @param[in] input A source data.
1204 * @param[in] size The length of the source data in bytes.
1208 yaml_parser_set_input_string(yaml_parser_t *parser,
1209 const unsigned char *input, size_t size);
1214 * @a file should be a file object open for reading. The application is
1215 * responsible for closing the @a file.
1217 * @param[in,out] parser A parser object.
1218 * @param[in] file An open file.
1222 yaml_parser_set_input_file(yaml_parser_t *parser, FILE *file);
1225 * Set a generic input handler.
1227 * @param[in,out] parser A parser object.
1228 * @param[in] handler A read handler.
1229 * @param[in] data Any application data for passing to the read
1234 yaml_parser_set_input(yaml_parser_t *parser,
1235 yaml_read_handler_t *handler, void *data);
1238 * Set the source encoding.
1240 * @param[in,out] parser A parser object.
1241 * @param[in] encoding The source encoding.
1245 yaml_parser_set_encoding(yaml_parser_t *parser, yaml_encoding_t encoding);
1248 * Scan the input stream and produce the next token.
1250 * Call the function subsequently to produce a sequence of tokens corresponding
1251 * to the input stream. The initial token has the type
1252 * @c YAML_STREAM_START_TOKEN while the ending token has the type
1253 * @c YAML_STREAM_END_TOKEN.
1255 * An application is responsible for freeing any buffers associated with the
1256 * produced token object using the @c yaml_token_delete function.
1258 * An application must not alternate the calls of yaml_parser_scan() with the
1259 * calls of yaml_parser_parse(). Doing this will break the parser.
1261 * @param[in,out] parser A parser object.
1262 * @param[out] token An empty token object.
1264 * @returns @c 1 if the function succeeded, @c 0 on error.
1268 yaml_parser_scan(yaml_parser_t *parser, yaml_token_t *token);
1271 * Parse the input stream and produce the next parsing event.
1273 * Call the function subsequently to produce a sequence of events corresponding
1274 * to the input stream. The initial event has the type
1275 * @c YAML_STREAM_START_EVENT while the ending event has the type
1276 * @c YAML_STREAM_END_EVENT.
1278 * An application is responsible for freeing any buffers associated with the
1279 * produced event object using the yaml_event_delete() function.
1281 * An application must not alternate the calls of yaml_parser_scan() with the
1282 * calls of yaml_parser_parse(). Doing this will break the parser.
1284 * @param[in,out] parser A parser object.
1285 * @param[out] event An empty event object.
1287 * @returns @c 1 if the function succeeded, @c 0 on error.
1291 yaml_parser_parse(yaml_parser_t *parser, yaml_event_t *event);
1296 * @defgroup emitter Emitter Definitions
1301 * The prototype of a write handler.
1303 * The write handler is called when the emitter needs to flush the accumulated
1304 * characters to the output. The handler should write @a size bytes of the
1305 * @a buffer to the output.
1307 * @param[in,out] data A pointer to an application data specified by
1308 * yaml_emitter_set_output().
1309 * @param[in] buffer The buffer with bytes to be written.
1310 * @param[in] size The size of the buffer.
1312 * @returns On success, the handler should return @c 1. If the handler failed,
1313 * the returned value should be @c 0.
1316 typedef int yaml_write_handler_t(void *data, unsigned char *buffer, size_t size);
1318 /** The emitter states. */
1320 YAML_EMIT_STREAM_START_STATE,
1321 YAML_EMIT_FIRST_DOCUMENT_START_STATE,
1322 YAML_EMIT_DOCUMENT_START_STATE,
1323 YAML_EMIT_DOCUMENT_CONTENT_STATE,
1324 YAML_EMIT_DOCUMENT_END_STATE,
1325 YAML_EMIT_FLOW_SEQUENCE_FIRST_ITEM_STATE,
1326 YAML_EMIT_FLOW_SEQUENCE_ITEM_STATE,
1327 YAML_EMIT_FLOW_MAPPING_FIRST_KEY_STATE,
1328 YAML_EMIT_FLOW_MAPPING_KEY_STATE,
1329 YAML_EMIT_FLOW_MAPPING_SIMPLE_VALUE_STATE,
1330 YAML_EMIT_FLOW_MAPPING_VALUE_STATE,
1331 YAML_EMIT_BLOCK_SEQUENCE_FIRST_ITEM_STATE,
1332 YAML_EMIT_BLOCK_SEQUENCE_ITEM_STATE,
1333 YAML_EMIT_BLOCK_MAPPING_FIRST_KEY_STATE,
1334 YAML_EMIT_BLOCK_MAPPING_KEY_STATE,
1335 YAML_EMIT_BLOCK_MAPPING_SIMPLE_VALUE_STATE,
1336 YAML_EMIT_BLOCK_MAPPING_VALUE_STATE,
1338 } yaml_emitter_state_t;
1341 * The emitter structure.
1343 * All members are internal. Manage the structure using the @c yaml_emitter_
1344 * family of functions.
1350 * @name Error handling
1355 yaml_error_type_t error;
1356 /** Error description. */
1357 const char *problem;
1364 * @name Writer stuff
1368 /** Write handler. */
1369 yaml_write_handler_t *write_handler;
1371 /** A pointer for passing to the white handler. */
1372 void *write_handler_data;
1374 /** Standard (string or file) output data. */
1376 /** String output data. */
1378 /** The buffer pointer. */
1379 unsigned char *buffer;
1380 /** The buffer size. */
1382 /** The number of written bytes. */
1383 size_t *size_written;
1386 /** File output data. */
1390 /** The working buffer. */
1392 /** The beginning of the buffer. */
1394 /** The end of the buffer. */
1396 /** The current position of the buffer. */
1397 yaml_char_t *pointer;
1398 /** The last filled position of the buffer. */
1402 /** The raw buffer. */
1404 /** The beginning of the buffer. */
1405 unsigned char *start;
1406 /** The end of the buffer. */
1408 /** The current position of the buffer. */
1409 unsigned char *pointer;
1410 /** The last filled position of the buffer. */
1411 unsigned char *last;
1414 /** The stream encoding. */
1415 yaml_encoding_t encoding;
1422 * @name Emitter stuff
1426 /** If the output is in the canonical style? */
1428 /** The number of indentation spaces. */
1430 /** The preferred width of the output lines. */
1432 /** Allow unescaped non-ASCII characters? */
1434 /** The preferred line break. */
1435 yaml_break_t line_break;
1437 /** The stack of states. */
1439 /** The beginning of the stack. */
1440 yaml_emitter_state_t *start;
1441 /** The end of the stack. */
1442 yaml_emitter_state_t *end;
1443 /** The top of the stack. */
1444 yaml_emitter_state_t *top;
1447 /** The current emitter state. */
1448 yaml_emitter_state_t state;
1450 /** The event queue. */
1452 /** The beginning of the event queue. */
1453 yaml_event_t *start;
1454 /** The end of the event queue. */
1456 /** The head of the event queue. */
1458 /** The tail of the event queue. */
1462 /** The stack of indentation levels. */
1464 /** The beginning of the stack. */
1466 /** The end of the stack. */
1468 /** The top of the stack. */
1472 /** The list of tag directives. */
1474 /** The beginning of the list. */
1475 yaml_tag_directive_t *start;
1476 /** The end of the list. */
1477 yaml_tag_directive_t *end;
1478 /** The top of the list. */
1479 yaml_tag_directive_t *top;
1482 /** The current indentation level. */
1485 /** The current flow level. */
1488 /** Is it the document root context? */
1490 /** Is it a sequence context? */
1491 int sequence_context;
1492 /** Is it a mapping context? */
1493 int mapping_context;
1494 /** Is it a simple mapping key context? */
1495 int simple_key_context;
1497 /** The current line. */
1499 /** The current column. */
1501 /** If the last character was a whitespace? */
1503 /** If the last character was an indentation character (' ', '-', '?', ':')? */
1506 /** Anchor analysis. */
1508 /** The anchor value. */
1509 yaml_char_t *anchor;
1510 /** The anchor length. */
1511 size_t anchor_length;
1512 /** Is it an alias? */
1516 /** Tag analysis. */
1518 /** The tag handle. */
1519 yaml_char_t *handle;
1520 /** The tag handle length. */
1521 size_t handle_length;
1522 /** The tag suffix. */
1523 yaml_char_t *suffix;
1524 /** The tag suffix length. */
1525 size_t suffix_length;
1528 /** Scalar analysis. */
1530 /** The scalar value. */
1532 /** The scalar length. */
1534 /** Does the scalar contain line breaks? */
1536 /** Can the scalar be expessed in the flow plain style? */
1537 int flow_plain_allowed;
1538 /** Can the scalar be expressed in the block plain style? */
1539 int block_plain_allowed;
1540 /** Can the scalar be expressed in the single quoted style? */
1541 int single_quoted_allowed;
1542 /** Can the scalar be expressed in the literal or folded styles? */
1544 /** The output style. */
1545 yaml_scalar_style_t style;
1555 * Initialize an emitter.
1557 * This function creates a new emitter object. An application is responsible
1558 * for destroying the object using the yaml_emitter_delete() function.
1560 * @param[out] emitter An empty parser object.
1562 * @returns @c 1 if the function succeeded, @c 0 on error.
1566 yaml_emitter_initialize(yaml_emitter_t *emitter);
1569 * Destroy an emitter.
1571 * @param[in,out] emitter An emitter object.
1575 yaml_emitter_delete(yaml_emitter_t *emitter);
1578 * Set a string output.
1580 * The emitter will write the output characters to the @a output buffer of the
1581 * size @a size. The emitter will set @a size_written to the number of written
1582 * bytes. If the buffer is smaller than required, the emitter produces the
1583 * YAML_WRITE_ERROR error.
1585 * @param[in,out] emitter An emitter object.
1586 * @param[in] output An output buffer.
1587 * @param[in] size The buffer size.
1588 * @param[in] size_written The pointer to save the number of written
1593 yaml_emitter_set_output_string(yaml_emitter_t *emitter,
1594 unsigned char *output, size_t size, size_t *size_written);
1597 * Set a file output.
1599 * @a file should be a file object open for writing. The application is
1600 * responsible for closing the @a file.
1602 * @param[in,out] emitter An emitter object.
1603 * @param[in] file An open file.
1607 yaml_emitter_set_output_file(yaml_emitter_t *emitter, FILE *file);
1610 * Set a generic output handler.
1612 * @param[in,out] emitter An emitter object.
1613 * @param[in] handler A write handler.
1614 * @param[in] data Any application data for passing to the write
1619 yaml_emitter_set_output(yaml_emitter_t *emitter,
1620 yaml_write_handler_t *handler, void *data);
1623 * Set the output encoding.
1625 * @param[in,out] emitter An emitter object.
1626 * @param[in] encoding The output encoding.
1630 yaml_emitter_set_encoding(yaml_emitter_t *emitter, yaml_encoding_t encoding);
1633 * Set if the output should be in the "canonical" format as in the YAML
1636 * @param[in,out] emitter An emitter object.
1637 * @param[in] canonical If the output is canonical.
1641 yaml_emitter_set_canonical(yaml_emitter_t *emitter, int canonical);
1644 * Set the intendation increment.
1646 * @param[in,out] emitter An emitter object.
1647 * @param[in] indent The indentation increment (1 < . < 10).
1651 yaml_emitter_set_indent(yaml_emitter_t *emitter, int indent);
1654 * Set the preferred line width. @c -1 means unlimited.
1656 * @param[in,out] emitter An emitter object.
1657 * @param[in] width The preferred line width.
1661 yaml_emitter_set_width(yaml_emitter_t *emitter, int width);
1664 * Set if unescaped non-ASCII characters are allowed.
1666 * @param[in,out] emitter An emitter object.
1667 * @param[in] unicode If unescaped Unicode characters are allowed.
1671 yaml_emitter_set_unicode(yaml_emitter_t *emitter, int unicode);
1674 * Set the preferred line break.
1676 * @param[in,out] emitter An emitter object.
1677 * @param[in] line_break The preferred line break.
1681 yaml_emitter_set_break(yaml_emitter_t *emitter, yaml_break_t line_break);
1686 * The event object may be generated using the yaml_parser_parse() function.
1687 * The emitter takes the responsibility for the event object and destroys its
1688 * content after it is emitted. The event object is destroyed even if the
1691 * @param[in,out] emitter An emitter object.
1692 * @param[in,out] event An event object.
1694 * @returns @c 1 if the function succeeded, @c 0 on error.
1698 yaml_emitter_emit(yaml_emitter_t *emitter, yaml_event_t *event);
1701 * Flush the accumulated characters to the output.
1703 * @param[in,out] emitter An emitter object.
1705 * @returns @c 1 if the function succeeded, @c 0 on error.
1709 yaml_emitter_flush(yaml_emitter_t *emitter);
1717 #endif /* #ifndef YAML_H */