1 ! Copyright (C) 2013 Jon Harper.
2 ! See http://factorcode.org/license.txt for BSD license.
3 ! adapted from "yaml.h" libYAML 0.1.4
4 ! http://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 ;
10 ADD-FIRST-LIBRARY: libyaml cdecl { "yaml" "yaml-0" "libyaml-0-2" }
17 ! * @defgroup version Version Information
22 ! * Get the library version as a string.
24 ! * @returns The function returns the pointer to a static string of the form
25 ! * @c "X.Y.Z", where @c X is the major version number, @c Y is a minor version
26 ! * number, and @c Z is the patch version number.
29 yaml_get_version_string ( )
32 ! * Get the library version numbers.
34 ! * @param[out] major Major version number.
35 ! * @param[out] minor Minor version number.
36 ! * @param[out] patch Patch version number.
39 yaml_get_version ( int *major, int *minor, int *patch )
44 ! * @defgroup basic Basic Types
48 ! /** The character type (UTF-8 octet). */
49 ! libYAML returns it's data as null-terminated UTF-8 string.
50 ! It copies it's input and we can use null-terminated string
51 ! if we give a negative length. So we can use factor's c-string
52 ! for input and output.
53 TYPEDEF: uchar yaml_char_t
55 ! /** The version directive data. */
56 STRUCT: yaml_version_directive_t
61 ! /** The tag directive data. */
62 STRUCT: yaml_tag_directive_t
67 ! /** The stream encoding. */
75 ! /** Line break types. */
83 ! /** Many bad things could happen with the parser and emitter. */
84 ENUM: yaml_error_type_t
98 ! /** The pointer position. */
108 ! * @defgroup styles Node Styles
112 ! /** Scalar styles. */
113 ENUM: yaml_scalar_style_t
114 YAML_ANY_SCALAR_STYLE
116 YAML_PLAIN_SCALAR_STYLE
118 YAML_SINGLE_QUOTED_SCALAR_STYLE
119 YAML_DOUBLE_QUOTED_SCALAR_STYLE
121 YAML_LITERAL_SCALAR_STYLE
122 YAML_FOLDED_SCALAR_STYLE
125 ! /** Sequence styles. */
126 ENUM: yaml_sequence_style_t
127 YAML_ANY_SEQUENCE_STYLE
129 YAML_BLOCK_SEQUENCE_STYLE
130 YAML_FLOW_SEQUENCE_STYLE
133 ! /** Mapping styles. */
134 ENUM: yaml_mapping_style_t
135 YAML_ANY_MAPPING_STYLE
137 YAML_BLOCK_MAPPING_STYLE
138 YAML_FLOW_MAPPING_STYLE
144 ! * @defgroup tokens Tokens
148 ! /** Token types. */
149 ENUM: yaml_token_type_t
152 YAML_STREAM_START_TOKEN
153 YAML_STREAM_END_TOKEN
155 YAML_VERSION_DIRECTIVE_TOKEN
156 YAML_TAG_DIRECTIVE_TOKEN
157 YAML_DOCUMENT_START_TOKEN
158 YAML_DOCUMENT_END_TOKEN
160 YAML_BLOCK_SEQUENCE_START_TOKEN
161 YAML_BLOCK_MAPPING_START_TOKEN
164 YAML_FLOW_SEQUENCE_START_TOKEN
165 YAML_FLOW_SEQUENCE_END_TOKEN
166 YAML_FLOW_MAPPING_START_TOKEN
167 YAML_FLOW_MAPPING_END_TOKEN
169 YAML_BLOCK_ENTRY_TOKEN
170 YAML_FLOW_ENTRY_TOKEN
180 ! /** The token structure. */
181 ! /** The stream start (for @c YAML_STREAM_START_TOKEN). */
182 STRUCT: stream_start_token_data
183 { encoding yaml_encoding_t }
185 ! /** The alias (for @c YAML_ALIAS_TOKEN). */
186 STRUCT: alias_token_data
189 ! /** The anchor (for @c YAML_ANCHOR_TOKEN). */
190 STRUCT: anchor_token_data
194 ! /** The tag (for @c YAML_TAG_TOKEN). */
195 STRUCT: tag_token_data
200 ! /** The scalar value (for @c YAML_SCALAR_TOKEN). */
201 STRUCT: scalar_token_data
204 { style yaml_scalar_style_t }
207 ! /** The version directive (for @c YAML_VERSION_DIRECTIVE_TOKEN). */
208 STRUCT: version_directive_token_data
213 UNION-STRUCT: token_data
214 { stream_start stream_start_token_data }
215 { alias alias_token_data }
216 { anchor anchor_token_data }
217 { tag tag_token_data }
218 { scalar scalar_token_data }
219 { version_directive version_directive_token_data }
223 { type yaml_token_type_t }
227 { start_mark yaml_mark_t }
228 { end_mark yaml_mark_t }
232 ! * Free any memory allocated for a token object.
234 ! * @param[in,out] token A token object.
238 yaml_token_delete ( yaml_token_t *token )
239 DESTRUCTOR: yaml_token_delete
244 ! * @defgroup events Events
248 ! /** Event types. */
249 ENUM: yaml_event_type_t
252 YAML_STREAM_START_EVENT
253 YAML_STREAM_END_EVENT
255 YAML_DOCUMENT_START_EVENT
256 YAML_DOCUMENT_END_EVENT
261 YAML_SEQUENCE_START_EVENT
262 YAML_SEQUENCE_END_EVENT
264 YAML_MAPPING_START_EVENT
265 YAML_MAPPING_END_EVENT
268 ! /** The event structure. */
270 ! /** The event data. */
271 ! /** The stream parameters (for @c YAML_STREAM_START_EVENT). */
272 STRUCT: stream_start_event_data
273 { encoding yaml_encoding_t }
276 ! /** The document parameters (for @c YAML_DOCUMENT_START_EVENT). */
277 ! /** The list of tag directives. */
278 STRUCT: tag_directives_document_start_event_data
279 { start yaml_tag_directive_t* }
280 { end yaml_tag_directive_t* }
282 STRUCT: document_start_event_data
283 { version_directive yaml_version_directive_t* }
284 { tag_directives tag_directives_document_start_event_data }
288 ! /** The document end parameters (for @c YAML_DOCUMENT_END_EVENT). */
289 STRUCT: document_end_event_data
293 ! /** The alias parameters (for @c YAML_ALIAS_EVENT). */
294 STRUCT: alias_event_data
298 ! /** The scalar parameters (for @c YAML_SCALAR_EVENT). */
299 STRUCT: scalar_event_data
304 { plain_implicit int }
305 { quoted_implicit int }
306 { style yaml_scalar_style_t }
309 ! /** The sequence parameters (for @c YAML_SEQUENCE_START_EVENT). */
310 STRUCT: sequence_start_event_data
314 { style yaml_sequence_style_t }
317 ! /** The mapping parameters (for @c YAML_MAPPING_START_EVENT). */
318 STRUCT: mapping_start_event_data
322 { style yaml_mapping_style_t }
325 UNION-STRUCT: event_data
326 { stream_start stream_start_event_data }
327 { document_start document_start_event_data }
328 { document_end document_end_event_data }
329 { alias alias_event_data }
330 { scalar scalar_event_data }
331 { sequence_start sequence_start_event_data }
332 { mapping_start mapping_start_event_data }
337 { type yaml_event_type_t }
341 { start_mark yaml_mark_t }
342 { end_mark yaml_mark_t }
346 ! * Create the STREAM-START event.
348 ! * @param[out] event An empty event object.
349 ! * @param[in] encoding The stream encoding.
351 ! * @returns @c 1 if the function succeeded, @c 0 on error.
355 yaml_stream_start_event_initialize ( yaml_event_t *event,
356 yaml_encoding_t encoding )
359 ! * Create the STREAM-END event.
361 ! * @param[out] event An empty event object.
363 ! * @returns @c 1 if the function succeeded, @c 0 on error.
367 yaml_stream_end_event_initialize ( yaml_event_t *event )
370 ! * Create the DOCUMENT-START event.
372 ! * The @a implicit argument is considered as a stylistic parameter and may be
373 ! * ignored by the emitter.
375 ! * @param[out] event An empty event object.
376 ! * @param[in] version_directive The %YAML directive value or
378 ! * @param[in] tag_directives_start The beginning of the %TAG
380 ! * @param[in] tag_directives_end The end of the %TAG directives
382 ! * @param[in] implicit If the document start indicator is
385 ! * @returns @c 1 if the function succeeded, @c 0 on error.
389 yaml_document_start_event_initialize ( yaml_event_t *event,
390 yaml_version_directive_t *version_directive,
391 yaml_tag_directive_t *tag_directives_start,
392 yaml_tag_directive_t *tag_directives_end,
396 ! * Create the DOCUMENT-END event.
398 ! * The @a implicit argument is considered as a stylistic parameter and may be
399 ! * ignored by the emitter.
401 ! * @param[out] event An empty event object.
402 ! * @param[in] implicit If the document end indicator is implicit.
404 ! * @returns @c 1 if the function succeeded, @c 0 on error.
408 yaml_document_end_event_initialize ( yaml_event_t *event, bool implicit )
411 ! * Create an ALIAS event.
413 ! * @param[out] event An empty event object.
414 ! * @param[in] anchor The anchor value.
416 ! * @returns @c 1 if the function succeeded, @c 0 on error.
420 yaml_alias_event_initialize ( yaml_event_t *event, c-string anchor )
423 ! * Create a SCALAR event.
425 ! * The @a style argument may be ignored by the emitter.
427 ! * Either the @a tag attribute or one of the @a plain_implicit and
428 ! * @a quoted_implicit flags must be set.
430 ! * @param[out] event An empty event object.
431 ! * @param[in] anchor The scalar anchor or @c NULL.
432 ! * @param[in] tag The scalar tag or @c NULL.
433 ! * @param[in] value The scalar value.
434 ! * @param[in] length The length of the scalar value.
435 ! * @param[in] plain_implicit If the tag may be omitted for the plain
437 ! * @param[in] quoted_implicit If the tag may be omitted for any
439 ! * @param[in] style The scalar style.
441 ! * @returns @c 1 if the function succeeded, @c 0 on error.
445 yaml_scalar_event_initialize ( yaml_event_t *event,
446 c-string anchor, c-string tag,
447 c-string value, int length,
448 bool plain_implicit, bool quoted_implicit,
449 yaml_scalar_style_t style )
452 ! * Create a SEQUENCE-START event.
454 ! * The @a style argument may be ignored by the emitter.
456 ! * Either the @a tag attribute or the @a implicit flag must be set.
458 ! * @param[out] event An empty event object.
459 ! * @param[in] anchor The sequence anchor or @c NULL.
460 ! * @param[in] tag The sequence tag or @c NULL.
461 ! * @param[in] implicit If the tag may be omitted.
462 ! * @param[in] style The sequence style.
464 ! * @returns @c 1 if the function succeeded, @c 0 on error.
468 yaml_sequence_start_event_initialize ( yaml_event_t *event,
469 c-string anchor, c-string tag, bool implicit,
470 yaml_sequence_style_t style )
473 ! * Create a SEQUENCE-END event.
475 ! * @param[out] event An empty event object.
477 ! * @returns @c 1 if the function succeeded, @c 0 on error.
481 yaml_sequence_end_event_initialize ( yaml_event_t *event )
484 ! * Create a MAPPING-START event.
486 ! * The @a style argument may be ignored by the emitter.
488 ! * Either the @a tag attribute or the @a implicit flag must be set.
490 ! * @param[out] event An empty event object.
491 ! * @param[in] anchor The mapping anchor or @c NULL.
492 ! * @param[in] tag The mapping tag or @c NULL.
493 ! * @param[in] implicit If the tag may be omitted.
494 ! * @param[in] style The mapping style.
496 ! * @returns @c 1 if the function succeeded, @c 0 on error.
500 yaml_mapping_start_event_initialize ( yaml_event_t *event,
501 c-string anchor, c-string tag, bool implicit,
502 yaml_mapping_style_t style )
505 ! * Create a MAPPING-END event.
507 ! * @param[out] event An empty event object.
509 ! * @returns @c 1 if the function succeeded, @c 0 on error.
513 yaml_mapping_end_event_initialize ( yaml_event_t *event )
516 ! * Free any memory allocated for an event object.
518 ! * @param[in,out] event An event object.
522 yaml_event_delete ( yaml_event_t *event )
523 DESTRUCTOR: yaml_event_delete
528 ! * @defgroup nodes Nodes
532 ! /** The tag @c !!null with the only possible value: @c null. */
533 CONSTANT: YAML_NULL_TAG "tag:yaml.org,2002:null"
534 ! /** The tag @c !!bool with the values: @c true and @c falce. */
535 CONSTANT: YAML_BOOL_TAG "tag:yaml.org,2002:bool"
536 ! /** The tag @c !!str for string values. */
537 CONSTANT: YAML_STR_TAG "tag:yaml.org,2002:str"
538 ! /** The tag @c !!int for integer values. */
539 CONSTANT: YAML_INT_TAG "tag:yaml.org,2002:int"
540 ! /** The tag @c !!float for float values. */
541 CONSTANT: YAML_FLOAT_TAG "tag:yaml.org,2002:float"
542 ! /** The tag @c !!timestamp for date and time values. */
543 CONSTANT: YAML_TIMESTAMP_TAG "tag:yaml.org,2002:timestamp"
545 ! /** The tag @c !!seq is used to denote sequences. */
546 CONSTANT: YAML_SEQ_TAG "tag:yaml.org,2002:seq"
547 ! /** The tag @c !!map is used to denote mapping. */
548 CONSTANT: YAML_MAP_TAG "tag:yaml.org,2002:map"
550 ! /** The default scalar tag is @c !!str. */
551 CONSTANT: YAML_DEFAULT_SCALAR_TAG $ YAML_STR_TAG
552 ! /** The default sequence tag is @c !!seq. */
553 CONSTANT: YAML_DEFAULT_SEQUENCE_TAG $ YAML_SEQ_TAG
554 ! /** The default mapping tag is @c !!map. */
555 CONSTANT: YAML_DEFAULT_MAPPING_TAG $ YAML_MAP_TAG
558 ENUM: yaml_node_type_t
566 ! /** The forward definition of a document node structure. */
567 ! typedef struct yaml_node_s yaml_node_t;
569 ! /** An element of a sequence node. */
570 TYPEDEF: int yaml_node_item_t
572 ! /** An element of a mapping node. */
573 STRUCT: yaml_node_pair_t
578 ! /** The node structure. */
579 ! /** The scalar parameters (for @c YAML_SCALAR_NODE). */
580 STRUCT: scalar_node_data
583 { style yaml_scalar_style_t }
586 ! /** The sequence parameters (for @c YAML_SEQUENCE_NODE). */
587 ! /** The stack of sequence items. */
588 STRUCT: sequence_node_data_items
589 { start yaml_node_item_t* }
590 { end yaml_node_item_t* }
591 { top yaml_node_item_t* }
593 STRUCT: sequence_node_data
594 { items sequence_node_data_items }
595 { style yaml_sequence_style_t }
598 ! /** The mapping parameters (for @c YAML_MAPPING_NODE). */
599 ! /** The stack of mapping pairs (key, value). */
600 STRUCT: mapping_node_data_pairs
601 { start yaml_node_pair_t* }
602 { end yaml_node_pair_t* }
603 { top yaml_node_pair_t* }
605 STRUCT: mapping_node_data
606 { pairs mapping_node_data_pairs }
607 { style yaml_mapping_style_t }
609 UNION-STRUCT: node_data
610 { scalar scalar_node_data }
611 { sequence sequence_node_data }
612 { mapping mapping_node_data }
617 { type yaml_node_type_t }
623 { start_mark yaml_mark_t }
624 { end_mark yaml_mark_t }
628 ! /** The document structure. */
629 ! /** The document nodes. */
630 STRUCT: yaml_document_nodes
631 { start yaml_node_t* }
636 ! /** The list of tag directives. */
637 STRUCT: yaml_document_tag_directives
638 { start yaml_tag_directive_t* }
639 { end yaml_tag_directive_t* }
642 STRUCT: yaml_document_t
644 { nodes yaml_document_nodes }
646 { version_directive yaml_version_directive_t* }
648 { tag_directives yaml_document_tag_directives }
650 { start_implicit int }
653 { start_mark yaml_mark_t }
654 { end_mark yaml_mark_t }
659 ! * Create a YAML document.
661 ! * @param[out] document An empty document object.
662 ! * @param[in] version_directive The %YAML directive value or
664 ! * @param[in] tag_directives_start The beginning of the %TAG
666 ! * @param[in] tag_directives_end The end of the %TAG directives
668 ! * @param[in] start_implicit If the document start indicator is
670 ! * @param[in] end_implicit If the document end indicator is
673 ! * @returns @c 1 if the function succeeded, @c 0 on error.
677 yaml_document_initialize ( yaml_document_t *document,
678 yaml_version_directive_t *version_directive,
679 yaml_tag_directive_t *tag_directives_start,
680 yaml_tag_directive_t *tag_directives_end,
681 bool start_implicit, bool end_implicit )
684 ! * Delete a YAML document and all its nodes.
686 ! * @param[in,out] document A document object.
690 yaml_document_delete ( yaml_document_t *document )
691 DESTRUCTOR: yaml_document_delete
694 ! * Get a node of a YAML document.
696 ! * The pointer returned by this function is valid until any of the functions
697 ! * modifying the documents are called.
699 ! * @param[in] document A document object.
700 ! * @param[in] index The node id.
702 ! * @returns the node objct or @c NULL if @c node_id is out of range.
705 FUNCTION: yaml_node_t*
706 yaml_document_get_node ( yaml_document_t *document, int index )
709 ! * Get the root of a YAML document node.
711 ! * The root object is the first object added to the document.
713 ! * The pointer returned by this function is valid until any of the functions
714 ! * modifying the documents are called.
716 ! * An empty document produced by the parser signifies the end of a YAML
719 ! * @param[in] document A document object.
721 ! * @returns the node object or @c NULL if the document is empty.
724 FUNCTION: yaml_node_t*
725 yaml_document_get_root_node ( yaml_document_t *document )
728 ! * Create a SCALAR node and attach it to the document.
730 ! * The @a style argument may be ignored by the emitter.
732 ! * @param[in,out] document A document object.
733 ! * @param[in] tag The scalar tag.
734 ! * @param[in] value The scalar value.
735 ! * @param[in] length The length of the scalar value.
736 ! * @param[in] style The scalar style.
738 ! * @returns the node id or @c 0 on error.
742 yaml_document_add_scalar ( yaml_document_t *document,
743 c-string tag, c-string value, int length,
744 yaml_scalar_style_t style )
747 ! * Create a SEQUENCE node and attach it to the document.
749 ! * The @a style argument may be ignored by the emitter.
751 ! * @param[in,out] document A document object.
752 ! * @param[in] tag The sequence tag.
753 ! * @param[in] style The sequence style.
755 ! * @returns the node id or @c 0 on error.
759 yaml_document_add_sequence ( yaml_document_t *document,
760 c-string tag, yaml_sequence_style_t style )
763 ! * Create a MAPPING node and attach it to the document.
765 ! * The @a style argument may be ignored by the emitter.
767 ! * @param[in,out] document A document object.
768 ! * @param[in] tag The sequence tag.
769 ! * @param[in] style The sequence style.
771 ! * @returns the node id or @c 0 on error.
775 yaml_document_add_mapping ( yaml_document_t *document,
776 c-string tag, yaml_mapping_style_t style )
779 ! * Add an item to a SEQUENCE node.
781 ! * @param[in,out] document A document object.
782 ! * @param[in] sequence The sequence node id.
783 ! * @param[in] item The item node id.
785 ! * @returns @c 1 if the function succeeded, @c 0 on error.
789 yaml_document_append_sequence_item ( yaml_document_t *document,
790 int sequence, int item )
793 ! * Add a pair of a key and a value to a MAPPING node.
795 ! * @param[in,out] document A document object.
796 ! * @param[in] mapping The mapping node id.
797 ! * @param[in] key The key node id.
798 ! * @param[in] value The value node id.
800 ! * @returns @c 1 if the function succeeded, @c 0 on error.
804 yaml_document_append_mapping_pair ( yaml_document_t *document,
805 int mapping, int key, int value )
810 ! * @defgroup parser Parser Definitions
815 ! * The prototype of a read handler.
817 ! * The read handler is called when the parser needs to read more bytes from the
818 ! * source. The handler should write not more than @a size bytes to the @a
819 ! * buffer. The number of written bytes should be set to the @a length variable.
821 ! * @param[in,out] data A pointer to an application data specified by
822 ! * yaml_parser_set_input().
823 ! * @param[out] buffer The buffer to write the data from the source.
824 ! * @param[in] size The size of the buffer.
825 ! * @param[out] size_read The actual number of bytes read from the source.
827 ! * @returns On success, the handler should return @c 1. If the handler failed,
828 ! * the returned value should be @c 0. On EOF, the handler should set the
829 ! * @a size_read to @c 0 and return @c 1.
832 CALLBACK: bool yaml_read_handler_t ( void *data, uchar *buffer, size_t size,
836 ! * This structure holds information about a potential simple key.
839 STRUCT: yaml_simple_key_t
844 { token_number size_t }
850 ! * The states of the parser.
852 ENUM: yaml_parser_state_t
853 YAML_PARSE_STREAM_START_STATE
854 YAML_PARSE_IMPLICIT_DOCUMENT_START_STATE
855 YAML_PARSE_DOCUMENT_START_STATE
856 YAML_PARSE_DOCUMENT_CONTENT_STATE
857 YAML_PARSE_DOCUMENT_END_STATE
858 YAML_PARSE_BLOCK_NODE_STATE
859 YAML_PARSE_BLOCK_NODE_OR_INDENTLESS_SEQUENCE_STATE
860 YAML_PARSE_FLOW_NODE_STATE
861 YAML_PARSE_BLOCK_SEQUENCE_FIRST_ENTRY_STATE
862 YAML_PARSE_BLOCK_SEQUENCE_ENTRY_STATE
863 YAML_PARSE_INDENTLESS_SEQUENCE_ENTRY_STATE
864 YAML_PARSE_BLOCK_MAPPING_FIRST_KEY_STATE
865 YAML_PARSE_BLOCK_MAPPING_KEY_STATE
866 YAML_PARSE_BLOCK_MAPPING_VALUE_STATE
867 YAML_PARSE_FLOW_SEQUENCE_FIRST_ENTRY_STATE
868 YAML_PARSE_FLOW_SEQUENCE_ENTRY_STATE
869 YAML_PARSE_FLOW_SEQUENCE_ENTRY_MAPPING_KEY_STATE
870 YAML_PARSE_FLOW_SEQUENCE_ENTRY_MAPPING_VALUE_STATE
871 YAML_PARSE_FLOW_SEQUENCE_ENTRY_MAPPING_END_STATE
872 YAML_PARSE_FLOW_MAPPING_FIRST_KEY_STATE
873 YAML_PARSE_FLOW_MAPPING_KEY_STATE
874 YAML_PARSE_FLOW_MAPPING_VALUE_STATE
875 YAML_PARSE_FLOW_MAPPING_EMPTY_VALUE_STATE
880 ! * This structure holds aliases data.
883 STRUCT: yaml_alias_data_t
890 ! * The parser structure.
892 ! * All members are internal. Manage the structure using the @c yaml_parser_
893 ! * family of functions.
896 ! /** Standard (string or file) input data. */
897 ! /** String input data. */
898 STRUCT: string_yaml_parser_input
903 UNION-STRUCT: yaml_parser_input
904 { string string_yaml_parser_input }
908 ! /** The working buffer. */
909 STRUCT: yaml_parser_buffer
910 { start yaml_char_t* }
912 { pointer yaml_char_t* }
913 { last yaml_char_t* }
916 ! /** The raw buffer. */
917 STRUCT: yaml_parser_raw_buffer
924 ! /** The tokens queue. */
925 STRUCT: yaml_parser_tokens
926 { start yaml_token_t* }
927 { end yaml_token_t* }
928 { head yaml_token_t* }
929 { tail yaml_token_t* }
932 ! /** The indentation levels stack. */
933 STRUCT: yaml_parser_indents
939 ! /** The stack of simple keys. */
940 STRUCT: yaml_parser_simple_keys
941 { start yaml_simple_key_t* }
942 { end yaml_simple_key_t* }
943 { top yaml_simple_key_t* }
946 ! /** The parser states stack. */
947 STRUCT: yaml_parser_states
948 { start yaml_parser_state_t* }
949 { end yaml_parser_state_t* }
950 { top yaml_parser_state_t* }
953 ! /** The stack of marks. */
954 STRUCT: yaml_parser_marks
955 { start yaml_mark_t* }
960 ! /** The list of TAG directives. */
961 STRUCT: yaml_parser_tag_directives
962 { start yaml_tag_directive_t* }
963 { end yaml_tag_directive_t* }
964 { top yaml_tag_directive_t* }
967 ! /** The alias data. */
968 STRUCT: yaml_parser_aliases
969 { start yaml_alias_data_t* }
970 { end yaml_alias_data_t* }
971 { top yaml_alias_data_t* }
973 STRUCT: yaml_parser_t
975 { error yaml_error_type_t }
977 { problem_offset size_t }
978 { problem_value int }
979 { problem_mark yaml_mark_t }
981 { context_mark yaml_mark_t }
983 { read_handler yaml_read_handler_t* }
985 { read_handler_data void* }
987 { input yaml_parser_input }
991 { buffer yaml_parser_buffer }
995 { raw_buffer yaml_parser_raw_buffer }
997 { encoding yaml_encoding_t }
1001 { mark yaml_mark_t }
1003 { stream_start_produced int }
1005 { stream_end_produced int }
1009 { tokens yaml_parser_tokens }
1011 { tokens_parsed size_t }
1013 { token_available int }
1015 { indents yaml_parser_indents }
1019 { simple_key_allowed int }
1021 { simple_keys yaml_parser_simple_keys }
1023 { states yaml_parser_states }
1025 { state yaml_parser_state_t }
1027 { marks yaml_parser_marks }
1029 { tag_directives yaml_parser_tag_directives }
1031 { aliases yaml_parser_aliases }
1033 { document yaml_document_t* }
1037 ! * Initialize a parser.
1039 ! * This function creates a new parser object. An application is responsible
1040 ! * for destroying the object using the yaml_parser_delete() function.
1042 ! * @param[out] parser An empty parser object.
1044 ! * @returns @c 1 if the function succeeded, @c 0 on error.
1048 yaml_parser_initialize ( yaml_parser_t *parser )
1051 ! * Destroy a parser.
1053 ! * @param[in,out] parser A parser object.
1057 yaml_parser_delete ( yaml_parser_t *parser )
1058 DESTRUCTOR: yaml_parser_delete
1061 ! * Set a string input.
1063 ! * Note that the @a input pointer must be valid while the @a parser object
1064 ! * exists. The application is responsible for destroing @a input after
1065 ! * destroying the @a parser.
1067 ! * @param[in,out] parser A parser object.
1068 ! * @param[in] input A source data.
1069 ! * @param[in] size The length of the source data in bytes.
1073 yaml_parser_set_input_string ( yaml_parser_t *parser,
1074 uchar *input, size_t size )
1077 ! * Set a file input.
1079 ! * @a file should be a file object open for reading. The application is
1080 ! * responsible for closing the @a file.
1082 ! * @param[in,out] parser A parser object.
1083 ! * @param[in] file An open file.
1087 yaml_parser_set_input_file ( yaml_parser_t *parser, FILE *file )
1090 ! * Set a generic input handler.
1092 ! * @param[in,out] parser A parser object.
1093 ! * @param[in] handler A read handler.
1094 ! * @param[in] data Any application data for passing to the read
1099 yaml_parser_set_input ( yaml_parser_t *parser,
1100 yaml_read_handler_t *handler, void *data )
1103 ! * Set the source encoding.
1105 ! * @param[in,out] parser A parser object.
1106 ! * @param[in] encoding The source encoding.
1110 yaml_parser_set_encoding ( yaml_parser_t *parser, yaml_encoding_t encoding )
1113 ! * Scan the input stream and produce the next token.
1115 ! * Call the function subsequently to produce a sequence of tokens corresponding
1116 ! * to the input stream. The initial token has the type
1117 ! * @c YAML_STREAM_START_TOKEN while the ending token has the type
1118 ! * @c YAML_STREAM_END_TOKEN.
1120 ! * An application is responsible for freeing any buffers associated with the
1121 ! * produced token object using the @c yaml_token_delete function.
1123 ! * An application must not alternate the calls of yaml_parser_scan() with the
1124 ! * calls of yaml_parser_parse() or yaml_parser_load(). Doing this will break
1127 ! * @param[in,out] parser A parser object.
1128 ! * @param[out] token An empty token object.
1130 ! * @returns @c 1 if the function succeeded, @c 0 on error.
1134 yaml_parser_scan ( yaml_parser_t *parser, yaml_token_t *token )
1137 ! * Parse the input stream and produce the next parsing event.
1139 ! * Call the function subsequently to produce a sequence of events corresponding
1140 ! * to the input stream. The initial event has the type
1141 ! * @c YAML_STREAM_START_EVENT while the ending event has the type
1142 ! * @c YAML_STREAM_END_EVENT.
1144 ! * An application is responsible for freeing any buffers associated with the
1145 ! * produced event object using the yaml_event_delete() function.
1147 ! * An application must not alternate the calls of yaml_parser_parse() with the
1148 ! * calls of yaml_parser_scan() or yaml_parser_load(). Doing this will break the
1151 ! * @param[in,out] parser A parser object.
1152 ! * @param[out] event An empty event object.
1154 ! * @returns @c 1 if the function succeeded, @c 0 on error.
1158 yaml_parser_parse ( yaml_parser_t *parser, yaml_event_t *event )
1161 ! * Parse the input stream and produce the next YAML document.
1163 ! * Call this function subsequently to produce a sequence of documents
1164 ! * constituting the input stream.
1166 ! * If the produced document has no root node, it means that the document
1167 ! * end has been reached.
1169 ! * An application is responsible for freeing any data associated with the
1170 ! * produced document object using the yaml_document_delete() function.
1172 ! * An application must not alternate the calls of yaml_parser_load() with the
1173 ! * calls of yaml_parser_scan() or yaml_parser_parse(). Doing this will break
1176 ! * @param[in,out] parser A parser object.
1177 ! * @param[out] document An empty document object.
1179 ! * @return @c 1 if the function succeeded, @c 0 on error.
1183 yaml_parser_load ( yaml_parser_t *parser, yaml_document_t *document )
1188 ! * @defgroup emitter Emitter Definitions
1193 ! * The prototype of a write handler.
1195 ! * The write handler is called when the emitter needs to flush the accumulated
1196 ! * characters to the output. The handler should write @a size bytes of the
1197 ! * @a buffer to the output.
1199 ! * @param[in,out] data A pointer to an application data specified by
1200 ! * yaml_emitter_set_output().
1201 ! * @param[in] buffer The buffer with bytes to be written.
1202 ! * @param[in] size The size of the buffer.
1204 ! * @returns On success, the handler should return @c 1. If the handler failed,
1205 ! * the returned value should be @c 0.
1208 CALLBACK: bool yaml_write_handler_t ( void *data, uchar *buffer, size_t size )
1210 ! /** The emitter states. */
1211 ENUM: yaml_emitter_state_t
1212 YAML_EMIT_STREAM_START_STATE
1213 YAML_EMIT_FIRST_DOCUMENT_START_STATE
1214 YAML_EMIT_DOCUMENT_START_STATE
1215 YAML_EMIT_DOCUMENT_CONTENT_STATE
1216 YAML_EMIT_DOCUMENT_END_STATE
1217 YAML_EMIT_FLOW_SEQUENCE_FIRST_ITEM_STATE
1218 YAML_EMIT_FLOW_SEQUENCE_ITEM_STATE
1219 YAML_EMIT_FLOW_MAPPING_FIRST_KEY_STATE
1220 YAML_EMIT_FLOW_MAPPING_KEY_STATE
1221 YAML_EMIT_FLOW_MAPPING_SIMPLE_VALUE_STATE
1222 YAML_EMIT_FLOW_MAPPING_VALUE_STATE
1223 YAML_EMIT_BLOCK_SEQUENCE_FIRST_ITEM_STATE
1224 YAML_EMIT_BLOCK_SEQUENCE_ITEM_STATE
1225 YAML_EMIT_BLOCK_MAPPING_FIRST_KEY_STATE
1226 YAML_EMIT_BLOCK_MAPPING_KEY_STATE
1227 YAML_EMIT_BLOCK_MAPPING_SIMPLE_VALUE_STATE
1228 YAML_EMIT_BLOCK_MAPPING_VALUE_STATE
1233 ! * The emitter structure.
1235 ! * All members are internal. Manage the structure using the @c yaml_emitter_
1236 ! * family of functions.
1239 ! /** Standard (string or file) output data. */
1240 ! /** String output data. */
1241 STRUCT: yaml_emitter_output_string
1244 { size_written size_t* }
1247 UNION-STRUCT: yaml_emitter_output
1248 { string yaml_emitter_output_string }
1253 ! /** The working buffer. */
1254 STRUCT: yaml_emitter_buffer
1255 { start yaml_char_t* }
1256 { end yaml_char_t* }
1257 { pointer yaml_char_t* }
1258 { last yaml_char_t* }
1261 ! /** The raw buffer. */
1262 STRUCT: yaml_emitter_raw_buffer
1269 ! /** The stack of states. */
1270 STRUCT: yaml_emitter_states
1271 { start yaml_emitter_state_t* }
1272 { end yaml_emitter_state_t* }
1273 { top yaml_emitter_state_t* }
1276 ! /** The event queue. */
1277 STRUCT: yaml_emitter_events
1278 { start yaml_event_t* }
1279 { end yaml_event_t* }
1280 { head yaml_event_t* }
1281 { tail yaml_event_t* }
1284 ! /** The stack of indentation levels. */
1285 STRUCT: yaml_emitter_indents
1291 ! /** The list of tag directives. */
1292 STRUCT: yaml_emitter_tag_directives
1293 { start yaml_tag_directive_t* }
1294 { end yaml_tag_directive_t* }
1295 { top yaml_tag_directive_t* }
1298 ! /** Anchor analysis. */
1299 STRUCT: yaml_emitter_anchor_data
1301 { anchor_length size_t }
1305 ! /** Tag analysis. */
1306 STRUCT: yaml_emitter_tag_data
1308 { handle_length size_t }
1310 { suffix_length size_t }
1313 ! /** Scalar analysis. */
1314 STRUCT: yaml_emitter_scalar_data
1318 { flow_plain_allowed int }
1319 { block_plain_allowed int }
1320 { single_quoted_allowed int }
1321 { block_allowed int }
1322 { style yaml_scalar_style_t }
1325 ! /** The information associated with the document nodes. */
1326 STRUCT: yaml_emitter_anchors
1331 STRUCT: yaml_emitter_t
1333 { error yaml_error_type_t }
1334 { problem c-string }
1336 { write_handler yaml_write_handler_t* }
1338 { write_handler_data void* }
1340 { output yaml_emitter_output }
1342 { buffer yaml_emitter_buffer }
1344 { raw_buffer yaml_emitter_raw_buffer }
1346 { encoding yaml_encoding_t }
1352 { line_break yaml_break_t }
1354 { states yaml_emitter_states }
1355 { state yaml_emitter_state_t }
1357 { events yaml_emitter_events }
1359 { indents yaml_emitter_indents }
1361 { tag_directives yaml_emitter_tag_directives }
1367 { root_context int }
1368 { sequence_context int }
1369 { mapping_context int }
1370 { simple_key_context int }
1378 { anchor_data yaml_emitter_anchor_data }
1380 { tag_data yaml_emitter_tag_data }
1382 { scalar_data yaml_emitter_scalar_data }
1387 { anchors yaml_emitter_anchors* }
1389 { last_anchor_id int }
1391 { document yaml_document_t* }
1396 ! * Initialize an emitter.
1398 ! * This function creates a new emitter object. An application is responsible
1399 ! * for destroying the object using the yaml_emitter_delete() function.
1401 ! * @param[out] emitter An empty parser object.
1403 ! * @returns @c 1 if the function succeeded, @c 0 on error.
1407 yaml_emitter_initialize ( yaml_emitter_t *emitter )
1410 ! * Destroy an emitter.
1412 ! * @param[in,out] emitter An emitter object.
1416 yaml_emitter_delete ( yaml_emitter_t *emitter )
1417 DESTRUCTOR: yaml_emitter_delete
1420 ! * Set a string output.
1422 ! * The emitter will write the output characters to the @a output buffer of the
1423 ! * size @a size. The emitter will set @a size_written to the number of written
1424 ! * bytes. If the buffer is smaller than required, the emitter produces the
1425 ! * YAML_WRITE_ERROR error.
1427 ! * @param[in,out] emitter An emitter object.
1428 ! * @param[in] output An output buffer.
1429 ! * @param[in] size The buffer size.
1430 ! * @param[in] size_written The pointer to save the number of written
1435 yaml_emitter_set_output_string ( yaml_emitter_t *emitter,
1436 uchar *output, size_t size, size_t *size_written )
1439 ! * Set a file output.
1441 ! * @a file should be a file object open for writing. The application is
1442 ! * responsible for closing the @a file.
1444 ! * @param[in,out] emitter An emitter object.
1445 ! * @param[in] file An open file.
1449 yaml_emitter_set_output_file ( yaml_emitter_t *emitter, FILE *file )
1452 ! * Set a generic output handler.
1454 ! * @param[in,out] emitter An emitter object.
1455 ! * @param[in] handler A write handler.
1456 ! * @param[in] data Any application data for passing to the write
1461 yaml_emitter_set_output ( yaml_emitter_t *emitter,
1462 yaml_write_handler_t *handler, void *data )
1465 ! * Set the output encoding.
1467 ! * @param[in,out] emitter An emitter object.
1468 ! * @param[in] encoding The output encoding.
1472 yaml_emitter_set_encoding ( yaml_emitter_t *emitter, yaml_encoding_t encoding )
1475 ! * Set if the output should be in the "canonical" format as in the YAML
1478 ! * @param[in,out] emitter An emitter object.
1479 ! * @param[in] canonical If the output is canonical.
1483 yaml_emitter_set_canonical ( yaml_emitter_t *emitter, bool canonical )
1486 ! * Set the intendation increment.
1488 ! * @param[in,out] emitter An emitter object.
1489 ! * @param[in] indent The indentation increment (1 < . < 10).
1493 yaml_emitter_set_indent ( yaml_emitter_t *emitter, int indent )
1496 ! * Set the preferred line width. @c -1 means unlimited.
1498 ! * @param[in,out] emitter An emitter object.
1499 ! * @param[in] width The preferred line width.
1503 yaml_emitter_set_width ( yaml_emitter_t *emitter, int width )
1506 ! * Set if unescaped non-ASCII characters are allowed.
1508 ! * @param[in,out] emitter An emitter object.
1509 ! * @param[in] unicode If unescaped Unicode characters are allowed.
1513 yaml_emitter_set_unicode ( yaml_emitter_t *emitter, bool unicode )
1516 ! * Set the preferred line break.
1518 ! * @param[in,out] emitter An emitter object.
1519 ! * @param[in] line_break The preferred line break.
1523 yaml_emitter_set_break ( yaml_emitter_t *emitter, yaml_break_t line_break )
1528 ! * The event object may be generated using the yaml_parser_parse() function.
1529 ! * The emitter takes the responsibility for the event object and destroys its
1530 ! * content after it is emitted. The event object is destroyed even if the
1533 ! * @param[in,out] emitter An emitter object.
1534 ! * @param[in,out] event An event object.
1536 ! * @returns @c 1 if the function succeeded, @c 0 on error.
1540 yaml_emitter_emit ( yaml_emitter_t *emitter, yaml_event_t *event )
1543 ! * Start a YAML stream.
1545 ! * This function should be used before yaml_emitter_dump() is called.
1547 ! * @param[in,out] emitter An emitter object.
1549 ! * @returns @c 1 if the function succeeded, @c 0 on error.
1553 yaml_emitter_open ( yaml_emitter_t *emitter )
1556 ! * Finish a YAML stream.
1558 ! * This function should be used after yaml_emitter_dump() is called.
1560 ! * @param[in,out] emitter An emitter object.
1562 ! * @returns @c 1 if the function succeeded, @c 0 on error.
1566 yaml_emitter_close ( yaml_emitter_t *emitter )
1569 ! * Emit a YAML document.
1571 ! * The documen object may be generated using the yaml_parser_load() function
1572 ! * or the yaml_document_initialize() function. The emitter takes the
1573 ! * responsibility for the document object and destoys its content after
1574 ! * it is emitted. The document object is destroyedeven if the function fails.
1576 ! * @param[in,out] emitter An emitter object.
1577 ! * @param[in,out] document A document object.
1579 ! * @returns @c 1 if the function succeeded, @c 0 on error.
1583 yaml_emitter_dump ( yaml_emitter_t *emitter, yaml_document_t *document )
1586 ! * Flush the accumulated characters to the output.
1588 ! * @param[in,out] emitter An emitter object.
1590 ! * @returns @c 1 if the function succeeded, @c 0 on error.
1594 yaml_emitter_flush ( yaml_emitter_t *emitter )
1598 ! #ifdef __cplusplus
1602 ! #endif /* #ifndef YAML_H */