1247738Sbapt/**
2247738Sbapt * @file yaml.h
3247738Sbapt * @brief Public interface for libyaml.
4247738Sbapt *
5247738Sbapt * Include the header file with the code:
6247738Sbapt * @code
7247738Sbapt * #include <yaml.h>
8247738Sbapt * @endcode
9247738Sbapt */
10247738Sbapt
11247738Sbapt#ifndef YAML_H
12247738Sbapt#define YAML_H
13247738Sbapt
14247738Sbapt#ifdef __cplusplus
15247738Sbaptextern "C" {
16247738Sbapt#endif
17247738Sbapt
18247738Sbapt#include <stdlib.h>
19247738Sbapt#include <stdio.h>
20247738Sbapt#include <string.h>
21247738Sbapt
22247738Sbapt/**
23247738Sbapt * @defgroup export Export Definitions
24247738Sbapt * @{
25247738Sbapt */
26247738Sbapt
27247738Sbapt/** The public API declaration. */
28247738Sbapt
29247738Sbapt#ifdef _WIN32
30247738Sbapt#   if defined(YAML_DECLARE_STATIC)
31247738Sbapt#       define  YAML_DECLARE(type)  type
32247738Sbapt#   elif defined(YAML_DECLARE_EXPORT)
33247738Sbapt#       define  YAML_DECLARE(type)  __declspec(dllexport) type
34247738Sbapt#   else
35247738Sbapt#       define  YAML_DECLARE(type)  __declspec(dllimport) type
36247738Sbapt#   endif
37247738Sbapt#else
38247738Sbapt#   define  YAML_DECLARE(type)  type
39247738Sbapt#endif
40247738Sbapt
41247738Sbapt/** @} */
42247738Sbapt
43247738Sbapt/**
44247738Sbapt * @defgroup version Version Information
45247738Sbapt * @{
46247738Sbapt */
47247738Sbapt
48247738Sbapt/**
49247738Sbapt * Get the library version as a string.
50247738Sbapt *
51247738Sbapt * @returns The function returns the pointer to a static string of the form
52247738Sbapt * @c "X.Y.Z", where @c X is the major version number, @c Y is a minor version
53247738Sbapt * number, and @c Z is the patch version number.
54247738Sbapt */
55247738Sbapt
56247738SbaptYAML_DECLARE(const char *)
57247738Sbaptyaml_get_version_string(void);
58247738Sbapt
59247738Sbapt/**
60247738Sbapt * Get the library version numbers.
61247738Sbapt *
62247738Sbapt * @param[out]      major   Major version number.
63247738Sbapt * @param[out]      minor   Minor version number.
64247738Sbapt * @param[out]      patch   Patch version number.
65247738Sbapt */
66247738Sbapt
67247738SbaptYAML_DECLARE(void)
68247738Sbaptyaml_get_version(int *major, int *minor, int *patch);
69247738Sbapt
70247738Sbapt/** @} */
71247738Sbapt
72247738Sbapt/**
73247738Sbapt * @defgroup basic Basic Types
74247738Sbapt * @{
75247738Sbapt */
76247738Sbapt
77247738Sbapt/** The character type (UTF-8 octet). */
78247738Sbapttypedef unsigned char yaml_char_t;
79247738Sbapt
80247738Sbapt/** The version directive data. */
81247738Sbapttypedef struct yaml_version_directive_s {
82247738Sbapt    /** The major version number. */
83247738Sbapt    int major;
84247738Sbapt    /** The minor version number. */
85247738Sbapt    int minor;
86247738Sbapt} yaml_version_directive_t;
87247738Sbapt
88247738Sbapt/** The tag directive data. */
89247738Sbapttypedef struct yaml_tag_directive_s {
90247738Sbapt    /** The tag handle. */
91247738Sbapt    yaml_char_t *handle;
92247738Sbapt    /** The tag prefix. */
93247738Sbapt    yaml_char_t *prefix;
94247738Sbapt} yaml_tag_directive_t;
95247738Sbapt
96247738Sbapt/** The stream encoding. */
97247738Sbapttypedef enum yaml_encoding_e {
98247738Sbapt    /** Let the parser choose the encoding. */
99247738Sbapt    YAML_ANY_ENCODING,
100247738Sbapt    /** The default UTF-8 encoding. */
101247738Sbapt    YAML_UTF8_ENCODING,
102247738Sbapt    /** The UTF-16-LE encoding with BOM. */
103247738Sbapt    YAML_UTF16LE_ENCODING,
104247738Sbapt    /** The UTF-16-BE encoding with BOM. */
105247738Sbapt    YAML_UTF16BE_ENCODING
106247738Sbapt} yaml_encoding_t;
107247738Sbapt
108247738Sbapt/** Line break types. */
109247738Sbapt
110247738Sbapttypedef enum yaml_break_e {
111247738Sbapt    /** Let the parser choose the break type. */
112247738Sbapt    YAML_ANY_BREAK,
113247738Sbapt    /** Use CR for line breaks (Mac style). */
114247738Sbapt    YAML_CR_BREAK,
115247738Sbapt    /** Use LN for line breaks (Unix style). */
116247738Sbapt    YAML_LN_BREAK,
117247738Sbapt    /** Use CR LN for line breaks (DOS style). */
118247738Sbapt    YAML_CRLN_BREAK
119247738Sbapt} yaml_break_t;
120247738Sbapt
121247738Sbapt/** Many bad things could happen with the parser and emitter. */
122247738Sbapttypedef enum yaml_error_type_e {
123247738Sbapt    /** No error is produced. */
124247738Sbapt    YAML_NO_ERROR,
125247738Sbapt
126247738Sbapt    /** Cannot allocate or reallocate a block of memory. */
127247738Sbapt    YAML_MEMORY_ERROR,
128247738Sbapt
129247738Sbapt    /** Cannot read or decode the input stream. */
130247738Sbapt    YAML_READER_ERROR,
131247738Sbapt    /** Cannot scan the input stream. */
132247738Sbapt    YAML_SCANNER_ERROR,
133247738Sbapt    /** Cannot parse the input stream. */
134247738Sbapt    YAML_PARSER_ERROR,
135247738Sbapt    /** Cannot compose a YAML document. */
136247738Sbapt    YAML_COMPOSER_ERROR,
137247738Sbapt
138247738Sbapt    /** Cannot write to the output stream. */
139247738Sbapt    YAML_WRITER_ERROR,
140247738Sbapt    /** Cannot emit a YAML stream. */
141247738Sbapt    YAML_EMITTER_ERROR
142247738Sbapt} yaml_error_type_t;
143247738Sbapt
144247738Sbapt/** The pointer position. */
145247738Sbapttypedef struct yaml_mark_s {
146247738Sbapt    /** The position index. */
147247738Sbapt    size_t index;
148247738Sbapt
149247738Sbapt    /** The position line. */
150247738Sbapt    size_t line;
151247738Sbapt
152247738Sbapt    /** The position column. */
153247738Sbapt    size_t column;
154247738Sbapt} yaml_mark_t;
155247738Sbapt
156247738Sbapt/** @} */
157247738Sbapt
158247738Sbapt/**
159247738Sbapt * @defgroup styles Node Styles
160247738Sbapt * @{
161247738Sbapt */
162247738Sbapt
163247738Sbapt/** Scalar styles. */
164247738Sbapttypedef enum yaml_scalar_style_e {
165247738Sbapt    /** Let the emitter choose the style. */
166247738Sbapt    YAML_ANY_SCALAR_STYLE,
167247738Sbapt
168247738Sbapt    /** The plain scalar style. */
169247738Sbapt    YAML_PLAIN_SCALAR_STYLE,
170247738Sbapt
171247738Sbapt    /** The single-quoted scalar style. */
172247738Sbapt    YAML_SINGLE_QUOTED_SCALAR_STYLE,
173247738Sbapt    /** The double-quoted scalar style. */
174247738Sbapt    YAML_DOUBLE_QUOTED_SCALAR_STYLE,
175247738Sbapt
176247738Sbapt    /** The literal scalar style. */
177247738Sbapt    YAML_LITERAL_SCALAR_STYLE,
178247738Sbapt    /** The folded scalar style. */
179247738Sbapt    YAML_FOLDED_SCALAR_STYLE
180247738Sbapt} yaml_scalar_style_t;
181247738Sbapt
182247738Sbapt/** Sequence styles. */
183247738Sbapttypedef enum yaml_sequence_style_e {
184247738Sbapt    /** Let the emitter choose the style. */
185247738Sbapt    YAML_ANY_SEQUENCE_STYLE,
186247738Sbapt
187247738Sbapt    /** The block sequence style. */
188247738Sbapt    YAML_BLOCK_SEQUENCE_STYLE,
189247738Sbapt    /** The flow sequence style. */
190247738Sbapt    YAML_FLOW_SEQUENCE_STYLE
191247738Sbapt} yaml_sequence_style_t;
192247738Sbapt
193247738Sbapt/** Mapping styles. */
194247738Sbapttypedef enum yaml_mapping_style_e {
195247738Sbapt    /** Let the emitter choose the style. */
196247738Sbapt    YAML_ANY_MAPPING_STYLE,
197247738Sbapt
198247738Sbapt    /** The block mapping style. */
199247738Sbapt    YAML_BLOCK_MAPPING_STYLE,
200247738Sbapt    /** The flow mapping style. */
201247738Sbapt    YAML_FLOW_MAPPING_STYLE
202247738Sbapt/*    YAML_FLOW_SET_MAPPING_STYLE   */
203247738Sbapt} yaml_mapping_style_t;
204247738Sbapt
205247738Sbapt/** @} */
206247738Sbapt
207247738Sbapt/**
208247738Sbapt * @defgroup tokens Tokens
209247738Sbapt * @{
210247738Sbapt */
211247738Sbapt
212247738Sbapt/** Token types. */
213247738Sbapttypedef enum yaml_token_type_e {
214247738Sbapt    /** An empty token. */
215247738Sbapt    YAML_NO_TOKEN,
216247738Sbapt
217247738Sbapt    /** A STREAM-START token. */
218247738Sbapt    YAML_STREAM_START_TOKEN,
219247738Sbapt    /** A STREAM-END token. */
220247738Sbapt    YAML_STREAM_END_TOKEN,
221247738Sbapt
222247738Sbapt    /** A VERSION-DIRECTIVE token. */
223247738Sbapt    YAML_VERSION_DIRECTIVE_TOKEN,
224247738Sbapt    /** A TAG-DIRECTIVE token. */
225247738Sbapt    YAML_TAG_DIRECTIVE_TOKEN,
226247738Sbapt    /** A DOCUMENT-START token. */
227247738Sbapt    YAML_DOCUMENT_START_TOKEN,
228247738Sbapt    /** A DOCUMENT-END token. */
229247738Sbapt    YAML_DOCUMENT_END_TOKEN,
230247738Sbapt
231247738Sbapt    /** A BLOCK-SEQUENCE-START token. */
232247738Sbapt    YAML_BLOCK_SEQUENCE_START_TOKEN,
233247738Sbapt    /** A BLOCK-SEQUENCE-END token. */
234247738Sbapt    YAML_BLOCK_MAPPING_START_TOKEN,
235247738Sbapt    /** A BLOCK-END token. */
236247738Sbapt    YAML_BLOCK_END_TOKEN,
237247738Sbapt
238247738Sbapt    /** A FLOW-SEQUENCE-START token. */
239247738Sbapt    YAML_FLOW_SEQUENCE_START_TOKEN,
240247738Sbapt    /** A FLOW-SEQUENCE-END token. */
241247738Sbapt    YAML_FLOW_SEQUENCE_END_TOKEN,
242247738Sbapt    /** A FLOW-MAPPING-START token. */
243247738Sbapt    YAML_FLOW_MAPPING_START_TOKEN,
244247738Sbapt    /** A FLOW-MAPPING-END token. */
245247738Sbapt    YAML_FLOW_MAPPING_END_TOKEN,
246247738Sbapt
247247738Sbapt    /** A BLOCK-ENTRY token. */
248247738Sbapt    YAML_BLOCK_ENTRY_TOKEN,
249247738Sbapt    /** A FLOW-ENTRY token. */
250247738Sbapt    YAML_FLOW_ENTRY_TOKEN,
251247738Sbapt    /** A KEY token. */
252247738Sbapt    YAML_KEY_TOKEN,
253247738Sbapt    /** A VALUE token. */
254247738Sbapt    YAML_VALUE_TOKEN,
255247738Sbapt
256247738Sbapt    /** An ALIAS token. */
257247738Sbapt    YAML_ALIAS_TOKEN,
258247738Sbapt    /** An ANCHOR token. */
259247738Sbapt    YAML_ANCHOR_TOKEN,
260247738Sbapt    /** A TAG token. */
261247738Sbapt    YAML_TAG_TOKEN,
262247738Sbapt    /** A SCALAR token. */
263247738Sbapt    YAML_SCALAR_TOKEN
264247738Sbapt} yaml_token_type_t;
265247738Sbapt
266247738Sbapt/** The token structure. */
267247738Sbapttypedef struct yaml_token_s {
268247738Sbapt
269247738Sbapt    /** The token type. */
270247738Sbapt    yaml_token_type_t type;
271247738Sbapt
272247738Sbapt    /** The token data. */
273247738Sbapt    union {
274247738Sbapt
275247738Sbapt        /** The stream start (for @c YAML_STREAM_START_TOKEN). */
276247738Sbapt        struct {
277247738Sbapt            /** The stream encoding. */
278247738Sbapt            yaml_encoding_t encoding;
279247738Sbapt        } stream_start;
280247738Sbapt
281247738Sbapt        /** The alias (for @c YAML_ALIAS_TOKEN). */
282247738Sbapt        struct {
283247738Sbapt            /** The alias value. */
284247738Sbapt            yaml_char_t *value;
285247738Sbapt        } alias;
286247738Sbapt
287247738Sbapt        /** The anchor (for @c YAML_ANCHOR_TOKEN). */
288247738Sbapt        struct {
289247738Sbapt            /** The anchor value. */
290247738Sbapt            yaml_char_t *value;
291247738Sbapt        } anchor;
292247738Sbapt
293247738Sbapt        /** The tag (for @c YAML_TAG_TOKEN). */
294247738Sbapt        struct {
295247738Sbapt            /** The tag handle. */
296247738Sbapt            yaml_char_t *handle;
297247738Sbapt            /** The tag suffix. */
298247738Sbapt            yaml_char_t *suffix;
299247738Sbapt        } tag;
300247738Sbapt
301247738Sbapt        /** The scalar value (for @c YAML_SCALAR_TOKEN). */
302247738Sbapt        struct {
303247738Sbapt            /** The scalar value. */
304247738Sbapt            yaml_char_t *value;
305247738Sbapt            /** The length of the scalar value. */
306247738Sbapt            size_t length;
307247738Sbapt            /** The scalar style. */
308247738Sbapt            yaml_scalar_style_t style;
309247738Sbapt        } scalar;
310247738Sbapt
311247738Sbapt        /** The version directive (for @c YAML_VERSION_DIRECTIVE_TOKEN). */
312247738Sbapt        struct {
313247738Sbapt            /** The major version number. */
314247738Sbapt            int major;
315247738Sbapt            /** The minor version number. */
316247738Sbapt            int minor;
317247738Sbapt        } version_directive;
318247738Sbapt
319247738Sbapt        /** The tag directive (for @c YAML_TAG_DIRECTIVE_TOKEN). */
320247738Sbapt        struct {
321247738Sbapt            /** The tag handle. */
322247738Sbapt            yaml_char_t *handle;
323247738Sbapt            /** The tag prefix. */
324247738Sbapt            yaml_char_t *prefix;
325247738Sbapt        } tag_directive;
326247738Sbapt
327247738Sbapt    } data;
328247738Sbapt
329247738Sbapt    /** The beginning of the token. */
330247738Sbapt    yaml_mark_t start_mark;
331247738Sbapt    /** The end of the token. */
332247738Sbapt    yaml_mark_t end_mark;
333247738Sbapt
334247738Sbapt} yaml_token_t;
335247738Sbapt
336247738Sbapt/**
337247738Sbapt * Free any memory allocated for a token object.
338247738Sbapt *
339247738Sbapt * @param[in,out]   token   A token object.
340247738Sbapt */
341247738Sbapt
342247738SbaptYAML_DECLARE(void)
343247738Sbaptyaml_token_delete(yaml_token_t *token);
344247738Sbapt
345247738Sbapt/** @} */
346247738Sbapt
347247738Sbapt/**
348247738Sbapt * @defgroup events Events
349247738Sbapt * @{
350247738Sbapt */
351247738Sbapt
352247738Sbapt/** Event types. */
353247738Sbapttypedef enum yaml_event_type_e {
354247738Sbapt    /** An empty event. */
355247738Sbapt    YAML_NO_EVENT,
356247738Sbapt
357247738Sbapt    /** A STREAM-START event. */
358247738Sbapt    YAML_STREAM_START_EVENT,
359247738Sbapt    /** A STREAM-END event. */
360247738Sbapt    YAML_STREAM_END_EVENT,
361247738Sbapt
362247738Sbapt    /** A DOCUMENT-START event. */
363247738Sbapt    YAML_DOCUMENT_START_EVENT,
364247738Sbapt    /** A DOCUMENT-END event. */
365247738Sbapt    YAML_DOCUMENT_END_EVENT,
366247738Sbapt
367247738Sbapt    /** An ALIAS event. */
368247738Sbapt    YAML_ALIAS_EVENT,
369247738Sbapt    /** A SCALAR event. */
370247738Sbapt    YAML_SCALAR_EVENT,
371247738Sbapt
372247738Sbapt    /** A SEQUENCE-START event. */
373247738Sbapt    YAML_SEQUENCE_START_EVENT,
374247738Sbapt    /** A SEQUENCE-END event. */
375247738Sbapt    YAML_SEQUENCE_END_EVENT,
376247738Sbapt
377247738Sbapt    /** A MAPPING-START event. */
378247738Sbapt    YAML_MAPPING_START_EVENT,
379247738Sbapt    /** A MAPPING-END event. */
380247738Sbapt    YAML_MAPPING_END_EVENT
381247738Sbapt} yaml_event_type_t;
382247738Sbapt
383247738Sbapt/** The event structure. */
384247738Sbapttypedef struct yaml_event_s {
385247738Sbapt
386247738Sbapt    /** The event type. */
387247738Sbapt    yaml_event_type_t type;
388247738Sbapt
389247738Sbapt    /** The event data. */
390247738Sbapt    union {
391247738Sbapt
392247738Sbapt        /** The stream parameters (for @c YAML_STREAM_START_EVENT). */
393247738Sbapt        struct {
394247738Sbapt            /** The document encoding. */
395247738Sbapt            yaml_encoding_t encoding;
396247738Sbapt        } stream_start;
397247738Sbapt
398247738Sbapt        /** The document parameters (for @c YAML_DOCUMENT_START_EVENT). */
399247738Sbapt        struct {
400247738Sbapt            /** The version directive. */
401247738Sbapt            yaml_version_directive_t *version_directive;
402247738Sbapt
403247738Sbapt            /** The list of tag directives. */
404247738Sbapt            struct {
405247738Sbapt                /** The beginning of the tag directives list. */
406247738Sbapt                yaml_tag_directive_t *start;
407247738Sbapt                /** The end of the tag directives list. */
408247738Sbapt                yaml_tag_directive_t *end;
409247738Sbapt            } tag_directives;
410247738Sbapt
411247738Sbapt            /** Is the document indicator implicit? */
412247738Sbapt            int implicit;
413247738Sbapt        } document_start;
414247738Sbapt
415247738Sbapt        /** The document end parameters (for @c YAML_DOCUMENT_END_EVENT). */
416247738Sbapt        struct {
417247738Sbapt            /** Is the document end indicator implicit? */
418247738Sbapt            int implicit;
419247738Sbapt        } document_end;
420247738Sbapt
421247738Sbapt        /** The alias parameters (for @c YAML_ALIAS_EVENT). */
422247738Sbapt        struct {
423247738Sbapt            /** The anchor. */
424247738Sbapt            yaml_char_t *anchor;
425247738Sbapt        } alias;
426247738Sbapt
427247738Sbapt        /** The scalar parameters (for @c YAML_SCALAR_EVENT). */
428247738Sbapt        struct {
429247738Sbapt            /** The anchor. */
430247738Sbapt            yaml_char_t *anchor;
431247738Sbapt            /** The tag. */
432247738Sbapt            yaml_char_t *tag;
433247738Sbapt            /** The scalar value. */
434247738Sbapt            yaml_char_t *value;
435247738Sbapt            /** The length of the scalar value. */
436247738Sbapt            size_t length;
437247738Sbapt            /** Is the tag optional for the plain style? */
438247738Sbapt            int plain_implicit;
439247738Sbapt            /** Is the tag optional for any non-plain style? */
440247738Sbapt            int quoted_implicit;
441247738Sbapt            /** The scalar style. */
442247738Sbapt            yaml_scalar_style_t style;
443247738Sbapt        } scalar;
444247738Sbapt
445247738Sbapt        /** The sequence parameters (for @c YAML_SEQUENCE_START_EVENT). */
446247738Sbapt        struct {
447247738Sbapt            /** The anchor. */
448247738Sbapt            yaml_char_t *anchor;
449247738Sbapt            /** The tag. */
450247738Sbapt            yaml_char_t *tag;
451247738Sbapt            /** Is the tag optional? */
452247738Sbapt            int implicit;
453247738Sbapt            /** The sequence style. */
454247738Sbapt            yaml_sequence_style_t style;
455247738Sbapt        } sequence_start;
456247738Sbapt
457247738Sbapt        /** The mapping parameters (for @c YAML_MAPPING_START_EVENT). */
458247738Sbapt        struct {
459247738Sbapt            /** The anchor. */
460247738Sbapt            yaml_char_t *anchor;
461247738Sbapt            /** The tag. */
462247738Sbapt            yaml_char_t *tag;
463247738Sbapt            /** Is the tag optional? */
464247738Sbapt            int implicit;
465247738Sbapt            /** The mapping style. */
466247738Sbapt            yaml_mapping_style_t style;
467247738Sbapt        } mapping_start;
468247738Sbapt
469247738Sbapt    } data;
470247738Sbapt
471247738Sbapt    /** The beginning of the event. */
472247738Sbapt    yaml_mark_t start_mark;
473247738Sbapt    /** The end of the event. */
474247738Sbapt    yaml_mark_t end_mark;
475247738Sbapt
476247738Sbapt} yaml_event_t;
477247738Sbapt
478247738Sbapt/**
479247738Sbapt * Create the STREAM-START event.
480247738Sbapt *
481247738Sbapt * @param[out]      event       An empty event object.
482247738Sbapt * @param[in]       encoding    The stream encoding.
483247738Sbapt *
484247738Sbapt * @returns @c 1 if the function succeeded, @c 0 on error.
485247738Sbapt */
486247738Sbapt
487247738SbaptYAML_DECLARE(int)
488247738Sbaptyaml_stream_start_event_initialize(yaml_event_t *event,
489247738Sbapt        yaml_encoding_t encoding);
490247738Sbapt
491247738Sbapt/**
492247738Sbapt * Create the STREAM-END event.
493247738Sbapt *
494247738Sbapt * @param[out]      event       An empty event object.
495247738Sbapt *
496247738Sbapt * @returns @c 1 if the function succeeded, @c 0 on error.
497247738Sbapt */
498247738Sbapt
499247738SbaptYAML_DECLARE(int)
500247738Sbaptyaml_stream_end_event_initialize(yaml_event_t *event);
501247738Sbapt
502247738Sbapt/**
503247738Sbapt * Create the DOCUMENT-START event.
504247738Sbapt *
505247738Sbapt * The @a implicit argument is considered as a stylistic parameter and may be
506247738Sbapt * ignored by the emitter.
507247738Sbapt *
508247738Sbapt * @param[out]      event                   An empty event object.
509247738Sbapt * @param[in]       version_directive       The %YAML directive value or
510247738Sbapt *                                          @c NULL.
511247738Sbapt * @param[in]       tag_directives_start    The beginning of the %TAG
512247738Sbapt *                                          directives list.
513247738Sbapt * @param[in]       tag_directives_end      The end of the %TAG directives
514247738Sbapt *                                          list.
515247738Sbapt * @param[in]       implicit                If the document start indicator is
516247738Sbapt *                                          implicit.
517247738Sbapt *
518247738Sbapt * @returns @c 1 if the function succeeded, @c 0 on error.
519247738Sbapt */
520247738Sbapt
521247738SbaptYAML_DECLARE(int)
522247738Sbaptyaml_document_start_event_initialize(yaml_event_t *event,
523247738Sbapt        yaml_version_directive_t *version_directive,
524247738Sbapt        yaml_tag_directive_t *tag_directives_start,
525247738Sbapt        yaml_tag_directive_t *tag_directives_end,
526247738Sbapt        int implicit);
527247738Sbapt
528247738Sbapt/**
529247738Sbapt * Create the DOCUMENT-END event.
530247738Sbapt *
531247738Sbapt * The @a implicit argument is considered as a stylistic parameter and may be
532247738Sbapt * ignored by the emitter.
533247738Sbapt *
534247738Sbapt * @param[out]      event       An empty event object.
535247738Sbapt * @param[in]       implicit    If the document end indicator is implicit.
536247738Sbapt *
537247738Sbapt * @returns @c 1 if the function succeeded, @c 0 on error.
538247738Sbapt */
539247738Sbapt
540247738SbaptYAML_DECLARE(int)
541247738Sbaptyaml_document_end_event_initialize(yaml_event_t *event, int implicit);
542247738Sbapt
543247738Sbapt/**
544247738Sbapt * Create an ALIAS event.
545247738Sbapt *
546247738Sbapt * @param[out]      event       An empty event object.
547247738Sbapt * @param[in]       anchor      The anchor value.
548247738Sbapt *
549247738Sbapt * @returns @c 1 if the function succeeded, @c 0 on error.
550247738Sbapt */
551247738Sbapt
552247738SbaptYAML_DECLARE(int)
553247738Sbaptyaml_alias_event_initialize(yaml_event_t *event, yaml_char_t *anchor);
554247738Sbapt
555247738Sbapt/**
556247738Sbapt * Create a SCALAR event.
557247738Sbapt *
558247738Sbapt * The @a style argument may be ignored by the emitter.
559247738Sbapt *
560247738Sbapt * Either the @a tag attribute or one of the @a plain_implicit and
561247738Sbapt * @a quoted_implicit flags must be set.
562247738Sbapt *
563247738Sbapt * @param[out]      event           An empty event object.
564247738Sbapt * @param[in]       anchor          The scalar anchor or @c NULL.
565247738Sbapt * @param[in]       tag             The scalar tag or @c NULL.
566247738Sbapt * @param[in]       value           The scalar value.
567247738Sbapt * @param[in]       length          The length of the scalar value.
568247738Sbapt * @param[in]       plain_implicit  If the tag may be omitted for the plain
569247738Sbapt *                                  style.
570247738Sbapt * @param[in]       quoted_implicit If the tag may be omitted for any
571247738Sbapt *                                  non-plain style.
572247738Sbapt * @param[in]       style           The scalar style.
573247738Sbapt *
574247738Sbapt * @returns @c 1 if the function succeeded, @c 0 on error.
575247738Sbapt */
576247738Sbapt
577247738SbaptYAML_DECLARE(int)
578247738Sbaptyaml_scalar_event_initialize(yaml_event_t *event,
579247738Sbapt        yaml_char_t *anchor, yaml_char_t *tag,
580247738Sbapt        yaml_char_t *value, int length,
581247738Sbapt        int plain_implicit, int quoted_implicit,
582247738Sbapt        yaml_scalar_style_t style);
583247738Sbapt
584247738Sbapt/**
585247738Sbapt * Create a SEQUENCE-START event.
586247738Sbapt *
587247738Sbapt * The @a style argument may be ignored by the emitter.
588247738Sbapt *
589247738Sbapt * Either the @a tag attribute or the @a implicit flag must be set.
590247738Sbapt *
591247738Sbapt * @param[out]      event       An empty event object.
592247738Sbapt * @param[in]       anchor      The sequence anchor or @c NULL.
593247738Sbapt * @param[in]       tag         The sequence tag or @c NULL.
594247738Sbapt * @param[in]       implicit    If the tag may be omitted.
595247738Sbapt * @param[in]       style       The sequence style.
596247738Sbapt *
597247738Sbapt * @returns @c 1 if the function succeeded, @c 0 on error.
598247738Sbapt */
599247738Sbapt
600247738SbaptYAML_DECLARE(int)
601247738Sbaptyaml_sequence_start_event_initialize(yaml_event_t *event,
602247738Sbapt        yaml_char_t *anchor, yaml_char_t *tag, int implicit,
603247738Sbapt        yaml_sequence_style_t style);
604247738Sbapt
605247738Sbapt/**
606247738Sbapt * Create a SEQUENCE-END event.
607247738Sbapt *
608247738Sbapt * @param[out]      event       An empty event object.
609247738Sbapt *
610247738Sbapt * @returns @c 1 if the function succeeded, @c 0 on error.
611247738Sbapt */
612247738Sbapt
613247738SbaptYAML_DECLARE(int)
614247738Sbaptyaml_sequence_end_event_initialize(yaml_event_t *event);
615247738Sbapt
616247738Sbapt/**
617247738Sbapt * Create a MAPPING-START event.
618247738Sbapt *
619247738Sbapt * The @a style argument may be ignored by the emitter.
620247738Sbapt *
621247738Sbapt * Either the @a tag attribute or the @a implicit flag must be set.
622247738Sbapt *
623247738Sbapt * @param[out]      event       An empty event object.
624247738Sbapt * @param[in]       anchor      The mapping anchor or @c NULL.
625247738Sbapt * @param[in]       tag         The mapping tag or @c NULL.
626247738Sbapt * @param[in]       implicit    If the tag may be omitted.
627247738Sbapt * @param[in]       style       The mapping style.
628247738Sbapt *
629247738Sbapt * @returns @c 1 if the function succeeded, @c 0 on error.
630247738Sbapt */
631247738Sbapt
632247738SbaptYAML_DECLARE(int)
633247738Sbaptyaml_mapping_start_event_initialize(yaml_event_t *event,
634247738Sbapt        yaml_char_t *anchor, yaml_char_t *tag, int implicit,
635247738Sbapt        yaml_mapping_style_t style);
636247738Sbapt
637247738Sbapt/**
638247738Sbapt * Create a MAPPING-END event.
639247738Sbapt *
640247738Sbapt * @param[out]      event       An empty event object.
641247738Sbapt *
642247738Sbapt * @returns @c 1 if the function succeeded, @c 0 on error.
643247738Sbapt */
644247738Sbapt
645247738SbaptYAML_DECLARE(int)
646247738Sbaptyaml_mapping_end_event_initialize(yaml_event_t *event);
647247738Sbapt
648247738Sbapt/**
649247738Sbapt * Free any memory allocated for an event object.
650247738Sbapt *
651247738Sbapt * @param[in,out]   event   An event object.
652247738Sbapt */
653247738Sbapt
654247738SbaptYAML_DECLARE(void)
655247738Sbaptyaml_event_delete(yaml_event_t *event);
656247738Sbapt
657247738Sbapt/** @} */
658247738Sbapt
659247738Sbapt/**
660247738Sbapt * @defgroup nodes Nodes
661247738Sbapt * @{
662247738Sbapt */
663247738Sbapt
664247738Sbapt/** The tag @c !!null with the only possible value: @c null. */
665247738Sbapt#define YAML_NULL_TAG       "tag:yaml.org,2002:null"
666247738Sbapt/** The tag @c !!bool with the values: @c true and @c falce. */
667247738Sbapt#define YAML_BOOL_TAG       "tag:yaml.org,2002:bool"
668247738Sbapt/** The tag @c !!str for string values. */
669247738Sbapt#define YAML_STR_TAG        "tag:yaml.org,2002:str"
670247738Sbapt/** The tag @c !!int for integer values. */
671247738Sbapt#define YAML_INT_TAG        "tag:yaml.org,2002:int"
672247738Sbapt/** The tag @c !!float for float values. */
673247738Sbapt#define YAML_FLOAT_TAG      "tag:yaml.org,2002:float"
674247738Sbapt/** The tag @c !!timestamp for date and time values. */
675247738Sbapt#define YAML_TIMESTAMP_TAG  "tag:yaml.org,2002:timestamp"
676247738Sbapt
677247738Sbapt/** The tag @c !!seq is used to denote sequences. */
678247738Sbapt#define YAML_SEQ_TAG        "tag:yaml.org,2002:seq"
679247738Sbapt/** The tag @c !!map is used to denote mapping. */
680247738Sbapt#define YAML_MAP_TAG        "tag:yaml.org,2002:map"
681247738Sbapt
682247738Sbapt/** The default scalar tag is @c !!str. */
683247738Sbapt#define YAML_DEFAULT_SCALAR_TAG     YAML_STR_TAG
684247738Sbapt/** The default sequence tag is @c !!seq. */
685247738Sbapt#define YAML_DEFAULT_SEQUENCE_TAG   YAML_SEQ_TAG
686247738Sbapt/** The default mapping tag is @c !!map. */
687247738Sbapt#define YAML_DEFAULT_MAPPING_TAG    YAML_MAP_TAG
688247738Sbapt
689247738Sbapt/** Node types. */
690247738Sbapttypedef enum yaml_node_type_e {
691247738Sbapt    /** An empty node. */
692247738Sbapt    YAML_NO_NODE,
693247738Sbapt
694247738Sbapt    /** A scalar node. */
695247738Sbapt    YAML_SCALAR_NODE,
696247738Sbapt    /** A sequence node. */
697247738Sbapt    YAML_SEQUENCE_NODE,
698247738Sbapt    /** A mapping node. */
699247738Sbapt    YAML_MAPPING_NODE
700247738Sbapt} yaml_node_type_t;
701247738Sbapt
702247738Sbapt/** The forward definition of a document node structure. */
703247738Sbapttypedef struct yaml_node_s yaml_node_t;
704247738Sbapt
705247738Sbapt/** An element of a sequence node. */
706247738Sbapttypedef int yaml_node_item_t;
707247738Sbapt
708247738Sbapt/** An element of a mapping node. */
709247738Sbapttypedef struct yaml_node_pair_s {
710247738Sbapt    /** The key of the element. */
711247738Sbapt    int key;
712247738Sbapt    /** The value of the element. */
713247738Sbapt    int value;
714247738Sbapt} yaml_node_pair_t;
715247738Sbapt
716247738Sbapt/** The node structure. */
717247738Sbaptstruct yaml_node_s {
718247738Sbapt
719247738Sbapt    /** The node type. */
720247738Sbapt    yaml_node_type_t type;
721247738Sbapt
722247738Sbapt    /** The node tag. */
723247738Sbapt    yaml_char_t *tag;
724247738Sbapt
725247738Sbapt    /** The node data. */
726247738Sbapt    union {
727247738Sbapt
728247738Sbapt        /** The scalar parameters (for @c YAML_SCALAR_NODE). */
729247738Sbapt        struct {
730247738Sbapt            /** The scalar value. */
731247738Sbapt            yaml_char_t *value;
732247738Sbapt            /** The length of the scalar value. */
733247738Sbapt            size_t length;
734247738Sbapt            /** The scalar style. */
735247738Sbapt            yaml_scalar_style_t style;
736247738Sbapt        } scalar;
737247738Sbapt
738247738Sbapt        /** The sequence parameters (for @c YAML_SEQUENCE_NODE). */
739247738Sbapt        struct {
740247738Sbapt            /** The stack of sequence items. */
741247738Sbapt            struct {
742247738Sbapt                /** The beginning of the stack. */
743247738Sbapt                yaml_node_item_t *start;
744247738Sbapt                /** The end of the stack. */
745247738Sbapt                yaml_node_item_t *end;
746247738Sbapt                /** The top of the stack. */
747247738Sbapt                yaml_node_item_t *top;
748247738Sbapt            } items;
749247738Sbapt            /** The sequence style. */
750247738Sbapt            yaml_sequence_style_t style;
751247738Sbapt        } sequence;
752247738Sbapt
753247738Sbapt        /** The mapping parameters (for @c YAML_MAPPING_NODE). */
754247738Sbapt        struct {
755247738Sbapt            /** The stack of mapping pairs (key, value). */
756247738Sbapt            struct {
757247738Sbapt                /** The beginning of the stack. */
758247738Sbapt                yaml_node_pair_t *start;
759247738Sbapt                /** The end of the stack. */
760247738Sbapt                yaml_node_pair_t *end;
761247738Sbapt                /** The top of the stack. */
762247738Sbapt                yaml_node_pair_t *top;
763247738Sbapt            } pairs;
764247738Sbapt            /** The mapping style. */
765247738Sbapt            yaml_mapping_style_t style;
766247738Sbapt        } mapping;
767247738Sbapt
768247738Sbapt    } data;
769247738Sbapt
770247738Sbapt    /** The beginning of the node. */
771247738Sbapt    yaml_mark_t start_mark;
772247738Sbapt    /** The end of the node. */
773247738Sbapt    yaml_mark_t end_mark;
774247738Sbapt
775247738Sbapt};
776247738Sbapt
777247738Sbapt/** The document structure. */
778247738Sbapttypedef struct yaml_document_s {
779247738Sbapt
780247738Sbapt    /** The document nodes. */
781247738Sbapt    struct {
782247738Sbapt        /** The beginning of the stack. */
783247738Sbapt        yaml_node_t *start;
784247738Sbapt        /** The end of the stack. */
785247738Sbapt        yaml_node_t *end;
786247738Sbapt        /** The top of the stack. */
787247738Sbapt        yaml_node_t *top;
788247738Sbapt    } nodes;
789247738Sbapt
790247738Sbapt    /** The version directive. */
791247738Sbapt    yaml_version_directive_t *version_directive;
792247738Sbapt
793247738Sbapt    /** The list of tag directives. */
794247738Sbapt    struct {
795247738Sbapt        /** The beginning of the tag directives list. */
796247738Sbapt        yaml_tag_directive_t *start;
797247738Sbapt        /** The end of the tag directives list. */
798247738Sbapt        yaml_tag_directive_t *end;
799247738Sbapt    } tag_directives;
800247738Sbapt
801247738Sbapt    /** Is the document start indicator implicit? */
802247738Sbapt    int start_implicit;
803247738Sbapt    /** Is the document end indicator implicit? */
804247738Sbapt    int end_implicit;
805247738Sbapt
806247738Sbapt    /** The beginning of the document. */
807247738Sbapt    yaml_mark_t start_mark;
808247738Sbapt    /** The end of the document. */
809247738Sbapt    yaml_mark_t end_mark;
810247738Sbapt
811247738Sbapt} yaml_document_t;
812247738Sbapt
813247738Sbapt/**
814247738Sbapt * Create a YAML document.
815247738Sbapt *
816247738Sbapt * @param[out]      document                An empty document object.
817247738Sbapt * @param[in]       version_directive       The %YAML directive value or
818247738Sbapt *                                          @c NULL.
819247738Sbapt * @param[in]       tag_directives_start    The beginning of the %TAG
820247738Sbapt *                                          directives list.
821247738Sbapt * @param[in]       tag_directives_end      The end of the %TAG directives
822247738Sbapt *                                          list.
823247738Sbapt * @param[in]       start_implicit          If the document start indicator is
824247738Sbapt *                                          implicit.
825247738Sbapt * @param[in]       end_implicit            If the document end indicator is
826247738Sbapt *                                          implicit.
827247738Sbapt *
828247738Sbapt * @returns @c 1 if the function succeeded, @c 0 on error.
829247738Sbapt */
830247738Sbapt
831247738SbaptYAML_DECLARE(int)
832247738Sbaptyaml_document_initialize(yaml_document_t *document,
833247738Sbapt        yaml_version_directive_t *version_directive,
834247738Sbapt        yaml_tag_directive_t *tag_directives_start,
835247738Sbapt        yaml_tag_directive_t *tag_directives_end,
836247738Sbapt        int start_implicit, int end_implicit);
837247738Sbapt
838247738Sbapt/**
839247738Sbapt * Delete a YAML document and all its nodes.
840247738Sbapt *
841247738Sbapt * @param[in,out]   document        A document object.
842247738Sbapt */
843247738Sbapt
844247738SbaptYAML_DECLARE(void)
845247738Sbaptyaml_document_delete(yaml_document_t *document);
846247738Sbapt
847247738Sbapt/**
848247738Sbapt * Get a node of a YAML document.
849247738Sbapt *
850247738Sbapt * The pointer returned by this function is valid until any of the functions
851247738Sbapt * modifying the documents are called.
852247738Sbapt *
853247738Sbapt * @param[in]       document        A document object.
854247738Sbapt * @param[in]       index           The node id.
855247738Sbapt *
856247738Sbapt * @returns the node objct or @c NULL if @c node_id is out of range.
857247738Sbapt */
858247738Sbapt
859247738SbaptYAML_DECLARE(yaml_node_t *)
860247738Sbaptyaml_document_get_node(yaml_document_t *document, int index);
861247738Sbapt
862247738Sbapt/**
863247738Sbapt * Get the root of a YAML document node.
864247738Sbapt *
865247738Sbapt * The root object is the first object added to the document.
866247738Sbapt *
867247738Sbapt * The pointer returned by this function is valid until any of the functions
868247738Sbapt * modifying the documents are called.
869247738Sbapt *
870247738Sbapt * An empty document produced by the parser signifies the end of a YAML
871247738Sbapt * stream.
872247738Sbapt *
873247738Sbapt * @param[in]       document        A document object.
874247738Sbapt *
875247738Sbapt * @returns the node object or @c NULL if the document is empty.
876247738Sbapt */
877247738Sbapt
878247738SbaptYAML_DECLARE(yaml_node_t *)
879247738Sbaptyaml_document_get_root_node(yaml_document_t *document);
880247738Sbapt
881247738Sbapt/**
882247738Sbapt * Create a SCALAR node and attach it to the document.
883247738Sbapt *
884247738Sbapt * The @a style argument may be ignored by the emitter.
885247738Sbapt *
886247738Sbapt * @param[in,out]   document        A document object.
887247738Sbapt * @param[in]       tag             The scalar tag.
888247738Sbapt * @param[in]       value           The scalar value.
889247738Sbapt * @param[in]       length          The length of the scalar value.
890247738Sbapt * @param[in]       style           The scalar style.
891247738Sbapt *
892247738Sbapt * @returns the node id or @c 0 on error.
893247738Sbapt */
894247738Sbapt
895247738SbaptYAML_DECLARE(int)
896247738Sbaptyaml_document_add_scalar(yaml_document_t *document,
897247738Sbapt        yaml_char_t *tag, yaml_char_t *value, int length,
898247738Sbapt        yaml_scalar_style_t style);
899247738Sbapt
900247738Sbapt/**
901247738Sbapt * Create a SEQUENCE node and attach it to the document.
902247738Sbapt *
903247738Sbapt * The @a style argument may be ignored by the emitter.
904247738Sbapt *
905247738Sbapt * @param[in,out]   document    A document object.
906247738Sbapt * @param[in]       tag         The sequence tag.
907247738Sbapt * @param[in]       style       The sequence style.
908247738Sbapt *
909247738Sbapt * @returns the node id or @c 0 on error.
910247738Sbapt */
911247738Sbapt
912247738SbaptYAML_DECLARE(int)
913247738Sbaptyaml_document_add_sequence(yaml_document_t *document,
914247738Sbapt        yaml_char_t *tag, yaml_sequence_style_t style);
915247738Sbapt
916247738Sbapt/**
917247738Sbapt * Create a MAPPING node and attach it to the document.
918247738Sbapt *
919247738Sbapt * The @a style argument may be ignored by the emitter.
920247738Sbapt *
921247738Sbapt * @param[in,out]   document    A document object.
922247738Sbapt * @param[in]       tag         The sequence tag.
923247738Sbapt * @param[in]       style       The sequence style.
924247738Sbapt *
925247738Sbapt * @returns the node id or @c 0 on error.
926247738Sbapt */
927247738Sbapt
928247738SbaptYAML_DECLARE(int)
929247738Sbaptyaml_document_add_mapping(yaml_document_t *document,
930247738Sbapt        yaml_char_t *tag, yaml_mapping_style_t style);
931247738Sbapt
932247738Sbapt/**
933247738Sbapt * Add an item to a SEQUENCE node.
934247738Sbapt *
935247738Sbapt * @param[in,out]   document    A document object.
936247738Sbapt * @param[in]       sequence    The sequence node id.
937247738Sbapt * @param[in]       item        The item node id.
938247738Sbapt*
939247738Sbapt * @returns @c 1 if the function succeeded, @c 0 on error.
940247738Sbapt */
941247738Sbapt
942247738SbaptYAML_DECLARE(int)
943247738Sbaptyaml_document_append_sequence_item(yaml_document_t *document,
944247738Sbapt        int sequence, int item);
945247738Sbapt
946247738Sbapt/**
947247738Sbapt * Add a pair of a key and a value to a MAPPING node.
948247738Sbapt *
949247738Sbapt * @param[in,out]   document    A document object.
950247738Sbapt * @param[in]       mapping     The mapping node id.
951247738Sbapt * @param[in]       key         The key node id.
952247738Sbapt * @param[in]       value       The value node id.
953247738Sbapt*
954247738Sbapt * @returns @c 1 if the function succeeded, @c 0 on error.
955247738Sbapt */
956247738Sbapt
957247738SbaptYAML_DECLARE(int)
958247738Sbaptyaml_document_append_mapping_pair(yaml_document_t *document,
959247738Sbapt        int mapping, int key, int value);
960247738Sbapt
961247738Sbapt/** @} */
962247738Sbapt
963247738Sbapt/**
964247738Sbapt * @defgroup parser Parser Definitions
965247738Sbapt * @{
966247738Sbapt */
967247738Sbapt
968247738Sbapt/**
969247738Sbapt * The prototype of a read handler.
970247738Sbapt *
971247738Sbapt * The read handler is called when the parser needs to read more bytes from the
972247738Sbapt * source.  The handler should write not more than @a size bytes to the @a
973247738Sbapt * buffer.  The number of written bytes should be set to the @a length variable.
974247738Sbapt *
975247738Sbapt * @param[in,out]   data        A pointer to an application data specified by
976247738Sbapt *                              yaml_parser_set_input().
977247738Sbapt * @param[out]      buffer      The buffer to write the data from the source.
978247738Sbapt * @param[in]       size        The size of the buffer.
979247738Sbapt * @param[out]      size_read   The actual number of bytes read from the source.
980247738Sbapt *
981247738Sbapt * @returns On success, the handler should return @c 1.  If the handler failed,
982247738Sbapt * the returned value should be @c 0.  On EOF, the handler should set the
983247738Sbapt * @a size_read to @c 0 and return @c 1.
984247738Sbapt */
985247738Sbapt
986247738Sbapttypedef int yaml_read_handler_t(void *data, unsigned char *buffer, size_t size,
987247738Sbapt        size_t *size_read);
988247738Sbapt
989247738Sbapt/**
990247738Sbapt * This structure holds information about a potential simple key.
991247738Sbapt */
992247738Sbapt
993247738Sbapttypedef struct yaml_simple_key_s {
994247738Sbapt    /** Is a simple key possible? */
995247738Sbapt    int possible;
996247738Sbapt
997247738Sbapt    /** Is a simple key required? */
998247738Sbapt    int required;
999247738Sbapt
1000247738Sbapt    /** The number of the token. */
1001247738Sbapt    size_t token_number;
1002247738Sbapt
1003247738Sbapt    /** The position mark. */
1004247738Sbapt    yaml_mark_t mark;
1005247738Sbapt} yaml_simple_key_t;
1006247738Sbapt
1007247738Sbapt/**
1008247738Sbapt * The states of the parser.
1009247738Sbapt */
1010247738Sbapttypedef enum yaml_parser_state_e {
1011247738Sbapt    /** Expect STREAM-START. */
1012247738Sbapt    YAML_PARSE_STREAM_START_STATE,
1013247738Sbapt    /** Expect the beginning of an implicit document. */
1014247738Sbapt    YAML_PARSE_IMPLICIT_DOCUMENT_START_STATE,
1015247738Sbapt    /** Expect DOCUMENT-START. */
1016247738Sbapt    YAML_PARSE_DOCUMENT_START_STATE,
1017247738Sbapt    /** Expect the content of a document. */
1018247738Sbapt    YAML_PARSE_DOCUMENT_CONTENT_STATE,
1019247738Sbapt    /** Expect DOCUMENT-END. */
1020247738Sbapt    YAML_PARSE_DOCUMENT_END_STATE,
1021247738Sbapt    /** Expect a block node. */
1022247738Sbapt    YAML_PARSE_BLOCK_NODE_STATE,
1023247738Sbapt    /** Expect a block node or indentless sequence. */
1024247738Sbapt    YAML_PARSE_BLOCK_NODE_OR_INDENTLESS_SEQUENCE_STATE,
1025247738Sbapt    /** Expect a flow node. */
1026247738Sbapt    YAML_PARSE_FLOW_NODE_STATE,
1027247738Sbapt    /** Expect the first entry of a block sequence. */
1028247738Sbapt    YAML_PARSE_BLOCK_SEQUENCE_FIRST_ENTRY_STATE,
1029247738Sbapt    /** Expect an entry of a block sequence. */
1030247738Sbapt    YAML_PARSE_BLOCK_SEQUENCE_ENTRY_STATE,
1031247738Sbapt    /** Expect an entry of an indentless sequence. */
1032247738Sbapt    YAML_PARSE_INDENTLESS_SEQUENCE_ENTRY_STATE,
1033247738Sbapt    /** Expect the first key of a block mapping. */
1034247738Sbapt    YAML_PARSE_BLOCK_MAPPING_FIRST_KEY_STATE,
1035247738Sbapt    /** Expect a block mapping key. */
1036247738Sbapt    YAML_PARSE_BLOCK_MAPPING_KEY_STATE,
1037247738Sbapt    /** Expect a block mapping value. */
1038247738Sbapt    YAML_PARSE_BLOCK_MAPPING_VALUE_STATE,
1039247738Sbapt    /** Expect the first entry of a flow sequence. */
1040247738Sbapt    YAML_PARSE_FLOW_SEQUENCE_FIRST_ENTRY_STATE,
1041247738Sbapt    /** Expect an entry of a flow sequence. */
1042247738Sbapt    YAML_PARSE_FLOW_SEQUENCE_ENTRY_STATE,
1043247738Sbapt    /** Expect a key of an ordered mapping. */
1044247738Sbapt    YAML_PARSE_FLOW_SEQUENCE_ENTRY_MAPPING_KEY_STATE,
1045247738Sbapt    /** Expect a value of an ordered mapping. */
1046247738Sbapt    YAML_PARSE_FLOW_SEQUENCE_ENTRY_MAPPING_VALUE_STATE,
1047247738Sbapt    /** Expect the and of an ordered mapping entry. */
1048247738Sbapt    YAML_PARSE_FLOW_SEQUENCE_ENTRY_MAPPING_END_STATE,
1049247738Sbapt    /** Expect the first key of a flow mapping. */
1050247738Sbapt    YAML_PARSE_FLOW_MAPPING_FIRST_KEY_STATE,
1051247738Sbapt    /** Expect a key of a flow mapping. */
1052247738Sbapt    YAML_PARSE_FLOW_MAPPING_KEY_STATE,
1053247738Sbapt    /** Expect a value of a flow mapping. */
1054247738Sbapt    YAML_PARSE_FLOW_MAPPING_VALUE_STATE,
1055247738Sbapt    /** Expect an empty value of a flow mapping. */
1056247738Sbapt    YAML_PARSE_FLOW_MAPPING_EMPTY_VALUE_STATE,
1057247738Sbapt    /** Expect nothing. */
1058247738Sbapt    YAML_PARSE_END_STATE
1059247738Sbapt} yaml_parser_state_t;
1060247738Sbapt
1061247738Sbapt/**
1062247738Sbapt * This structure holds aliases data.
1063247738Sbapt */
1064247738Sbapt
1065247738Sbapttypedef struct yaml_alias_data_s {
1066247738Sbapt    /** The anchor. */
1067247738Sbapt    yaml_char_t *anchor;
1068247738Sbapt    /** The node id. */
1069247738Sbapt    int index;
1070247738Sbapt    /** The anchor mark. */
1071247738Sbapt    yaml_mark_t mark;
1072247738Sbapt} yaml_alias_data_t;
1073247738Sbapt
1074247738Sbapt/**
1075247738Sbapt * The parser structure.
1076247738Sbapt *
1077247738Sbapt * All members are internal.  Manage the structure using the @c yaml_parser_
1078247738Sbapt * family of functions.
1079247738Sbapt */
1080247738Sbapt
1081247738Sbapttypedef struct yaml_parser_s {
1082247738Sbapt
1083247738Sbapt    /**
1084247738Sbapt     * @name Error handling
1085247738Sbapt     * @{
1086247738Sbapt     */
1087247738Sbapt
1088247738Sbapt    /** Error type. */
1089247738Sbapt    yaml_error_type_t error;
1090247738Sbapt    /** Error description. */
1091247738Sbapt    const char *problem;
1092247738Sbapt    /** The byte about which the problem occured. */
1093247738Sbapt    size_t problem_offset;
1094247738Sbapt    /** The problematic value (@c -1 is none). */
1095247738Sbapt    int problem_value;
1096247738Sbapt    /** The problem position. */
1097247738Sbapt    yaml_mark_t problem_mark;
1098247738Sbapt    /** The error context. */
1099247738Sbapt    const char *context;
1100247738Sbapt    /** The context position. */
1101247738Sbapt    yaml_mark_t context_mark;
1102247738Sbapt
1103247738Sbapt    /**
1104247738Sbapt     * @}
1105247738Sbapt     */
1106247738Sbapt
1107247738Sbapt    /**
1108247738Sbapt     * @name Reader stuff
1109247738Sbapt     * @{
1110247738Sbapt     */
1111247738Sbapt
1112247738Sbapt    /** Read handler. */
1113247738Sbapt    yaml_read_handler_t *read_handler;
1114247738Sbapt
1115247738Sbapt    /** A pointer for passing to the read handler. */
1116247738Sbapt    void *read_handler_data;
1117247738Sbapt
1118247738Sbapt    /** Standard (string or file) input data. */
1119247738Sbapt    union {
1120247738Sbapt        /** String input data. */
1121247738Sbapt        struct {
1122247738Sbapt            /** The string start pointer. */
1123247738Sbapt            const unsigned char *start;
1124247738Sbapt            /** The string end pointer. */
1125247738Sbapt            const unsigned char *end;
1126247738Sbapt            /** The string current position. */
1127247738Sbapt            const unsigned char *current;
1128247738Sbapt        } string;
1129247738Sbapt
1130247738Sbapt        /** File input data. */
1131247738Sbapt        FILE *file;
1132247738Sbapt    } input;
1133247738Sbapt
1134247738Sbapt    /** EOF flag */
1135247738Sbapt    int eof;
1136247738Sbapt
1137247738Sbapt    /** The working buffer. */
1138247738Sbapt    struct {
1139247738Sbapt        /** The beginning of the buffer. */
1140247738Sbapt        yaml_char_t *start;
1141247738Sbapt        /** The end of the buffer. */
1142247738Sbapt        yaml_char_t *end;
1143247738Sbapt        /** The current position of the buffer. */
1144247738Sbapt        yaml_char_t *pointer;
1145247738Sbapt        /** The last filled position of the buffer. */
1146247738Sbapt        yaml_char_t *last;
1147247738Sbapt    } buffer;
1148247738Sbapt
1149247738Sbapt    /* The number of unread characters in the buffer. */
1150247738Sbapt    size_t unread;
1151247738Sbapt
1152247738Sbapt    /** The raw buffer. */
1153247738Sbapt    struct {
1154247738Sbapt        /** The beginning of the buffer. */
1155247738Sbapt        unsigned char *start;
1156247738Sbapt        /** The end of the buffer. */
1157247738Sbapt        unsigned char *end;
1158247738Sbapt        /** The current position of the buffer. */
1159247738Sbapt        unsigned char *pointer;
1160247738Sbapt        /** The last filled position of the buffer. */
1161247738Sbapt        unsigned char *last;
1162247738Sbapt    } raw_buffer;
1163247738Sbapt
1164247738Sbapt    /** The input encoding. */
1165247738Sbapt    yaml_encoding_t encoding;
1166247738Sbapt
1167247738Sbapt    /** The offset of the current position (in bytes). */
1168247738Sbapt    size_t offset;
1169247738Sbapt
1170247738Sbapt    /** The mark of the current position. */
1171247738Sbapt    yaml_mark_t mark;
1172247738Sbapt
1173247738Sbapt    /**
1174247738Sbapt     * @}
1175247738Sbapt     */
1176247738Sbapt
1177247738Sbapt    /**
1178247738Sbapt     * @name Scanner stuff
1179247738Sbapt     * @{
1180247738Sbapt     */
1181247738Sbapt
1182247738Sbapt    /** Have we started to scan the input stream? */
1183247738Sbapt    int stream_start_produced;
1184247738Sbapt
1185247738Sbapt    /** Have we reached the end of the input stream? */
1186247738Sbapt    int stream_end_produced;
1187247738Sbapt
1188247738Sbapt    /** The number of unclosed '[' and '{' indicators. */
1189247738Sbapt    int flow_level;
1190247738Sbapt
1191247738Sbapt    /** The tokens queue. */
1192247738Sbapt    struct {
1193247738Sbapt        /** The beginning of the tokens queue. */
1194247738Sbapt        yaml_token_t *start;
1195247738Sbapt        /** The end of the tokens queue. */
1196247738Sbapt        yaml_token_t *end;
1197247738Sbapt        /** The head of the tokens queue. */
1198247738Sbapt        yaml_token_t *head;
1199247738Sbapt        /** The tail of the tokens queue. */
1200247738Sbapt        yaml_token_t *tail;
1201247738Sbapt    } tokens;
1202247738Sbapt
1203247738Sbapt    /** The number of tokens fetched from the queue. */
1204247738Sbapt    size_t tokens_parsed;
1205247738Sbapt
1206247738Sbapt    /* Does the tokens queue contain a token ready for dequeueing. */
1207247738Sbapt    int token_available;
1208247738Sbapt
1209247738Sbapt    /** The indentation levels stack. */
1210247738Sbapt    struct {
1211247738Sbapt        /** The beginning of the stack. */
1212247738Sbapt        int *start;
1213247738Sbapt        /** The end of the stack. */
1214247738Sbapt        int *end;
1215247738Sbapt        /** The top of the stack. */
1216247738Sbapt        int *top;
1217247738Sbapt    } indents;
1218247738Sbapt
1219247738Sbapt    /** The current indentation level. */
1220247738Sbapt    int indent;
1221247738Sbapt
1222247738Sbapt    /** May a simple key occur at the current position? */
1223247738Sbapt    int simple_key_allowed;
1224247738Sbapt
1225247738Sbapt    /** The stack of simple keys. */
1226247738Sbapt    struct {
1227247738Sbapt        /** The beginning of the stack. */
1228247738Sbapt        yaml_simple_key_t *start;
1229247738Sbapt        /** The end of the stack. */
1230247738Sbapt        yaml_simple_key_t *end;
1231247738Sbapt        /** The top of the stack. */
1232247738Sbapt        yaml_simple_key_t *top;
1233247738Sbapt    } simple_keys;
1234247738Sbapt
1235247738Sbapt    /**
1236247738Sbapt     * @}
1237247738Sbapt     */
1238247738Sbapt
1239247738Sbapt    /**
1240247738Sbapt     * @name Parser stuff
1241247738Sbapt     * @{
1242247738Sbapt     */
1243247738Sbapt
1244247738Sbapt    /** The parser states stack. */
1245247738Sbapt    struct {
1246247738Sbapt        /** The beginning of the stack. */
1247247738Sbapt        yaml_parser_state_t *start;
1248247738Sbapt        /** The end of the stack. */
1249247738Sbapt        yaml_parser_state_t *end;
1250247738Sbapt        /** The top of the stack. */
1251247738Sbapt        yaml_parser_state_t *top;
1252247738Sbapt    } states;
1253247738Sbapt
1254247738Sbapt    /** The current parser state. */
1255247738Sbapt    yaml_parser_state_t state;
1256247738Sbapt
1257247738Sbapt    /** The stack of marks. */
1258247738Sbapt    struct {
1259247738Sbapt        /** The beginning of the stack. */
1260247738Sbapt        yaml_mark_t *start;
1261247738Sbapt        /** The end of the stack. */
1262247738Sbapt        yaml_mark_t *end;
1263247738Sbapt        /** The top of the stack. */
1264247738Sbapt        yaml_mark_t *top;
1265247738Sbapt    } marks;
1266247738Sbapt
1267247738Sbapt    /** The list of TAG directives. */
1268247738Sbapt    struct {
1269247738Sbapt        /** The beginning of the list. */
1270247738Sbapt        yaml_tag_directive_t *start;
1271247738Sbapt        /** The end of the list. */
1272247738Sbapt        yaml_tag_directive_t *end;
1273247738Sbapt        /** The top of the list. */
1274247738Sbapt        yaml_tag_directive_t *top;
1275247738Sbapt    } tag_directives;
1276247738Sbapt
1277247738Sbapt    /**
1278247738Sbapt     * @}
1279247738Sbapt     */
1280247738Sbapt
1281247738Sbapt    /**
1282247738Sbapt     * @name Dumper stuff
1283247738Sbapt     * @{
1284247738Sbapt     */
1285247738Sbapt
1286247738Sbapt    /** The alias data. */
1287247738Sbapt    struct {
1288247738Sbapt        /** The beginning of the list. */
1289247738Sbapt        yaml_alias_data_t *start;
1290247738Sbapt        /** The end of the list. */
1291247738Sbapt        yaml_alias_data_t *end;
1292247738Sbapt        /** The top of the list. */
1293247738Sbapt        yaml_alias_data_t *top;
1294247738Sbapt    } aliases;
1295247738Sbapt
1296247738Sbapt    /** The currently parsed document. */
1297247738Sbapt    yaml_document_t *document;
1298247738Sbapt
1299247738Sbapt    /**
1300247738Sbapt     * @}
1301247738Sbapt     */
1302247738Sbapt
1303247738Sbapt} yaml_parser_t;
1304247738Sbapt
1305247738Sbapt/**
1306247738Sbapt * Initialize a parser.
1307247738Sbapt *
1308247738Sbapt * This function creates a new parser object.  An application is responsible
1309247738Sbapt * for destroying the object using the yaml_parser_delete() function.
1310247738Sbapt *
1311247738Sbapt * @param[out]      parser  An empty parser object.
1312247738Sbapt *
1313247738Sbapt * @returns @c 1 if the function succeeded, @c 0 on error.
1314247738Sbapt */
1315247738Sbapt
1316247738SbaptYAML_DECLARE(int)
1317247738Sbaptyaml_parser_initialize(yaml_parser_t *parser);
1318247738Sbapt
1319247738Sbapt/**
1320247738Sbapt * Destroy a parser.
1321247738Sbapt *
1322247738Sbapt * @param[in,out]   parser  A parser object.
1323247738Sbapt */
1324247738Sbapt
1325247738SbaptYAML_DECLARE(void)
1326247738Sbaptyaml_parser_delete(yaml_parser_t *parser);
1327247738Sbapt
1328247738Sbapt/**
1329247738Sbapt * Set a string input.
1330247738Sbapt *
1331247738Sbapt * Note that the @a input pointer must be valid while the @a parser object
1332247738Sbapt * exists.  The application is responsible for destroing @a input after
1333247738Sbapt * destroying the @a parser.
1334247738Sbapt *
1335247738Sbapt * @param[in,out]   parser  A parser object.
1336247738Sbapt * @param[in]       input   A source data.
1337247738Sbapt * @param[in]       size    The length of the source data in bytes.
1338247738Sbapt */
1339247738Sbapt
1340247738SbaptYAML_DECLARE(void)
1341247738Sbaptyaml_parser_set_input_string(yaml_parser_t *parser,
1342247738Sbapt        const unsigned char *input, size_t size);
1343247738Sbapt
1344247738Sbapt/**
1345247738Sbapt * Set a file input.
1346247738Sbapt *
1347247738Sbapt * @a file should be a file object open for reading.  The application is
1348247738Sbapt * responsible for closing the @a file.
1349247738Sbapt *
1350247738Sbapt * @param[in,out]   parser  A parser object.
1351247738Sbapt * @param[in]       file    An open file.
1352247738Sbapt */
1353247738Sbapt
1354247738SbaptYAML_DECLARE(void)
1355247738Sbaptyaml_parser_set_input_file(yaml_parser_t *parser, FILE *file);
1356247738Sbapt
1357247738Sbapt/**
1358247738Sbapt * Set a generic input handler.
1359247738Sbapt *
1360247738Sbapt * @param[in,out]   parser  A parser object.
1361247738Sbapt * @param[in]       handler A read handler.
1362247738Sbapt * @param[in]       data    Any application data for passing to the read
1363247738Sbapt *                          handler.
1364247738Sbapt */
1365247738Sbapt
1366247738SbaptYAML_DECLARE(void)
1367247738Sbaptyaml_parser_set_input(yaml_parser_t *parser,
1368247738Sbapt        yaml_read_handler_t *handler, void *data);
1369247738Sbapt
1370247738Sbapt/**
1371247738Sbapt * Set the source encoding.
1372247738Sbapt *
1373247738Sbapt * @param[in,out]   parser      A parser object.
1374247738Sbapt * @param[in]       encoding    The source encoding.
1375247738Sbapt */
1376247738Sbapt
1377247738SbaptYAML_DECLARE(void)
1378247738Sbaptyaml_parser_set_encoding(yaml_parser_t *parser, yaml_encoding_t encoding);
1379247738Sbapt
1380247738Sbapt/**
1381247738Sbapt * Scan the input stream and produce the next token.
1382247738Sbapt *
1383247738Sbapt * Call the function subsequently to produce a sequence of tokens corresponding
1384247738Sbapt * to the input stream.  The initial token has the type
1385247738Sbapt * @c YAML_STREAM_START_TOKEN while the ending token has the type
1386247738Sbapt * @c YAML_STREAM_END_TOKEN.
1387247738Sbapt *
1388247738Sbapt * An application is responsible for freeing any buffers associated with the
1389247738Sbapt * produced token object using the @c yaml_token_delete function.
1390247738Sbapt *
1391247738Sbapt * An application must not alternate the calls of yaml_parser_scan() with the
1392247738Sbapt * calls of yaml_parser_parse() or yaml_parser_load(). Doing this will break
1393247738Sbapt * the parser.
1394247738Sbapt *
1395247738Sbapt * @param[in,out]   parser      A parser object.
1396247738Sbapt * @param[out]      token       An empty token object.
1397247738Sbapt *
1398247738Sbapt * @returns @c 1 if the function succeeded, @c 0 on error.
1399247738Sbapt */
1400247738Sbapt
1401247738SbaptYAML_DECLARE(int)
1402247738Sbaptyaml_parser_scan(yaml_parser_t *parser, yaml_token_t *token);
1403247738Sbapt
1404247738Sbapt/**
1405247738Sbapt * Parse the input stream and produce the next parsing event.
1406247738Sbapt *
1407247738Sbapt * Call the function subsequently to produce a sequence of events corresponding
1408247738Sbapt * to the input stream.  The initial event has the type
1409247738Sbapt * @c YAML_STREAM_START_EVENT while the ending event has the type
1410247738Sbapt * @c YAML_STREAM_END_EVENT.
1411247738Sbapt *
1412247738Sbapt * An application is responsible for freeing any buffers associated with the
1413247738Sbapt * produced event object using the yaml_event_delete() function.
1414247738Sbapt *
1415247738Sbapt * An application must not alternate the calls of yaml_parser_parse() with the
1416247738Sbapt * calls of yaml_parser_scan() or yaml_parser_load(). Doing this will break the
1417247738Sbapt * parser.
1418247738Sbapt *
1419247738Sbapt * @param[in,out]   parser      A parser object.
1420247738Sbapt * @param[out]      event       An empty event object.
1421247738Sbapt *
1422247738Sbapt * @returns @c 1 if the function succeeded, @c 0 on error.
1423247738Sbapt */
1424247738Sbapt
1425247738SbaptYAML_DECLARE(int)
1426247738Sbaptyaml_parser_parse(yaml_parser_t *parser, yaml_event_t *event);
1427247738Sbapt
1428247738Sbapt/**
1429247738Sbapt * Parse the input stream and produce the next YAML document.
1430247738Sbapt *
1431247738Sbapt * Call this function subsequently to produce a sequence of documents
1432247738Sbapt * constituting the input stream.
1433247738Sbapt *
1434247738Sbapt * If the produced document has no root node, it means that the document
1435247738Sbapt * end has been reached.
1436247738Sbapt *
1437247738Sbapt * An application is responsible for freeing any data associated with the
1438247738Sbapt * produced document object using the yaml_document_delete() function.
1439247738Sbapt *
1440247738Sbapt * An application must not alternate the calls of yaml_parser_load() with the
1441247738Sbapt * calls of yaml_parser_scan() or yaml_parser_parse(). Doing this will break
1442247738Sbapt * the parser.
1443247738Sbapt *
1444247738Sbapt * @param[in,out]   parser      A parser object.
1445247738Sbapt * @param[out]      document    An empty document object.
1446247738Sbapt *
1447247738Sbapt * @return @c 1 if the function succeeded, @c 0 on error.
1448247738Sbapt */
1449247738Sbapt
1450247738SbaptYAML_DECLARE(int)
1451247738Sbaptyaml_parser_load(yaml_parser_t *parser, yaml_document_t *document);
1452247738Sbapt
1453247738Sbapt/** @} */
1454247738Sbapt
1455247738Sbapt/**
1456247738Sbapt * @defgroup emitter Emitter Definitions
1457247738Sbapt * @{
1458247738Sbapt */
1459247738Sbapt
1460247738Sbapt/**
1461247738Sbapt * The prototype of a write handler.
1462247738Sbapt *
1463247738Sbapt * The write handler is called when the emitter needs to flush the accumulated
1464247738Sbapt * characters to the output.  The handler should write @a size bytes of the
1465247738Sbapt * @a buffer to the output.
1466247738Sbapt *
1467247738Sbapt * @param[in,out]   data        A pointer to an application data specified by
1468247738Sbapt *                              yaml_emitter_set_output().
1469247738Sbapt * @param[in]       buffer      The buffer with bytes to be written.
1470247738Sbapt * @param[in]       size        The size of the buffer.
1471247738Sbapt *
1472247738Sbapt * @returns On success, the handler should return @c 1.  If the handler failed,
1473247738Sbapt * the returned value should be @c 0.
1474247738Sbapt */
1475247738Sbapt
1476247738Sbapttypedef int yaml_write_handler_t(void *data, unsigned char *buffer, size_t size);
1477247738Sbapt
1478247738Sbapt/** The emitter states. */
1479247738Sbapttypedef enum yaml_emitter_state_e {
1480247738Sbapt    /** Expect STREAM-START. */
1481247738Sbapt    YAML_EMIT_STREAM_START_STATE,
1482247738Sbapt    /** Expect the first DOCUMENT-START or STREAM-END. */
1483247738Sbapt    YAML_EMIT_FIRST_DOCUMENT_START_STATE,
1484247738Sbapt    /** Expect DOCUMENT-START or STREAM-END. */
1485247738Sbapt    YAML_EMIT_DOCUMENT_START_STATE,
1486247738Sbapt    /** Expect the content of a document. */
1487247738Sbapt    YAML_EMIT_DOCUMENT_CONTENT_STATE,
1488247738Sbapt    /** Expect DOCUMENT-END. */
1489247738Sbapt    YAML_EMIT_DOCUMENT_END_STATE,
1490247738Sbapt    /** Expect the first item of a flow sequence. */
1491247738Sbapt    YAML_EMIT_FLOW_SEQUENCE_FIRST_ITEM_STATE,
1492247738Sbapt    /** Expect an item of a flow sequence. */
1493247738Sbapt    YAML_EMIT_FLOW_SEQUENCE_ITEM_STATE,
1494247738Sbapt    /** Expect the first key of a flow mapping. */
1495247738Sbapt    YAML_EMIT_FLOW_MAPPING_FIRST_KEY_STATE,
1496247738Sbapt    /** Expect a key of a flow mapping. */
1497247738Sbapt    YAML_EMIT_FLOW_MAPPING_KEY_STATE,
1498247738Sbapt    /** Expect a value for a simple key of a flow mapping. */
1499247738Sbapt    YAML_EMIT_FLOW_MAPPING_SIMPLE_VALUE_STATE,
1500247738Sbapt    /** Expect a value of a flow mapping. */
1501247738Sbapt    YAML_EMIT_FLOW_MAPPING_VALUE_STATE,
1502247738Sbapt    /** Expect the first item of a block sequence. */
1503247738Sbapt    YAML_EMIT_BLOCK_SEQUENCE_FIRST_ITEM_STATE,
1504247738Sbapt    /** Expect an item of a block sequence. */
1505247738Sbapt    YAML_EMIT_BLOCK_SEQUENCE_ITEM_STATE,
1506247738Sbapt    /** Expect the first key of a block mapping. */
1507247738Sbapt    YAML_EMIT_BLOCK_MAPPING_FIRST_KEY_STATE,
1508247738Sbapt    /** Expect the key of a block mapping. */
1509247738Sbapt    YAML_EMIT_BLOCK_MAPPING_KEY_STATE,
1510247738Sbapt    /** Expect a value for a simple key of a block mapping. */
1511247738Sbapt    YAML_EMIT_BLOCK_MAPPING_SIMPLE_VALUE_STATE,
1512247738Sbapt    /** Expect a value of a block mapping. */
1513247738Sbapt    YAML_EMIT_BLOCK_MAPPING_VALUE_STATE,
1514247738Sbapt    /** Expect nothing. */
1515247738Sbapt    YAML_EMIT_END_STATE
1516247738Sbapt} yaml_emitter_state_t;
1517247738Sbapt
1518247738Sbapt/**
1519247738Sbapt * The emitter structure.
1520247738Sbapt *
1521247738Sbapt * All members are internal.  Manage the structure using the @c yaml_emitter_
1522247738Sbapt * family of functions.
1523247738Sbapt */
1524247738Sbapt
1525247738Sbapttypedef struct yaml_emitter_s {
1526247738Sbapt
1527247738Sbapt    /**
1528247738Sbapt     * @name Error handling
1529247738Sbapt     * @{
1530247738Sbapt     */
1531247738Sbapt
1532247738Sbapt    /** Error type. */
1533247738Sbapt    yaml_error_type_t error;
1534247738Sbapt    /** Error description. */
1535247738Sbapt    const char *problem;
1536247738Sbapt
1537247738Sbapt    /**
1538247738Sbapt     * @}
1539247738Sbapt     */
1540247738Sbapt
1541247738Sbapt    /**
1542247738Sbapt     * @name Writer stuff
1543247738Sbapt     * @{
1544247738Sbapt     */
1545247738Sbapt
1546247738Sbapt    /** Write handler. */
1547247738Sbapt    yaml_write_handler_t *write_handler;
1548247738Sbapt
1549247738Sbapt    /** A pointer for passing to the white handler. */
1550247738Sbapt    void *write_handler_data;
1551247738Sbapt
1552247738Sbapt    /** Standard (string or file) output data. */
1553247738Sbapt    union {
1554247738Sbapt        /** String output data. */
1555247738Sbapt        struct {
1556247738Sbapt            /** The buffer pointer. */
1557247738Sbapt            unsigned char *buffer;
1558247738Sbapt            /** The buffer size. */
1559247738Sbapt            size_t size;
1560247738Sbapt            /** The number of written bytes. */
1561247738Sbapt            size_t *size_written;
1562247738Sbapt        } string;
1563247738Sbapt
1564247738Sbapt        /** File output data. */
1565247738Sbapt        FILE *file;
1566247738Sbapt    } output;
1567247738Sbapt
1568247738Sbapt    /** The working buffer. */
1569247738Sbapt    struct {
1570247738Sbapt        /** The beginning of the buffer. */
1571247738Sbapt        yaml_char_t *start;
1572247738Sbapt        /** The end of the buffer. */
1573247738Sbapt        yaml_char_t *end;
1574247738Sbapt        /** The current position of the buffer. */
1575247738Sbapt        yaml_char_t *pointer;
1576247738Sbapt        /** The last filled position of the buffer. */
1577247738Sbapt        yaml_char_t *last;
1578247738Sbapt    } buffer;
1579247738Sbapt
1580247738Sbapt    /** The raw buffer. */
1581247738Sbapt    struct {
1582247738Sbapt        /** The beginning of the buffer. */
1583247738Sbapt        unsigned char *start;
1584247738Sbapt        /** The end of the buffer. */
1585247738Sbapt        unsigned char *end;
1586247738Sbapt        /** The current position of the buffer. */
1587247738Sbapt        unsigned char *pointer;
1588247738Sbapt        /** The last filled position of the buffer. */
1589247738Sbapt        unsigned char *last;
1590247738Sbapt    } raw_buffer;
1591247738Sbapt
1592247738Sbapt    /** The stream encoding. */
1593247738Sbapt    yaml_encoding_t encoding;
1594247738Sbapt
1595247738Sbapt    /**
1596247738Sbapt     * @}
1597247738Sbapt     */
1598247738Sbapt
1599247738Sbapt    /**
1600247738Sbapt     * @name Emitter stuff
1601247738Sbapt     * @{
1602247738Sbapt     */
1603247738Sbapt
1604247738Sbapt    /** If the output is in the canonical style? */
1605247738Sbapt    int canonical;
1606247738Sbapt    /** The number of indentation spaces. */
1607247738Sbapt    int best_indent;
1608247738Sbapt    /** The preferred width of the output lines. */
1609247738Sbapt    int best_width;
1610247738Sbapt    /** Allow unescaped non-ASCII characters? */
1611247738Sbapt    int unicode;
1612247738Sbapt    /** The preferred line break. */
1613247738Sbapt    yaml_break_t line_break;
1614247738Sbapt
1615247738Sbapt    /** The stack of states. */
1616247738Sbapt    struct {
1617247738Sbapt        /** The beginning of the stack. */
1618247738Sbapt        yaml_emitter_state_t *start;
1619247738Sbapt        /** The end of the stack. */
1620247738Sbapt        yaml_emitter_state_t *end;
1621247738Sbapt        /** The top of the stack. */
1622247738Sbapt        yaml_emitter_state_t *top;
1623247738Sbapt    } states;
1624247738Sbapt
1625247738Sbapt    /** The current emitter state. */
1626247738Sbapt    yaml_emitter_state_t state;
1627247738Sbapt
1628247738Sbapt    /** The event queue. */
1629247738Sbapt    struct {
1630247738Sbapt        /** The beginning of the event queue. */
1631247738Sbapt        yaml_event_t *start;
1632247738Sbapt        /** The end of the event queue. */
1633247738Sbapt        yaml_event_t *end;
1634247738Sbapt        /** The head of the event queue. */
1635247738Sbapt        yaml_event_t *head;
1636247738Sbapt        /** The tail of the event queue. */
1637247738Sbapt        yaml_event_t *tail;
1638247738Sbapt    } events;
1639247738Sbapt
1640247738Sbapt    /** The stack of indentation levels. */
1641247738Sbapt    struct {
1642247738Sbapt        /** The beginning of the stack. */
1643247738Sbapt        int *start;
1644247738Sbapt        /** The end of the stack. */
1645247738Sbapt        int *end;
1646247738Sbapt        /** The top of the stack. */
1647247738Sbapt        int *top;
1648247738Sbapt    } indents;
1649247738Sbapt
1650247738Sbapt    /** The list of tag directives. */
1651247738Sbapt    struct {
1652247738Sbapt        /** The beginning of the list. */
1653247738Sbapt        yaml_tag_directive_t *start;
1654247738Sbapt        /** The end of the list. */
1655247738Sbapt        yaml_tag_directive_t *end;
1656247738Sbapt        /** The top of the list. */
1657247738Sbapt        yaml_tag_directive_t *top;
1658247738Sbapt    } tag_directives;
1659247738Sbapt
1660247738Sbapt    /** The current indentation level. */
1661247738Sbapt    int indent;
1662247738Sbapt
1663247738Sbapt    /** The current flow level. */
1664247738Sbapt    int flow_level;
1665247738Sbapt
1666247738Sbapt    /** Is it the document root context? */
1667247738Sbapt    int root_context;
1668247738Sbapt    /** Is it a sequence context? */
1669247738Sbapt    int sequence_context;
1670247738Sbapt    /** Is it a mapping context? */
1671247738Sbapt    int mapping_context;
1672247738Sbapt    /** Is it a simple mapping key context? */
1673247738Sbapt    int simple_key_context;
1674247738Sbapt
1675247738Sbapt    /** The current line. */
1676247738Sbapt    int line;
1677247738Sbapt    /** The current column. */
1678247738Sbapt    int column;
1679247738Sbapt    /** If the last character was a whitespace? */
1680247738Sbapt    int whitespace;
1681247738Sbapt    /** If the last character was an indentation character (' ', '-', '?', ':')? */
1682247738Sbapt    int indention;
1683247738Sbapt    /** If an explicit document end is required? */
1684247738Sbapt    int open_ended;
1685247738Sbapt
1686247738Sbapt    /** Anchor analysis. */
1687247738Sbapt    struct {
1688247738Sbapt        /** The anchor value. */
1689247738Sbapt        yaml_char_t *anchor;
1690247738Sbapt        /** The anchor length. */
1691247738Sbapt        size_t anchor_length;
1692247738Sbapt        /** Is it an alias? */
1693247738Sbapt        int alias;
1694247738Sbapt    } anchor_data;
1695247738Sbapt
1696247738Sbapt    /** Tag analysis. */
1697247738Sbapt    struct {
1698247738Sbapt        /** The tag handle. */
1699247738Sbapt        yaml_char_t *handle;
1700247738Sbapt        /** The tag handle length. */
1701247738Sbapt        size_t handle_length;
1702247738Sbapt        /** The tag suffix. */
1703247738Sbapt        yaml_char_t *suffix;
1704247738Sbapt        /** The tag suffix length. */
1705247738Sbapt        size_t suffix_length;
1706247738Sbapt    } tag_data;
1707247738Sbapt
1708247738Sbapt    /** Scalar analysis. */
1709247738Sbapt    struct {
1710247738Sbapt        /** The scalar value. */
1711247738Sbapt        yaml_char_t *value;
1712247738Sbapt        /** The scalar length. */
1713247738Sbapt        size_t length;
1714247738Sbapt        /** Does the scalar contain line breaks? */
1715247738Sbapt        int multiline;
1716247738Sbapt        /** Can the scalar be expessed in the flow plain style? */
1717247738Sbapt        int flow_plain_allowed;
1718247738Sbapt        /** Can the scalar be expressed in the block plain style? */
1719247738Sbapt        int block_plain_allowed;
1720247738Sbapt        /** Can the scalar be expressed in the single quoted style? */
1721247738Sbapt        int single_quoted_allowed;
1722247738Sbapt        /** Can the scalar be expressed in the literal or folded styles? */
1723247738Sbapt        int block_allowed;
1724247738Sbapt        /** The output style. */
1725247738Sbapt        yaml_scalar_style_t style;
1726247738Sbapt    } scalar_data;
1727247738Sbapt
1728247738Sbapt    /**
1729247738Sbapt     * @}
1730247738Sbapt     */
1731247738Sbapt
1732247738Sbapt    /**
1733247738Sbapt     * @name Dumper stuff
1734247738Sbapt     * @{
1735247738Sbapt     */
1736247738Sbapt
1737247738Sbapt    /** If the stream was already opened? */
1738247738Sbapt    int opened;
1739247738Sbapt    /** If the stream was already closed? */
1740247738Sbapt    int closed;
1741247738Sbapt
1742247738Sbapt    /** The information associated with the document nodes. */
1743247738Sbapt    struct {
1744247738Sbapt        /** The number of references. */
1745247738Sbapt        int references;
1746247738Sbapt        /** The anchor id. */
1747247738Sbapt        int anchor;
1748247738Sbapt        /** If the node has been emitted? */
1749247738Sbapt        int serialized;
1750247738Sbapt    } *anchors;
1751247738Sbapt
1752247738Sbapt    /** The last assigned anchor id. */
1753247738Sbapt    int last_anchor_id;
1754247738Sbapt
1755247738Sbapt    /** The currently emitted document. */
1756247738Sbapt    yaml_document_t *document;
1757247738Sbapt
1758247738Sbapt    /**
1759247738Sbapt     * @}
1760247738Sbapt     */
1761247738Sbapt
1762247738Sbapt} yaml_emitter_t;
1763247738Sbapt
1764247738Sbapt/**
1765247738Sbapt * Initialize an emitter.
1766247738Sbapt *
1767247738Sbapt * This function creates a new emitter object.  An application is responsible
1768247738Sbapt * for destroying the object using the yaml_emitter_delete() function.
1769247738Sbapt *
1770247738Sbapt * @param[out]      emitter     An empty parser object.
1771247738Sbapt *
1772247738Sbapt * @returns @c 1 if the function succeeded, @c 0 on error.
1773247738Sbapt */
1774247738Sbapt
1775247738SbaptYAML_DECLARE(int)
1776247738Sbaptyaml_emitter_initialize(yaml_emitter_t *emitter);
1777247738Sbapt
1778247738Sbapt/**
1779247738Sbapt * Destroy an emitter.
1780247738Sbapt *
1781247738Sbapt * @param[in,out]   emitter     An emitter object.
1782247738Sbapt */
1783247738Sbapt
1784247738SbaptYAML_DECLARE(void)
1785247738Sbaptyaml_emitter_delete(yaml_emitter_t *emitter);
1786247738Sbapt
1787247738Sbapt/**
1788247738Sbapt * Set a string output.
1789247738Sbapt *
1790247738Sbapt * The emitter will write the output characters to the @a output buffer of the
1791247738Sbapt * size @a size.  The emitter will set @a size_written to the number of written
1792247738Sbapt * bytes.  If the buffer is smaller than required, the emitter produces the
1793247738Sbapt * YAML_WRITE_ERROR error.
1794247738Sbapt *
1795247738Sbapt * @param[in,out]   emitter         An emitter object.
1796247738Sbapt * @param[in]       output          An output buffer.
1797247738Sbapt * @param[in]       size            The buffer size.
1798247738Sbapt * @param[in]       size_written    The pointer to save the number of written
1799247738Sbapt *                                  bytes.
1800247738Sbapt */
1801247738Sbapt
1802247738SbaptYAML_DECLARE(void)
1803247738Sbaptyaml_emitter_set_output_string(yaml_emitter_t *emitter,
1804247738Sbapt        unsigned char *output, size_t size, size_t *size_written);
1805247738Sbapt
1806247738Sbapt/**
1807247738Sbapt * Set a file output.
1808247738Sbapt *
1809247738Sbapt * @a file should be a file object open for writing.  The application is
1810247738Sbapt * responsible for closing the @a file.
1811247738Sbapt *
1812247738Sbapt * @param[in,out]   emitter     An emitter object.
1813247738Sbapt * @param[in]       file        An open file.
1814247738Sbapt */
1815247738Sbapt
1816247738SbaptYAML_DECLARE(void)
1817247738Sbaptyaml_emitter_set_output_file(yaml_emitter_t *emitter, FILE *file);
1818247738Sbapt
1819247738Sbapt/**
1820247738Sbapt * Set a generic output handler.
1821247738Sbapt *
1822247738Sbapt * @param[in,out]   emitter     An emitter object.
1823247738Sbapt * @param[in]       handler     A write handler.
1824247738Sbapt * @param[in]       data        Any application data for passing to the write
1825247738Sbapt *                              handler.
1826247738Sbapt */
1827247738Sbapt
1828247738SbaptYAML_DECLARE(void)
1829247738Sbaptyaml_emitter_set_output(yaml_emitter_t *emitter,
1830247738Sbapt        yaml_write_handler_t *handler, void *data);
1831247738Sbapt
1832247738Sbapt/**
1833247738Sbapt * Set the output encoding.
1834247738Sbapt *
1835247738Sbapt * @param[in,out]   emitter     An emitter object.
1836247738Sbapt * @param[in]       encoding    The output encoding.
1837247738Sbapt */
1838247738Sbapt
1839247738SbaptYAML_DECLARE(void)
1840247738Sbaptyaml_emitter_set_encoding(yaml_emitter_t *emitter, yaml_encoding_t encoding);
1841247738Sbapt
1842247738Sbapt/**
1843247738Sbapt * Set if the output should be in the "canonical" format as in the YAML
1844247738Sbapt * specification.
1845247738Sbapt *
1846247738Sbapt * @param[in,out]   emitter     An emitter object.
1847247738Sbapt * @param[in]       canonical   If the output is canonical.
1848247738Sbapt */
1849247738Sbapt
1850247738SbaptYAML_DECLARE(void)
1851247738Sbaptyaml_emitter_set_canonical(yaml_emitter_t *emitter, int canonical);
1852247738Sbapt
1853247738Sbapt/**
1854247738Sbapt * Set the intendation increment.
1855247738Sbapt *
1856247738Sbapt * @param[in,out]   emitter     An emitter object.
1857247738Sbapt * @param[in]       indent      The indentation increment (1 < . < 10).
1858247738Sbapt */
1859247738Sbapt
1860247738SbaptYAML_DECLARE(void)
1861247738Sbaptyaml_emitter_set_indent(yaml_emitter_t *emitter, int indent);
1862247738Sbapt
1863247738Sbapt/**
1864247738Sbapt * Set the preferred line width. @c -1 means unlimited.
1865247738Sbapt *
1866247738Sbapt * @param[in,out]   emitter     An emitter object.
1867247738Sbapt * @param[in]       width       The preferred line width.
1868247738Sbapt */
1869247738Sbapt
1870247738SbaptYAML_DECLARE(void)
1871247738Sbaptyaml_emitter_set_width(yaml_emitter_t *emitter, int width);
1872247738Sbapt
1873247738Sbapt/**
1874247738Sbapt * Set if unescaped non-ASCII characters are allowed.
1875247738Sbapt *
1876247738Sbapt * @param[in,out]   emitter     An emitter object.
1877247738Sbapt * @param[in]       unicode     If unescaped Unicode characters are allowed.
1878247738Sbapt */
1879247738Sbapt
1880247738SbaptYAML_DECLARE(void)
1881247738Sbaptyaml_emitter_set_unicode(yaml_emitter_t *emitter, int unicode);
1882247738Sbapt
1883247738Sbapt/**
1884247738Sbapt * Set the preferred line break.
1885247738Sbapt *
1886247738Sbapt * @param[in,out]   emitter     An emitter object.
1887247738Sbapt * @param[in]       line_break  The preferred line break.
1888247738Sbapt */
1889247738Sbapt
1890247738SbaptYAML_DECLARE(void)
1891247738Sbaptyaml_emitter_set_break(yaml_emitter_t *emitter, yaml_break_t line_break);
1892247738Sbapt
1893247738Sbapt/**
1894247738Sbapt * Emit an event.
1895247738Sbapt *
1896247738Sbapt * The event object may be generated using the yaml_parser_parse() function.
1897247738Sbapt * The emitter takes the responsibility for the event object and destroys its
1898247738Sbapt * content after it is emitted. The event object is destroyed even if the
1899247738Sbapt * function fails.
1900247738Sbapt *
1901247738Sbapt * @param[in,out]   emitter     An emitter object.
1902247738Sbapt * @param[in,out]   event       An event object.
1903247738Sbapt *
1904247738Sbapt * @returns @c 1 if the function succeeded, @c 0 on error.
1905247738Sbapt */
1906247738Sbapt
1907247738SbaptYAML_DECLARE(int)
1908247738Sbaptyaml_emitter_emit(yaml_emitter_t *emitter, yaml_event_t *event);
1909247738Sbapt
1910247738Sbapt/**
1911247738Sbapt * Start a YAML stream.
1912247738Sbapt *
1913247738Sbapt * This function should be used before yaml_emitter_dump() is called.
1914247738Sbapt *
1915247738Sbapt * @param[in,out]   emitter     An emitter object.
1916247738Sbapt *
1917247738Sbapt * @returns @c 1 if the function succeeded, @c 0 on error.
1918247738Sbapt */
1919247738Sbapt
1920247738SbaptYAML_DECLARE(int)
1921247738Sbaptyaml_emitter_open(yaml_emitter_t *emitter);
1922247738Sbapt
1923247738Sbapt/**
1924247738Sbapt * Finish a YAML stream.
1925247738Sbapt *
1926247738Sbapt * This function should be used after yaml_emitter_dump() is called.
1927247738Sbapt *
1928247738Sbapt * @param[in,out]   emitter     An emitter object.
1929247738Sbapt *
1930247738Sbapt * @returns @c 1 if the function succeeded, @c 0 on error.
1931247738Sbapt */
1932247738Sbapt
1933247738SbaptYAML_DECLARE(int)
1934247738Sbaptyaml_emitter_close(yaml_emitter_t *emitter);
1935247738Sbapt
1936247738Sbapt/**
1937247738Sbapt * Emit a YAML document.
1938247738Sbapt *
1939247738Sbapt * The documen object may be generated using the yaml_parser_load() function
1940247738Sbapt * or the yaml_document_initialize() function.  The emitter takes the
1941247738Sbapt * responsibility for the document object and destoys its content after
1942247738Sbapt * it is emitted. The document object is destroyedeven if the function fails.
1943247738Sbapt *
1944247738Sbapt * @param[in,out]   emitter     An emitter object.
1945247738Sbapt * @param[in,out]   document    A document object.
1946247738Sbapt *
1947247738Sbapt * @returns @c 1 if the function succeeded, @c 0 on error.
1948247738Sbapt */
1949247738Sbapt
1950247738SbaptYAML_DECLARE(int)
1951247738Sbaptyaml_emitter_dump(yaml_emitter_t *emitter, yaml_document_t *document);
1952247738Sbapt
1953247738Sbapt/**
1954247738Sbapt * Flush the accumulated characters to the output.
1955247738Sbapt *
1956247738Sbapt * @param[in,out]   emitter     An emitter object.
1957247738Sbapt *
1958247738Sbapt * @returns @c 1 if the function succeeded, @c 0 on error.
1959247738Sbapt */
1960247738Sbapt
1961247738SbaptYAML_DECLARE(int)
1962247738Sbaptyaml_emitter_flush(yaml_emitter_t *emitter);
1963247738Sbapt
1964247738Sbapt/** @} */
1965247738Sbapt
1966247738Sbapt#ifdef __cplusplus
1967247738Sbapt}
1968247738Sbapt#endif
1969247738Sbapt
1970247738Sbapt#endif /* #ifndef YAML_H */
1971247738Sbapt
1972