1 ! Copyright (C) 2013 Jon Harper.
2 ! See https://factorcode.org/license.txt for BSD license.
3 ! adapted from "yaml.h" libYAML 0.1.4
4 ! https://pyyaml.org/wiki/LibYAML
5 USING: alien alien.c-types alien.destructors alien.libraries
6 alien.syntax classes.struct combinators literals system
7 alien.libraries.finder ;
11 "libyaml" { "yaml" "yaml-0" "libyaml-0-2" } find-library-from-list cdecl add-library
19 ! * @defgroup version Version Information
24 ! * Get the library version as a string.
26 ! * @returns The function returns the pointer to a static string of the form
27 ! * @c "X.Y.Z", where @c X is the major version number, @c Y is a minor version
28 ! * number, and @c Z is the patch version number.
31 yaml_get_version_string ( )
34 ! * Get the library version numbers.
36 ! * @param[out] major Major version number.
37 ! * @param[out] minor Minor version number.
38 ! * @param[out] patch Patch version number.
41 yaml_get_version ( int *major, int *minor, int *patch )
46 ! * @defgroup basic Basic Types
50 ! /** The character type (UTF-8 octet). */
51 ! libYAML returns it's data as null-terminated UTF-8 string.
52 ! It copies it's input and we can use null-terminated string
53 ! if we give a negative length. So we can use factor's c-string
54 ! for input and output.
55 TYPEDEF: uchar yaml_char_t
57 ! /** The version directive data. */
58 STRUCT: yaml_version_directive_t
63 ! /** The tag directive data. */
64 STRUCT: yaml_tag_directive_t
69 ! /** The stream encoding. */
77 ! /** Line break types. */
85 ! /** Many bad things could happen with the parser and emitter. */
86 ENUM: yaml_error_type_t
100 ! /** The pointer position. */
110 ! * @defgroup styles Node Styles
114 ! /** Scalar styles. */
115 ENUM: yaml_scalar_style_t
116 YAML_ANY_SCALAR_STYLE
118 YAML_PLAIN_SCALAR_STYLE
120 YAML_SINGLE_QUOTED_SCALAR_STYLE
121 YAML_DOUBLE_QUOTED_SCALAR_STYLE
123 YAML_LITERAL_SCALAR_STYLE
124 YAML_FOLDED_SCALAR_STYLE
127 ! /** Sequence styles. */
128 ENUM: yaml_sequence_style_t
129 YAML_ANY_SEQUENCE_STYLE
131 YAML_BLOCK_SEQUENCE_STYLE
132 YAML_FLOW_SEQUENCE_STYLE
135 ! /** Mapping styles. */
136 ENUM: yaml_mapping_style_t
137 YAML_ANY_MAPPING_STYLE
139 YAML_BLOCK_MAPPING_STYLE
140 YAML_FLOW_MAPPING_STYLE
146 ! * @defgroup tokens Tokens
150 ! /** Token types. */
151 ENUM: yaml_token_type_t
154 YAML_STREAM_START_TOKEN
155 YAML_STREAM_END_TOKEN
157 YAML_VERSION_DIRECTIVE_TOKEN
158 YAML_TAG_DIRECTIVE_TOKEN
159 YAML_DOCUMENT_START_TOKEN
160 YAML_DOCUMENT_END_TOKEN
162 YAML_BLOCK_SEQUENCE_START_TOKEN
163 YAML_BLOCK_MAPPING_START_TOKEN
166 YAML_FLOW_SEQUENCE_START_TOKEN
167 YAML_FLOW_SEQUENCE_END_TOKEN
168 YAML_FLOW_MAPPING_START_TOKEN
169 YAML_FLOW_MAPPING_END_TOKEN
171 YAML_BLOCK_ENTRY_TOKEN
172 YAML_FLOW_ENTRY_TOKEN
182 ! /** The token structure. */
183 ! /** The stream start (for @c YAML_STREAM_START_TOKEN). */
184 STRUCT: stream_start_token_data
185 { encoding yaml_encoding_t }
187 ! /** The alias (for @c YAML_ALIAS_TOKEN). */
188 STRUCT: alias_token_data
191 ! /** The anchor (for @c YAML_ANCHOR_TOKEN). */
192 STRUCT: anchor_token_data
196 ! /** The tag (for @c YAML_TAG_TOKEN). */
197 STRUCT: tag_token_data
202 ! /** The scalar value (for @c YAML_SCALAR_TOKEN). */
203 STRUCT: scalar_token_data
206 { style yaml_scalar_style_t }
209 ! /** The version directive (for @c YAML_VERSION_DIRECTIVE_TOKEN). */
210 STRUCT: version_directive_token_data
215 UNION-STRUCT: token_data
216 { stream_start stream_start_token_data }
217 { alias alias_token_data }
218 { anchor anchor_token_data }
219 { tag tag_token_data }
220 { scalar scalar_token_data }
221 { version_directive version_directive_token_data }
225 { type yaml_token_type_t }
229 { start_mark yaml_mark_t }
230 { end_mark yaml_mark_t }
234 ! * Free any memory allocated for a token object.
236 ! * @param[in,out] token A token object.
240 yaml_token_delete ( yaml_token_t *token )
241 DESTRUCTOR: yaml_token_delete
246 ! * @defgroup events Events
250 ! /** Event types. */
251 ENUM: yaml_event_type_t
254 YAML_STREAM_START_EVENT
255 YAML_STREAM_END_EVENT
257 YAML_DOCUMENT_START_EVENT
258 YAML_DOCUMENT_END_EVENT
263 YAML_SEQUENCE_START_EVENT
264 YAML_SEQUENCE_END_EVENT
266 YAML_MAPPING_START_EVENT
267 YAML_MAPPING_END_EVENT
270 ! /** The event structure. */
272 ! /** The event data. */
273 ! /** The stream parameters (for @c YAML_STREAM_START_EVENT). */
274 STRUCT: stream_start_event_data
275 { encoding yaml_encoding_t }
278 ! /** The document parameters (for @c YAML_DOCUMENT_START_EVENT). */
279 ! /** The list of tag directives. */
280 STRUCT: tag_directives_document_start_event_data
281 { start yaml_tag_directive_t* }
282 { end yaml_tag_directive_t* }
284 STRUCT: document_start_event_data
285 { version_directive yaml_version_directive_t* }
286 { tag_directives tag_directives_document_start_event_data }
290 ! /** The document end parameters (for @c YAML_DOCUMENT_END_EVENT). */
291 STRUCT: document_end_event_data
295 ! /** The alias parameters (for @c YAML_ALIAS_EVENT). */
296 STRUCT: alias_event_data
300 ! /** The scalar parameters (for @c YAML_SCALAR_EVENT). */
301 STRUCT: scalar_event_data
306 { plain_implicit int }
307 { quoted_implicit int }
308 { style yaml_scalar_style_t }
311 ! /** The sequence parameters (for @c YAML_SEQUENCE_START_EVENT). */
312 STRUCT: sequence_start_event_data
316 { style yaml_sequence_style_t }
319 ! /** The mapping parameters (for @c YAML_MAPPING_START_EVENT). */
320 STRUCT: mapping_start_event_data
324 { style yaml_mapping_style_t }
327 UNION-STRUCT: event_data
328 { stream_start stream_start_event_data }
329 { document_start document_start_event_data }
330 { document_end document_end_event_data }
331 { alias alias_event_data }
332 { scalar scalar_event_data }
333 { sequence_start sequence_start_event_data }
334 { mapping_start mapping_start_event_data }
339 { type yaml_event_type_t }
343 { start_mark yaml_mark_t }
344 { end_mark yaml_mark_t }
348 ! * Create the STREAM-START event.
350 ! * @param[out] event An empty event object.
351 ! * @param[in] encoding The stream encoding.
353 ! * @returns @c 1 if the function succeeded, @c 0 on error.
357 yaml_stream_start_event_initialize ( yaml_event_t *event,
358 yaml_encoding_t encoding )
361 ! * Create the STREAM-END event.
363 ! * @param[out] event An empty event object.
365 ! * @returns @c 1 if the function succeeded, @c 0 on error.
369 yaml_stream_end_event_initialize ( yaml_event_t *event )
372 ! * Create the DOCUMENT-START event.
374 ! * The @a implicit argument is considered as a stylistic parameter and may be
375 ! * ignored by the emitter.
377 ! * @param[out] event An empty event object.
378 ! * @param[in] version_directive The %YAML directive value or
380 ! * @param[in] tag_directives_start The beginning of the %TAG
382 ! * @param[in] tag_directives_end The end of the %TAG directives
384 ! * @param[in] implicit If the document start indicator is
387 ! * @returns @c 1 if the function succeeded, @c 0 on error.
391 yaml_document_start_event_initialize ( yaml_event_t *event,
392 yaml_version_directive_t *version_directive,
393 yaml_tag_directive_t *tag_directives_start,
394 yaml_tag_directive_t *tag_directives_end,
398 ! * Create the DOCUMENT-END event.
400 ! * The @a implicit argument is considered as a stylistic parameter and may be
401 ! * ignored by the emitter.
403 ! * @param[out] event An empty event object.
404 ! * @param[in] implicit If the document end indicator is implicit.
406 ! * @returns @c 1 if the function succeeded, @c 0 on error.
410 yaml_document_end_event_initialize ( yaml_event_t *event, bool implicit )
413 ! * Create an ALIAS event.
415 ! * @param[out] event An empty event object.
416 ! * @param[in] anchor The anchor value.
418 ! * @returns @c 1 if the function succeeded, @c 0 on error.
422 yaml_alias_event_initialize ( yaml_event_t *event, c-string anchor )
425 ! * Create a SCALAR event.
427 ! * The @a style argument may be ignored by the emitter.
429 ! * Either the @a tag attribute or one of the @a plain_implicit and
430 ! * @a quoted_implicit flags must be set.
432 ! * @param[out] event An empty event object.
433 ! * @param[in] anchor The scalar anchor or @c NULL.
434 ! * @param[in] tag The scalar tag or @c NULL.
435 ! * @param[in] value The scalar value.
436 ! * @param[in] length The length of the scalar value.
437 ! * @param[in] plain_implicit If the tag may be omitted for the plain
439 ! * @param[in] quoted_implicit If the tag may be omitted for any
441 ! * @param[in] style The scalar style.
443 ! * @returns @c 1 if the function succeeded, @c 0 on error.
447 yaml_scalar_event_initialize ( yaml_event_t *event,
448 c-string anchor, c-string tag,
449 c-string value, int length,
450 bool plain_implicit, bool quoted_implicit,
451 yaml_scalar_style_t style )
454 ! * Create a SEQUENCE-START event.
456 ! * The @a style argument may be ignored by the emitter.
458 ! * Either the @a tag attribute or the @a implicit flag must be set.
460 ! * @param[out] event An empty event object.
461 ! * @param[in] anchor The sequence anchor or @c NULL.
462 ! * @param[in] tag The sequence tag or @c NULL.
463 ! * @param[in] implicit If the tag may be omitted.
464 ! * @param[in] style The sequence style.
466 ! * @returns @c 1 if the function succeeded, @c 0 on error.
470 yaml_sequence_start_event_initialize ( yaml_event_t *event,
471 c-string anchor, c-string tag, bool implicit,
472 yaml_sequence_style_t style )
475 ! * Create a SEQUENCE-END event.
477 ! * @param[out] event An empty event object.
479 ! * @returns @c 1 if the function succeeded, @c 0 on error.
483 yaml_sequence_end_event_initialize ( yaml_event_t *event )
486 ! * Create a MAPPING-START event.
488 ! * The @a style argument may be ignored by the emitter.
490 ! * Either the @a tag attribute or the @a implicit flag must be set.
492 ! * @param[out] event An empty event object.
493 ! * @param[in] anchor The mapping anchor or @c NULL.
494 ! * @param[in] tag The mapping tag or @c NULL.
495 ! * @param[in] implicit If the tag may be omitted.
496 ! * @param[in] style The mapping style.
498 ! * @returns @c 1 if the function succeeded, @c 0 on error.
502 yaml_mapping_start_event_initialize ( yaml_event_t *event,
503 c-string anchor, c-string tag, bool implicit,
504 yaml_mapping_style_t style )
507 ! * Create a MAPPING-END event.
509 ! * @param[out] event An empty event object.
511 ! * @returns @c 1 if the function succeeded, @c 0 on error.
515 yaml_mapping_end_event_initialize ( yaml_event_t *event )
518 ! * Free any memory allocated for an event object.
520 ! * @param[in,out] event An event object.
524 yaml_event_delete ( yaml_event_t *event )
525 DESTRUCTOR: yaml_event_delete
530 ! * @defgroup nodes Nodes
534 ! /** The tag @c !!null with the only possible value: @c null. */
535 CONSTANT: YAML_NULL_TAG "tag:yaml.org,2002:null"
536 ! /** The tag @c !!bool with the values: @c true and @c falce. */
537 CONSTANT: YAML_BOOL_TAG "tag:yaml.org,2002:bool"
538 ! /** The tag @c !!str for string values. */
539 CONSTANT: YAML_STR_TAG "tag:yaml.org,2002:str"
540 ! /** The tag @c !!int for integer values. */
541 CONSTANT: YAML_INT_TAG "tag:yaml.org,2002:int"
542 ! /** The tag @c !!float for float values. */
543 CONSTANT: YAML_FLOAT_TAG "tag:yaml.org,2002:float"
544 ! /** The tag @c !!timestamp for date and time values. */
545 CONSTANT: YAML_TIMESTAMP_TAG "tag:yaml.org,2002:timestamp"
547 ! /** The tag @c !!seq is used to denote sequences. */
548 CONSTANT: YAML_SEQ_TAG "tag:yaml.org,2002:seq"
549 ! /** The tag @c !!map is used to denote mapping. */
550 CONSTANT: YAML_MAP_TAG "tag:yaml.org,2002:map"
552 ! /** The default scalar tag is @c !!str. */
553 CONSTANT: YAML_DEFAULT_SCALAR_TAG $ YAML_STR_TAG
554 ! /** The default sequence tag is @c !!seq. */
555 CONSTANT: YAML_DEFAULT_SEQUENCE_TAG $ YAML_SEQ_TAG
556 ! /** The default mapping tag is @c !!map. */
557 CONSTANT: YAML_DEFAULT_MAPPING_TAG $ YAML_MAP_TAG
560 ENUM: yaml_node_type_t
568 ! /** The forward definition of a document node structure. */
569 ! typedef struct yaml_node_s yaml_node_t;
571 ! /** An element of a sequence node. */
572 TYPEDEF: int yaml_node_item_t
574 ! /** An element of a mapping node. */
575 STRUCT: yaml_node_pair_t
580 ! /** The node structure. */
581 ! /** The scalar parameters (for @c YAML_SCALAR_NODE). */
582 STRUCT: scalar_node_data
585 { style yaml_scalar_style_t }
588 ! /** The sequence parameters (for @c YAML_SEQUENCE_NODE). */
589 ! /** The stack of sequence items. */
590 STRUCT: sequence_node_data_items
591 { start yaml_node_item_t* }
592 { end yaml_node_item_t* }
593 { top yaml_node_item_t* }
595 STRUCT: sequence_node_data
596 { items sequence_node_data_items }
597 { style yaml_sequence_style_t }
600 ! /** The mapping parameters (for @c YAML_MAPPING_NODE). */
601 ! /** The stack of mapping pairs (key, value). */
602 STRUCT: mapping_node_data_pairs
603 { start yaml_node_pair_t* }
604 { end yaml_node_pair_t* }
605 { top yaml_node_pair_t* }
607 STRUCT: mapping_node_data
608 { pairs mapping_node_data_pairs }
609 { style yaml_mapping_style_t }
611 UNION-STRUCT: node_data
612 { scalar scalar_node_data }
613 { sequence sequence_node_data }
614 { mapping mapping_node_data }
619 { type yaml_node_type_t }
625 { start_mark yaml_mark_t }
626 { end_mark yaml_mark_t }
630 ! /** The document structure. */
631 ! /** The document nodes. */
632 STRUCT: yaml_document_nodes
633 { start yaml_node_t* }
638 ! /** The list of tag directives. */
639 STRUCT: yaml_document_tag_directives
640 { start yaml_tag_directive_t* }
641 { end yaml_tag_directive_t* }
644 STRUCT: yaml_document_t
646 { nodes yaml_document_nodes }
648 { version_directive yaml_version_directive_t* }
650 { tag_directives yaml_document_tag_directives }
652 { start_implicit int }
655 { start_mark yaml_mark_t }
656 { end_mark yaml_mark_t }
661 ! * Create a YAML document.
663 ! * @param[out] document An empty document object.
664 ! * @param[in] version_directive The %YAML directive value or
666 ! * @param[in] tag_directives_start The beginning of the %TAG
668 ! * @param[in] tag_directives_end The end of the %TAG directives
670 ! * @param[in] start_implicit If the document start indicator is
672 ! * @param[in] end_implicit If the document end indicator is
675 ! * @returns @c 1 if the function succeeded, @c 0 on error.
679 yaml_document_initialize ( yaml_document_t *document,
680 yaml_version_directive_t *version_directive,
681 yaml_tag_directive_t *tag_directives_start,
682 yaml_tag_directive_t *tag_directives_end,
683 bool start_implicit, bool end_implicit )
686 ! * Delete a YAML document and all its nodes.
688 ! * @param[in,out] document A document object.
692 yaml_document_delete ( yaml_document_t *document )
693 DESTRUCTOR: yaml_document_delete
696 ! * Get a node of a YAML document.
698 ! * The pointer returned by this function is valid until any of the functions
699 ! * modifying the documents are called.
701 ! * @param[in] document A document object.
702 ! * @param[in] index The node id.
704 ! * @returns the node objct or @c NULL if @c node_id is out of range.
707 FUNCTION: yaml_node_t*
708 yaml_document_get_node ( yaml_document_t *document, int index )
711 ! * Get the root of a YAML document node.
713 ! * The root object is the first object added to the document.
715 ! * The pointer returned by this function is valid until any of the functions
716 ! * modifying the documents are called.
718 ! * An empty document produced by the parser signifies the end of a YAML
721 ! * @param[in] document A document object.
723 ! * @returns the node object or @c NULL if the document is empty.
726 FUNCTION: yaml_node_t*
727 yaml_document_get_root_node ( yaml_document_t *document )
730 ! * Create a SCALAR node and attach it to the document.
732 ! * The @a style argument may be ignored by the emitter.
734 ! * @param[in,out] document A document object.
735 ! * @param[in] tag The scalar tag.
736 ! * @param[in] value The scalar value.
737 ! * @param[in] length The length of the scalar value.
738 ! * @param[in] style The scalar style.
740 ! * @returns the node id or @c 0 on error.
744 yaml_document_add_scalar ( yaml_document_t *document,
745 c-string tag, c-string value, int length,
746 yaml_scalar_style_t style )
749 ! * Create a SEQUENCE node and attach it to the document.
751 ! * The @a style argument may be ignored by the emitter.
753 ! * @param[in,out] document A document object.
754 ! * @param[in] tag The sequence tag.
755 ! * @param[in] style The sequence style.
757 ! * @returns the node id or @c 0 on error.
761 yaml_document_add_sequence ( yaml_document_t *document,
762 c-string tag, yaml_sequence_style_t style )
765 ! * Create a MAPPING node and attach it to the document.
767 ! * The @a style argument may be ignored by the emitter.
769 ! * @param[in,out] document A document object.
770 ! * @param[in] tag The sequence tag.
771 ! * @param[in] style The sequence style.
773 ! * @returns the node id or @c 0 on error.
777 yaml_document_add_mapping ( yaml_document_t *document,
778 c-string tag, yaml_mapping_style_t style )
781 ! * Add an item to a SEQUENCE node.
783 ! * @param[in,out] document A document object.
784 ! * @param[in] sequence The sequence node id.
785 ! * @param[in] item The item node id.
787 ! * @returns @c 1 if the function succeeded, @c 0 on error.
791 yaml_document_append_sequence_item ( yaml_document_t *document,
792 int sequence, int item )
795 ! * Add a pair of a key and a value to a MAPPING node.
797 ! * @param[in,out] document A document object.
798 ! * @param[in] mapping The mapping node id.
799 ! * @param[in] key The key node id.
800 ! * @param[in] value The value node id.
802 ! * @returns @c 1 if the function succeeded, @c 0 on error.
806 yaml_document_append_mapping_pair ( yaml_document_t *document,
807 int mapping, int key, int value )
812 ! * @defgroup parser Parser Definitions
817 ! * The prototype of a read handler.
819 ! * The read handler is called when the parser needs to read more bytes from the
820 ! * source. The handler should write not more than @a size bytes to the @a
821 ! * buffer. The number of written bytes should be set to the @a length variable.
823 ! * @param[in,out] data A pointer to an application data specified by
824 ! * yaml_parser_set_input().
825 ! * @param[out] buffer The buffer to write the data from the source.
826 ! * @param[in] size The size of the buffer.
827 ! * @param[out] size_read The actual number of bytes read from the source.
829 ! * @returns On success, the handler should return @c 1. If the handler failed,
830 ! * the returned value should be @c 0. On EOF, the handler should set the
831 ! * @a size_read to @c 0 and return @c 1.
834 CALLBACK: bool yaml_read_handler_t ( void *data, uchar *buffer, size_t size,
838 ! * This structure holds information about a potential simple key.
841 STRUCT: yaml_simple_key_t
846 { token_number size_t }
852 ! * The states of the parser.
854 ENUM: yaml_parser_state_t
855 YAML_PARSE_STREAM_START_STATE
856 YAML_PARSE_IMPLICIT_DOCUMENT_START_STATE
857 YAML_PARSE_DOCUMENT_START_STATE
858 YAML_PARSE_DOCUMENT_CONTENT_STATE
859 YAML_PARSE_DOCUMENT_END_STATE
860 YAML_PARSE_BLOCK_NODE_STATE
861 YAML_PARSE_BLOCK_NODE_OR_INDENTLESS_SEQUENCE_STATE
862 YAML_PARSE_FLOW_NODE_STATE
863 YAML_PARSE_BLOCK_SEQUENCE_FIRST_ENTRY_STATE
864 YAML_PARSE_BLOCK_SEQUENCE_ENTRY_STATE
865 YAML_PARSE_INDENTLESS_SEQUENCE_ENTRY_STATE
866 YAML_PARSE_BLOCK_MAPPING_FIRST_KEY_STATE
867 YAML_PARSE_BLOCK_MAPPING_KEY_STATE
868 YAML_PARSE_BLOCK_MAPPING_VALUE_STATE
869 YAML_PARSE_FLOW_SEQUENCE_FIRST_ENTRY_STATE
870 YAML_PARSE_FLOW_SEQUENCE_ENTRY_STATE
871 YAML_PARSE_FLOW_SEQUENCE_ENTRY_MAPPING_KEY_STATE
872 YAML_PARSE_FLOW_SEQUENCE_ENTRY_MAPPING_VALUE_STATE
873 YAML_PARSE_FLOW_SEQUENCE_ENTRY_MAPPING_END_STATE
874 YAML_PARSE_FLOW_MAPPING_FIRST_KEY_STATE
875 YAML_PARSE_FLOW_MAPPING_KEY_STATE
876 YAML_PARSE_FLOW_MAPPING_VALUE_STATE
877 YAML_PARSE_FLOW_MAPPING_EMPTY_VALUE_STATE
882 ! * This structure holds aliases data.
885 STRUCT: yaml_alias_data_t
892 ! * The parser structure.
894 ! * All members are internal. Manage the structure using the @c yaml_parser_
895 ! * family of functions.
898 ! /** Standard (string or file) input data. */
899 ! /** String input data. */
900 STRUCT: string_yaml_parser_input
905 UNION-STRUCT: yaml_parser_input
906 { string string_yaml_parser_input }
910 ! /** The working buffer. */
911 STRUCT: yaml_parser_buffer
912 { start yaml_char_t* }
914 { pointer yaml_char_t* }
915 { last yaml_char_t* }
918 ! /** The raw buffer. */
919 STRUCT: yaml_parser_raw_buffer
926 ! /** The tokens queue. */
927 STRUCT: yaml_parser_tokens
928 { start yaml_token_t* }
929 { end yaml_token_t* }
930 { head yaml_token_t* }
931 { tail yaml_token_t* }
934 ! /** The indentation levels stack. */
935 STRUCT: yaml_parser_indents
941 ! /** The stack of simple keys. */
942 STRUCT: yaml_parser_simple_keys
943 { start yaml_simple_key_t* }
944 { end yaml_simple_key_t* }
945 { top yaml_simple_key_t* }
948 ! /** The parser states stack. */
949 STRUCT: yaml_parser_states
950 { start yaml_parser_state_t* }
951 { end yaml_parser_state_t* }
952 { top yaml_parser_state_t* }
955 ! /** The stack of marks. */
956 STRUCT: yaml_parser_marks
957 { start yaml_mark_t* }
962 ! /** The list of TAG directives. */
963 STRUCT: yaml_parser_tag_directives
964 { start yaml_tag_directive_t* }
965 { end yaml_tag_directive_t* }
966 { top yaml_tag_directive_t* }
969 ! /** The alias data. */
970 STRUCT: yaml_parser_aliases
971 { start yaml_alias_data_t* }
972 { end yaml_alias_data_t* }
973 { top yaml_alias_data_t* }
975 STRUCT: yaml_parser_t
977 { error yaml_error_type_t }
979 { problem_offset size_t }
980 { problem_value int }
981 { problem_mark yaml_mark_t }
983 { context_mark yaml_mark_t }
985 { read_handler yaml_read_handler_t* }
987 { read_handler_data void* }
989 { input yaml_parser_input }
993 { buffer yaml_parser_buffer }
997 { raw_buffer yaml_parser_raw_buffer }
999 { encoding yaml_encoding_t }
1003 { mark yaml_mark_t }
1005 { stream_start_produced int }
1007 { stream_end_produced int }
1011 { tokens yaml_parser_tokens }
1013 { tokens_parsed size_t }
1015 { token_available int }
1017 { indents yaml_parser_indents }
1021 { simple_key_allowed int }
1023 { simple_keys yaml_parser_simple_keys }
1025 { states yaml_parser_states }
1027 { state yaml_parser_state_t }
1029 { marks yaml_parser_marks }
1031 { tag_directives yaml_parser_tag_directives }
1033 { aliases yaml_parser_aliases }
1035 { document yaml_document_t* }
1039 ! * Initialize a parser.
1041 ! * This function creates a new parser object. An application is responsible
1042 ! * for destroying the object using the yaml_parser_delete() function.
1044 ! * @param[out] parser An empty parser object.
1046 ! * @returns @c 1 if the function succeeded, @c 0 on error.
1050 yaml_parser_initialize ( yaml_parser_t *parser )
1053 ! * Destroy a parser.
1055 ! * @param[in,out] parser A parser object.
1059 yaml_parser_delete ( yaml_parser_t *parser )
1060 DESTRUCTOR: yaml_parser_delete
1063 ! * Set a string input.
1065 ! * Note that the @a input pointer must be valid while the @a parser object
1066 ! * exists. The application is responsible for destroing @a input after
1067 ! * destroying the @a parser.
1069 ! * @param[in,out] parser A parser object.
1070 ! * @param[in] input A source data.
1071 ! * @param[in] size The length of the source data in bytes.
1075 yaml_parser_set_input_string ( yaml_parser_t *parser,
1076 uchar *input, size_t size )
1079 ! * Set a file input.
1081 ! * @a file should be a file object open for reading. The application is
1082 ! * responsible for closing the @a file.
1084 ! * @param[in,out] parser A parser object.
1085 ! * @param[in] file An open file.
1089 yaml_parser_set_input_file ( yaml_parser_t *parser, FILE *file )
1092 ! * Set a generic input handler.
1094 ! * @param[in,out] parser A parser object.
1095 ! * @param[in] handler A read handler.
1096 ! * @param[in] data Any application data for passing to the read
1101 yaml_parser_set_input ( yaml_parser_t *parser,
1102 yaml_read_handler_t *handler, void *data )
1105 ! * Set the source encoding.
1107 ! * @param[in,out] parser A parser object.
1108 ! * @param[in] encoding The source encoding.
1112 yaml_parser_set_encoding ( yaml_parser_t *parser, yaml_encoding_t encoding )
1115 ! * Scan the input stream and produce the next token.
1117 ! * Call the function subsequently to produce a sequence of tokens corresponding
1118 ! * to the input stream. The initial token has the type
1119 ! * @c YAML_STREAM_START_TOKEN while the ending token has the type
1120 ! * @c YAML_STREAM_END_TOKEN.
1122 ! * An application is responsible for freeing any buffers associated with the
1123 ! * produced token object using the @c yaml_token_delete function.
1125 ! * An application must not alternate the calls of yaml_parser_scan() with the
1126 ! * calls of yaml_parser_parse() or yaml_parser_load(). Doing this will break
1129 ! * @param[in,out] parser A parser object.
1130 ! * @param[out] token An empty token object.
1132 ! * @returns @c 1 if the function succeeded, @c 0 on error.
1136 yaml_parser_scan ( yaml_parser_t *parser, yaml_token_t *token )
1139 ! * Parse the input stream and produce the next parsing event.
1141 ! * Call the function subsequently to produce a sequence of events corresponding
1142 ! * to the input stream. The initial event has the type
1143 ! * @c YAML_STREAM_START_EVENT while the ending event has the type
1144 ! * @c YAML_STREAM_END_EVENT.
1146 ! * An application is responsible for freeing any buffers associated with the
1147 ! * produced event object using the yaml_event_delete() function.
1149 ! * An application must not alternate the calls of yaml_parser_parse() with the
1150 ! * calls of yaml_parser_scan() or yaml_parser_load(). Doing this will break the
1153 ! * @param[in,out] parser A parser object.
1154 ! * @param[out] event An empty event object.
1156 ! * @returns @c 1 if the function succeeded, @c 0 on error.
1160 yaml_parser_parse ( yaml_parser_t *parser, yaml_event_t *event )
1163 ! * Parse the input stream and produce the next YAML document.
1165 ! * Call this function subsequently to produce a sequence of documents
1166 ! * constituting the input stream.
1168 ! * If the produced document has no root node, it means that the document
1169 ! * end has been reached.
1171 ! * An application is responsible for freeing any data associated with the
1172 ! * produced document object using the yaml_document_delete() function.
1174 ! * An application must not alternate the calls of yaml_parser_load() with the
1175 ! * calls of yaml_parser_scan() or yaml_parser_parse(). Doing this will break
1178 ! * @param[in,out] parser A parser object.
1179 ! * @param[out] document An empty document object.
1181 ! * @return @c 1 if the function succeeded, @c 0 on error.
1185 yaml_parser_load ( yaml_parser_t *parser, yaml_document_t *document )
1190 ! * @defgroup emitter Emitter Definitions
1195 ! * The prototype of a write handler.
1197 ! * The write handler is called when the emitter needs to flush the accumulated
1198 ! * characters to the output. The handler should write @a size bytes of the
1199 ! * @a buffer to the output.
1201 ! * @param[in,out] data A pointer to an application data specified by
1202 ! * yaml_emitter_set_output().
1203 ! * @param[in] buffer The buffer with bytes to be written.
1204 ! * @param[in] size The size of the buffer.
1206 ! * @returns On success, the handler should return @c 1. If the handler failed,
1207 ! * the returned value should be @c 0.
1210 CALLBACK: bool yaml_write_handler_t ( void *data, uchar *buffer, size_t size )
1212 ! /** The emitter states. */
1213 ENUM: yaml_emitter_state_t
1214 YAML_EMIT_STREAM_START_STATE
1215 YAML_EMIT_FIRST_DOCUMENT_START_STATE
1216 YAML_EMIT_DOCUMENT_START_STATE
1217 YAML_EMIT_DOCUMENT_CONTENT_STATE
1218 YAML_EMIT_DOCUMENT_END_STATE
1219 YAML_EMIT_FLOW_SEQUENCE_FIRST_ITEM_STATE
1220 YAML_EMIT_FLOW_SEQUENCE_ITEM_STATE
1221 YAML_EMIT_FLOW_MAPPING_FIRST_KEY_STATE
1222 YAML_EMIT_FLOW_MAPPING_KEY_STATE
1223 YAML_EMIT_FLOW_MAPPING_SIMPLE_VALUE_STATE
1224 YAML_EMIT_FLOW_MAPPING_VALUE_STATE
1225 YAML_EMIT_BLOCK_SEQUENCE_FIRST_ITEM_STATE
1226 YAML_EMIT_BLOCK_SEQUENCE_ITEM_STATE
1227 YAML_EMIT_BLOCK_MAPPING_FIRST_KEY_STATE
1228 YAML_EMIT_BLOCK_MAPPING_KEY_STATE
1229 YAML_EMIT_BLOCK_MAPPING_SIMPLE_VALUE_STATE
1230 YAML_EMIT_BLOCK_MAPPING_VALUE_STATE
1235 ! * The emitter structure.
1237 ! * All members are internal. Manage the structure using the @c yaml_emitter_
1238 ! * family of functions.
1241 ! /** Standard (string or file) output data. */
1242 ! /** String output data. */
1243 STRUCT: yaml_emitter_output_string
1246 { size_written size_t* }
1249 UNION-STRUCT: yaml_emitter_output
1250 { string yaml_emitter_output_string }
1255 ! /** The working buffer. */
1256 STRUCT: yaml_emitter_buffer
1257 { start yaml_char_t* }
1258 { end yaml_char_t* }
1259 { pointer yaml_char_t* }
1260 { last yaml_char_t* }
1263 ! /** The raw buffer. */
1264 STRUCT: yaml_emitter_raw_buffer
1271 ! /** The stack of states. */
1272 STRUCT: yaml_emitter_states
1273 { start yaml_emitter_state_t* }
1274 { end yaml_emitter_state_t* }
1275 { top yaml_emitter_state_t* }
1278 ! /** The event queue. */
1279 STRUCT: yaml_emitter_events
1280 { start yaml_event_t* }
1281 { end yaml_event_t* }
1282 { head yaml_event_t* }
1283 { tail yaml_event_t* }
1286 ! /** The stack of indentation levels. */
1287 STRUCT: yaml_emitter_indents
1293 ! /** The list of tag directives. */
1294 STRUCT: yaml_emitter_tag_directives
1295 { start yaml_tag_directive_t* }
1296 { end yaml_tag_directive_t* }
1297 { top yaml_tag_directive_t* }
1300 ! /** Anchor analysis. */
1301 STRUCT: yaml_emitter_anchor_data
1303 { anchor_length size_t }
1307 ! /** Tag analysis. */
1308 STRUCT: yaml_emitter_tag_data
1310 { handle_length size_t }
1312 { suffix_length size_t }
1315 ! /** Scalar analysis. */
1316 STRUCT: yaml_emitter_scalar_data
1320 { flow_plain_allowed int }
1321 { block_plain_allowed int }
1322 { single_quoted_allowed int }
1323 { block_allowed int }
1324 { style yaml_scalar_style_t }
1327 ! /** The information associated with the document nodes. */
1328 STRUCT: yaml_emitter_anchors
1333 STRUCT: yaml_emitter_t
1335 { error yaml_error_type_t }
1336 { problem c-string }
1338 { write_handler yaml_write_handler_t* }
1340 { write_handler_data void* }
1342 { output yaml_emitter_output }
1344 { buffer yaml_emitter_buffer }
1346 { raw_buffer yaml_emitter_raw_buffer }
1348 { encoding yaml_encoding_t }
1354 { line_break yaml_break_t }
1356 { states yaml_emitter_states }
1357 { state yaml_emitter_state_t }
1359 { events yaml_emitter_events }
1361 { indents yaml_emitter_indents }
1363 { tag_directives yaml_emitter_tag_directives }
1369 { root_context int }
1370 { sequence_context int }
1371 { mapping_context int }
1372 { simple_key_context int }
1380 { anchor_data yaml_emitter_anchor_data }
1382 { tag_data yaml_emitter_tag_data }
1384 { scalar_data yaml_emitter_scalar_data }
1389 { anchors yaml_emitter_anchors* }
1391 { last_anchor_id int }
1393 { document yaml_document_t* }
1398 ! * Initialize an emitter.
1400 ! * This function creates a new emitter object. An application is responsible
1401 ! * for destroying the object using the yaml_emitter_delete() function.
1403 ! * @param[out] emitter An empty parser object.
1405 ! * @returns @c 1 if the function succeeded, @c 0 on error.
1409 yaml_emitter_initialize ( yaml_emitter_t *emitter )
1412 ! * Destroy an emitter.
1414 ! * @param[in,out] emitter An emitter object.
1418 yaml_emitter_delete ( yaml_emitter_t *emitter )
1419 DESTRUCTOR: yaml_emitter_delete
1422 ! * Set a string output.
1424 ! * The emitter will write the output characters to the @a output buffer of the
1425 ! * size @a size. The emitter will set @a size_written to the number of written
1426 ! * bytes. If the buffer is smaller than required, the emitter produces the
1427 ! * YAML_WRITE_ERROR error.
1429 ! * @param[in,out] emitter An emitter object.
1430 ! * @param[in] output An output buffer.
1431 ! * @param[in] size The buffer size.
1432 ! * @param[in] size_written The pointer to save the number of written
1437 yaml_emitter_set_output_string ( yaml_emitter_t *emitter,
1438 uchar *output, size_t size, size_t *size_written )
1441 ! * Set a file output.
1443 ! * @a file should be a file object open for writing. The application is
1444 ! * responsible for closing the @a file.
1446 ! * @param[in,out] emitter An emitter object.
1447 ! * @param[in] file An open file.
1451 yaml_emitter_set_output_file ( yaml_emitter_t *emitter, FILE *file )
1454 ! * Set a generic output handler.
1456 ! * @param[in,out] emitter An emitter object.
1457 ! * @param[in] handler A write handler.
1458 ! * @param[in] data Any application data for passing to the write
1463 yaml_emitter_set_output ( yaml_emitter_t *emitter,
1464 yaml_write_handler_t *handler, void *data )
1467 ! * Set the output encoding.
1469 ! * @param[in,out] emitter An emitter object.
1470 ! * @param[in] encoding The output encoding.
1474 yaml_emitter_set_encoding ( yaml_emitter_t *emitter, yaml_encoding_t encoding )
1477 ! * Set if the output should be in the "canonical" format as in the YAML
1480 ! * @param[in,out] emitter An emitter object.
1481 ! * @param[in] canonical If the output is canonical.
1485 yaml_emitter_set_canonical ( yaml_emitter_t *emitter, bool canonical )
1488 ! * Set the intendation increment.
1490 ! * @param[in,out] emitter An emitter object.
1491 ! * @param[in] indent The indentation increment (1 < . < 10).
1495 yaml_emitter_set_indent ( yaml_emitter_t *emitter, int indent )
1498 ! * Set the preferred line width. @c -1 means unlimited.
1500 ! * @param[in,out] emitter An emitter object.
1501 ! * @param[in] width The preferred line width.
1505 yaml_emitter_set_width ( yaml_emitter_t *emitter, int width )
1508 ! * Set if unescaped non-ASCII characters are allowed.
1510 ! * @param[in,out] emitter An emitter object.
1511 ! * @param[in] unicode If unescaped Unicode characters are allowed.
1515 yaml_emitter_set_unicode ( yaml_emitter_t *emitter, bool unicode )
1518 ! * Set the preferred line break.
1520 ! * @param[in,out] emitter An emitter object.
1521 ! * @param[in] line_break The preferred line break.
1525 yaml_emitter_set_break ( yaml_emitter_t *emitter, yaml_break_t line_break )
1530 ! * The event object may be generated using the yaml_parser_parse() function.
1531 ! * The emitter takes the responsibility for the event object and destroys its
1532 ! * content after it is emitted. The event object is destroyed even if the
1535 ! * @param[in,out] emitter An emitter object.
1536 ! * @param[in,out] event An event object.
1538 ! * @returns @c 1 if the function succeeded, @c 0 on error.
1542 yaml_emitter_emit ( yaml_emitter_t *emitter, yaml_event_t *event )
1545 ! * Start a YAML stream.
1547 ! * This function should be used before yaml_emitter_dump() is called.
1549 ! * @param[in,out] emitter An emitter object.
1551 ! * @returns @c 1 if the function succeeded, @c 0 on error.
1555 yaml_emitter_open ( yaml_emitter_t *emitter )
1558 ! * Finish a YAML stream.
1560 ! * This function should be used after yaml_emitter_dump() is called.
1562 ! * @param[in,out] emitter An emitter object.
1564 ! * @returns @c 1 if the function succeeded, @c 0 on error.
1568 yaml_emitter_close ( yaml_emitter_t *emitter )
1571 ! * Emit a YAML document.
1573 ! * The documen object may be generated using the yaml_parser_load() function
1574 ! * or the yaml_document_initialize() function. The emitter takes the
1575 ! * responsibility for the document object and destoys its content after
1576 ! * it is emitted. The document object is destroyedeven if the function fails.
1578 ! * @param[in,out] emitter An emitter object.
1579 ! * @param[in,out] document A document object.
1581 ! * @returns @c 1 if the function succeeded, @c 0 on error.
1585 yaml_emitter_dump ( yaml_emitter_t *emitter, yaml_document_t *document )
1588 ! * Flush the accumulated characters to the output.
1590 ! * @param[in,out] emitter An emitter object.
1592 ! * @returns @c 1 if the function succeeded, @c 0 on error.
1596 yaml_emitter_flush ( yaml_emitter_t *emitter )
1600 ! #ifdef __cplusplus
1604 ! #endif /* #ifndef YAML_H */