//1// Copyright (c) 2011-2019 Canonical Ltd2// Copyright (c) 2006-2010 Kirill Simonov3//4// Permission is hereby granted, free of charge, to any person obtaining a copy of5// this software and associated documentation files (the "Software"), to deal in6// the Software without restriction, including without limitation the rights to7// use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies8// of the Software, and to permit persons to whom the Software is furnished to do9// so, subject to the following conditions:10//11// The above copyright notice and this permission notice shall be included in all12// copies or substantial portions of the Software.13//14// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR15// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,16// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE17// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER18// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,19// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE20// SOFTWARE.2122package yaml2324import (25"fmt"26"io"27)2829// The version directive data.30type yaml_version_directive_t struct {31major int8 // The major version number.32minor int8 // The minor version number.33}3435// The tag directive data.36type yaml_tag_directive_t struct {37handle []byte // The tag handle.38prefix []byte // The tag prefix.39}4041type yaml_encoding_t int4243// The stream encoding.44const (45// Let the parser choose the encoding.46yaml_ANY_ENCODING yaml_encoding_t = iota4748yaml_UTF8_ENCODING // The default UTF-8 encoding.49yaml_UTF16LE_ENCODING // The UTF-16-LE encoding with BOM.50yaml_UTF16BE_ENCODING // The UTF-16-BE encoding with BOM.51)5253type yaml_break_t int5455// Line break types.56const (57// Let the parser choose the break type.58yaml_ANY_BREAK yaml_break_t = iota5960yaml_CR_BREAK // Use CR for line breaks (Mac style).61yaml_LN_BREAK // Use LN for line breaks (Unix style).62yaml_CRLN_BREAK // Use CR LN for line breaks (DOS style).63)6465type yaml_error_type_t int6667// Many bad things could happen with the parser and emitter.68const (69// No error is produced.70yaml_NO_ERROR yaml_error_type_t = iota7172yaml_MEMORY_ERROR // Cannot allocate or reallocate a block of memory.73yaml_READER_ERROR // Cannot read or decode the input stream.74yaml_SCANNER_ERROR // Cannot scan the input stream.75yaml_PARSER_ERROR // Cannot parse the input stream.76yaml_COMPOSER_ERROR // Cannot compose a YAML document.77yaml_WRITER_ERROR // Cannot write to the output stream.78yaml_EMITTER_ERROR // Cannot emit a YAML stream.79)8081// The pointer position.82type yaml_mark_t struct {83index int // The position index.84line int // The position line.85column int // The position column.86}8788// Node Styles8990type yaml_style_t int89192type yaml_scalar_style_t yaml_style_t9394// Scalar styles.95const (96// Let the emitter choose the style.97yaml_ANY_SCALAR_STYLE yaml_scalar_style_t = 09899yaml_PLAIN_SCALAR_STYLE yaml_scalar_style_t = 1 << iota // The plain scalar style.100yaml_SINGLE_QUOTED_SCALAR_STYLE // The single-quoted scalar style.101yaml_DOUBLE_QUOTED_SCALAR_STYLE // The double-quoted scalar style.102yaml_LITERAL_SCALAR_STYLE // The literal scalar style.103yaml_FOLDED_SCALAR_STYLE // The folded scalar style.104)105106type yaml_sequence_style_t yaml_style_t107108// Sequence styles.109const (110// Let the emitter choose the style.111yaml_ANY_SEQUENCE_STYLE yaml_sequence_style_t = iota112113yaml_BLOCK_SEQUENCE_STYLE // The block sequence style.114yaml_FLOW_SEQUENCE_STYLE // The flow sequence style.115)116117type yaml_mapping_style_t yaml_style_t118119// Mapping styles.120const (121// Let the emitter choose the style.122yaml_ANY_MAPPING_STYLE yaml_mapping_style_t = iota123124yaml_BLOCK_MAPPING_STYLE // The block mapping style.125yaml_FLOW_MAPPING_STYLE // The flow mapping style.126)127128// Tokens129130type yaml_token_type_t int131132// Token types.133const (134// An empty token.135yaml_NO_TOKEN yaml_token_type_t = iota136137yaml_STREAM_START_TOKEN // A STREAM-START token.138yaml_STREAM_END_TOKEN // A STREAM-END token.139140yaml_VERSION_DIRECTIVE_TOKEN // A VERSION-DIRECTIVE token.141yaml_TAG_DIRECTIVE_TOKEN // A TAG-DIRECTIVE token.142yaml_DOCUMENT_START_TOKEN // A DOCUMENT-START token.143yaml_DOCUMENT_END_TOKEN // A DOCUMENT-END token.144145yaml_BLOCK_SEQUENCE_START_TOKEN // A BLOCK-SEQUENCE-START token.146yaml_BLOCK_MAPPING_START_TOKEN // A BLOCK-SEQUENCE-END token.147yaml_BLOCK_END_TOKEN // A BLOCK-END token.148149yaml_FLOW_SEQUENCE_START_TOKEN // A FLOW-SEQUENCE-START token.150yaml_FLOW_SEQUENCE_END_TOKEN // A FLOW-SEQUENCE-END token.151yaml_FLOW_MAPPING_START_TOKEN // A FLOW-MAPPING-START token.152yaml_FLOW_MAPPING_END_TOKEN // A FLOW-MAPPING-END token.153154yaml_BLOCK_ENTRY_TOKEN // A BLOCK-ENTRY token.155yaml_FLOW_ENTRY_TOKEN // A FLOW-ENTRY token.156yaml_KEY_TOKEN // A KEY token.157yaml_VALUE_TOKEN // A VALUE token.158159yaml_ALIAS_TOKEN // An ALIAS token.160yaml_ANCHOR_TOKEN // An ANCHOR token.161yaml_TAG_TOKEN // A TAG token.162yaml_SCALAR_TOKEN // A SCALAR token.163)164165func (tt yaml_token_type_t) String() string {166switch tt {167case yaml_NO_TOKEN:168return "yaml_NO_TOKEN"169case yaml_STREAM_START_TOKEN:170return "yaml_STREAM_START_TOKEN"171case yaml_STREAM_END_TOKEN:172return "yaml_STREAM_END_TOKEN"173case yaml_VERSION_DIRECTIVE_TOKEN:174return "yaml_VERSION_DIRECTIVE_TOKEN"175case yaml_TAG_DIRECTIVE_TOKEN:176return "yaml_TAG_DIRECTIVE_TOKEN"177case yaml_DOCUMENT_START_TOKEN:178return "yaml_DOCUMENT_START_TOKEN"179case yaml_DOCUMENT_END_TOKEN:180return "yaml_DOCUMENT_END_TOKEN"181case yaml_BLOCK_SEQUENCE_START_TOKEN:182return "yaml_BLOCK_SEQUENCE_START_TOKEN"183case yaml_BLOCK_MAPPING_START_TOKEN:184return "yaml_BLOCK_MAPPING_START_TOKEN"185case yaml_BLOCK_END_TOKEN:186return "yaml_BLOCK_END_TOKEN"187case yaml_FLOW_SEQUENCE_START_TOKEN:188return "yaml_FLOW_SEQUENCE_START_TOKEN"189case yaml_FLOW_SEQUENCE_END_TOKEN:190return "yaml_FLOW_SEQUENCE_END_TOKEN"191case yaml_FLOW_MAPPING_START_TOKEN:192return "yaml_FLOW_MAPPING_START_TOKEN"193case yaml_FLOW_MAPPING_END_TOKEN:194return "yaml_FLOW_MAPPING_END_TOKEN"195case yaml_BLOCK_ENTRY_TOKEN:196return "yaml_BLOCK_ENTRY_TOKEN"197case yaml_FLOW_ENTRY_TOKEN:198return "yaml_FLOW_ENTRY_TOKEN"199case yaml_KEY_TOKEN:200return "yaml_KEY_TOKEN"201case yaml_VALUE_TOKEN:202return "yaml_VALUE_TOKEN"203case yaml_ALIAS_TOKEN:204return "yaml_ALIAS_TOKEN"205case yaml_ANCHOR_TOKEN:206return "yaml_ANCHOR_TOKEN"207case yaml_TAG_TOKEN:208return "yaml_TAG_TOKEN"209case yaml_SCALAR_TOKEN:210return "yaml_SCALAR_TOKEN"211}212return "<unknown token>"213}214215// The token structure.216type yaml_token_t struct {217// The token type.218typ yaml_token_type_t219220// The start/end of the token.221start_mark, end_mark yaml_mark_t222223// The stream encoding (for yaml_STREAM_START_TOKEN).224encoding yaml_encoding_t225226// The alias/anchor/scalar value or tag/tag directive handle227// (for yaml_ALIAS_TOKEN, yaml_ANCHOR_TOKEN, yaml_SCALAR_TOKEN, yaml_TAG_TOKEN, yaml_TAG_DIRECTIVE_TOKEN).228value []byte229230// The tag suffix (for yaml_TAG_TOKEN).231suffix []byte232233// The tag directive prefix (for yaml_TAG_DIRECTIVE_TOKEN).234prefix []byte235236// The scalar style (for yaml_SCALAR_TOKEN).237style yaml_scalar_style_t238239// The version directive major/minor (for yaml_VERSION_DIRECTIVE_TOKEN).240major, minor int8241}242243// Events244245type yaml_event_type_t int8246247// Event types.248const (249// An empty event.250yaml_NO_EVENT yaml_event_type_t = iota251252yaml_STREAM_START_EVENT // A STREAM-START event.253yaml_STREAM_END_EVENT // A STREAM-END event.254yaml_DOCUMENT_START_EVENT // A DOCUMENT-START event.255yaml_DOCUMENT_END_EVENT // A DOCUMENT-END event.256yaml_ALIAS_EVENT // An ALIAS event.257yaml_SCALAR_EVENT // A SCALAR event.258yaml_SEQUENCE_START_EVENT // A SEQUENCE-START event.259yaml_SEQUENCE_END_EVENT // A SEQUENCE-END event.260yaml_MAPPING_START_EVENT // A MAPPING-START event.261yaml_MAPPING_END_EVENT // A MAPPING-END event.262yaml_TAIL_COMMENT_EVENT263)264265var eventStrings = []string{266yaml_NO_EVENT: "none",267yaml_STREAM_START_EVENT: "stream start",268yaml_STREAM_END_EVENT: "stream end",269yaml_DOCUMENT_START_EVENT: "document start",270yaml_DOCUMENT_END_EVENT: "document end",271yaml_ALIAS_EVENT: "alias",272yaml_SCALAR_EVENT: "scalar",273yaml_SEQUENCE_START_EVENT: "sequence start",274yaml_SEQUENCE_END_EVENT: "sequence end",275yaml_MAPPING_START_EVENT: "mapping start",276yaml_MAPPING_END_EVENT: "mapping end",277yaml_TAIL_COMMENT_EVENT: "tail comment",278}279280func (e yaml_event_type_t) String() string {281if e < 0 || int(e) >= len(eventStrings) {282return fmt.Sprintf("unknown event %d", e)283}284return eventStrings[e]285}286287// The event structure.288type yaml_event_t struct {289290// The event type.291typ yaml_event_type_t292293// The start and end of the event.294start_mark, end_mark yaml_mark_t295296// The document encoding (for yaml_STREAM_START_EVENT).297encoding yaml_encoding_t298299// The version directive (for yaml_DOCUMENT_START_EVENT).300version_directive *yaml_version_directive_t301302// The list of tag directives (for yaml_DOCUMENT_START_EVENT).303tag_directives []yaml_tag_directive_t304305// The comments306head_comment []byte307line_comment []byte308foot_comment []byte309tail_comment []byte310311// The anchor (for yaml_SCALAR_EVENT, yaml_SEQUENCE_START_EVENT, yaml_MAPPING_START_EVENT, yaml_ALIAS_EVENT).312anchor []byte313314// The tag (for yaml_SCALAR_EVENT, yaml_SEQUENCE_START_EVENT, yaml_MAPPING_START_EVENT).315tag []byte316317// The scalar value (for yaml_SCALAR_EVENT).318value []byte319320// Is the document start/end indicator implicit, or the tag optional?321// (for yaml_DOCUMENT_START_EVENT, yaml_DOCUMENT_END_EVENT, yaml_SEQUENCE_START_EVENT, yaml_MAPPING_START_EVENT, yaml_SCALAR_EVENT).322implicit bool323324// Is the tag optional for any non-plain style? (for yaml_SCALAR_EVENT).325quoted_implicit bool326327// The style (for yaml_SCALAR_EVENT, yaml_SEQUENCE_START_EVENT, yaml_MAPPING_START_EVENT).328style yaml_style_t329}330331func (e *yaml_event_t) scalar_style() yaml_scalar_style_t { return yaml_scalar_style_t(e.style) }332func (e *yaml_event_t) sequence_style() yaml_sequence_style_t { return yaml_sequence_style_t(e.style) }333func (e *yaml_event_t) mapping_style() yaml_mapping_style_t { return yaml_mapping_style_t(e.style) }334335// Nodes336337const (338yaml_NULL_TAG = "tag:yaml.org,2002:null" // The tag !!null with the only possible value: null.339yaml_BOOL_TAG = "tag:yaml.org,2002:bool" // The tag !!bool with the values: true and false.340yaml_STR_TAG = "tag:yaml.org,2002:str" // The tag !!str for string values.341yaml_INT_TAG = "tag:yaml.org,2002:int" // The tag !!int for integer values.342yaml_FLOAT_TAG = "tag:yaml.org,2002:float" // The tag !!float for float values.343yaml_TIMESTAMP_TAG = "tag:yaml.org,2002:timestamp" // The tag !!timestamp for date and time values.344345yaml_SEQ_TAG = "tag:yaml.org,2002:seq" // The tag !!seq is used to denote sequences.346yaml_MAP_TAG = "tag:yaml.org,2002:map" // The tag !!map is used to denote mapping.347348// Not in original libyaml.349yaml_BINARY_TAG = "tag:yaml.org,2002:binary"350yaml_MERGE_TAG = "tag:yaml.org,2002:merge"351352yaml_DEFAULT_SCALAR_TAG = yaml_STR_TAG // The default scalar tag is !!str.353yaml_DEFAULT_SEQUENCE_TAG = yaml_SEQ_TAG // The default sequence tag is !!seq.354yaml_DEFAULT_MAPPING_TAG = yaml_MAP_TAG // The default mapping tag is !!map.355)356357type yaml_node_type_t int358359// Node types.360const (361// An empty node.362yaml_NO_NODE yaml_node_type_t = iota363364yaml_SCALAR_NODE // A scalar node.365yaml_SEQUENCE_NODE // A sequence node.366yaml_MAPPING_NODE // A mapping node.367)368369// An element of a sequence node.370type yaml_node_item_t int371372// An element of a mapping node.373type yaml_node_pair_t struct {374key int // The key of the element.375value int // The value of the element.376}377378// The node structure.379type yaml_node_t struct {380typ yaml_node_type_t // The node type.381tag []byte // The node tag.382383// The node data.384385// The scalar parameters (for yaml_SCALAR_NODE).386scalar struct {387value []byte // The scalar value.388length int // The length of the scalar value.389style yaml_scalar_style_t // The scalar style.390}391392// The sequence parameters (for YAML_SEQUENCE_NODE).393sequence struct {394items_data []yaml_node_item_t // The stack of sequence items.395style yaml_sequence_style_t // The sequence style.396}397398// The mapping parameters (for yaml_MAPPING_NODE).399mapping struct {400pairs_data []yaml_node_pair_t // The stack of mapping pairs (key, value).401pairs_start *yaml_node_pair_t // The beginning of the stack.402pairs_end *yaml_node_pair_t // The end of the stack.403pairs_top *yaml_node_pair_t // The top of the stack.404style yaml_mapping_style_t // The mapping style.405}406407start_mark yaml_mark_t // The beginning of the node.408end_mark yaml_mark_t // The end of the node.409410}411412// The document structure.413type yaml_document_t struct {414415// The document nodes.416nodes []yaml_node_t417418// The version directive.419version_directive *yaml_version_directive_t420421// The list of tag directives.422tag_directives_data []yaml_tag_directive_t423tag_directives_start int // The beginning of the tag directives list.424tag_directives_end int // The end of the tag directives list.425426start_implicit int // Is the document start indicator implicit?427end_implicit int // Is the document end indicator implicit?428429// The start/end of the document.430start_mark, end_mark yaml_mark_t431}432433// The prototype of a read handler.434//435// The read handler is called when the parser needs to read more bytes from the436// source. The handler should write not more than size bytes to the buffer.437// The number of written bytes should be set to the size_read variable.438//439// [in,out] data A pointer to an application data specified by440// yaml_parser_set_input().441// [out] buffer The buffer to write the data from the source.442// [in] size The size of the buffer.443// [out] size_read The actual number of bytes read from the source.444//445// On success, the handler should return 1. If the handler failed,446// the returned value should be 0. On EOF, the handler should set the447// size_read to 0 and return 1.448type yaml_read_handler_t func(parser *yaml_parser_t, buffer []byte) (n int, err error)449450// This structure holds information about a potential simple key.451type yaml_simple_key_t struct {452possible bool // Is a simple key possible?453required bool // Is a simple key required?454token_number int // The number of the token.455mark yaml_mark_t // The position mark.456}457458// The states of the parser.459type yaml_parser_state_t int460461const (462yaml_PARSE_STREAM_START_STATE yaml_parser_state_t = iota463464yaml_PARSE_IMPLICIT_DOCUMENT_START_STATE // Expect the beginning of an implicit document.465yaml_PARSE_DOCUMENT_START_STATE // Expect DOCUMENT-START.466yaml_PARSE_DOCUMENT_CONTENT_STATE // Expect the content of a document.467yaml_PARSE_DOCUMENT_END_STATE // Expect DOCUMENT-END.468yaml_PARSE_BLOCK_NODE_STATE // Expect a block node.469yaml_PARSE_BLOCK_NODE_OR_INDENTLESS_SEQUENCE_STATE // Expect a block node or indentless sequence.470yaml_PARSE_FLOW_NODE_STATE // Expect a flow node.471yaml_PARSE_BLOCK_SEQUENCE_FIRST_ENTRY_STATE // Expect the first entry of a block sequence.472yaml_PARSE_BLOCK_SEQUENCE_ENTRY_STATE // Expect an entry of a block sequence.473yaml_PARSE_INDENTLESS_SEQUENCE_ENTRY_STATE // Expect an entry of an indentless sequence.474yaml_PARSE_BLOCK_MAPPING_FIRST_KEY_STATE // Expect the first key of a block mapping.475yaml_PARSE_BLOCK_MAPPING_KEY_STATE // Expect a block mapping key.476yaml_PARSE_BLOCK_MAPPING_VALUE_STATE // Expect a block mapping value.477yaml_PARSE_FLOW_SEQUENCE_FIRST_ENTRY_STATE // Expect the first entry of a flow sequence.478yaml_PARSE_FLOW_SEQUENCE_ENTRY_STATE // Expect an entry of a flow sequence.479yaml_PARSE_FLOW_SEQUENCE_ENTRY_MAPPING_KEY_STATE // Expect a key of an ordered mapping.480yaml_PARSE_FLOW_SEQUENCE_ENTRY_MAPPING_VALUE_STATE // Expect a value of an ordered mapping.481yaml_PARSE_FLOW_SEQUENCE_ENTRY_MAPPING_END_STATE // Expect the and of an ordered mapping entry.482yaml_PARSE_FLOW_MAPPING_FIRST_KEY_STATE // Expect the first key of a flow mapping.483yaml_PARSE_FLOW_MAPPING_KEY_STATE // Expect a key of a flow mapping.484yaml_PARSE_FLOW_MAPPING_VALUE_STATE // Expect a value of a flow mapping.485yaml_PARSE_FLOW_MAPPING_EMPTY_VALUE_STATE // Expect an empty value of a flow mapping.486yaml_PARSE_END_STATE // Expect nothing.487)488489func (ps yaml_parser_state_t) String() string {490switch ps {491case yaml_PARSE_STREAM_START_STATE:492return "yaml_PARSE_STREAM_START_STATE"493case yaml_PARSE_IMPLICIT_DOCUMENT_START_STATE:494return "yaml_PARSE_IMPLICIT_DOCUMENT_START_STATE"495case yaml_PARSE_DOCUMENT_START_STATE:496return "yaml_PARSE_DOCUMENT_START_STATE"497case yaml_PARSE_DOCUMENT_CONTENT_STATE:498return "yaml_PARSE_DOCUMENT_CONTENT_STATE"499case yaml_PARSE_DOCUMENT_END_STATE:500return "yaml_PARSE_DOCUMENT_END_STATE"501case yaml_PARSE_BLOCK_NODE_STATE:502return "yaml_PARSE_BLOCK_NODE_STATE"503case yaml_PARSE_BLOCK_NODE_OR_INDENTLESS_SEQUENCE_STATE:504return "yaml_PARSE_BLOCK_NODE_OR_INDENTLESS_SEQUENCE_STATE"505case yaml_PARSE_FLOW_NODE_STATE:506return "yaml_PARSE_FLOW_NODE_STATE"507case yaml_PARSE_BLOCK_SEQUENCE_FIRST_ENTRY_STATE:508return "yaml_PARSE_BLOCK_SEQUENCE_FIRST_ENTRY_STATE"509case yaml_PARSE_BLOCK_SEQUENCE_ENTRY_STATE:510return "yaml_PARSE_BLOCK_SEQUENCE_ENTRY_STATE"511case yaml_PARSE_INDENTLESS_SEQUENCE_ENTRY_STATE:512return "yaml_PARSE_INDENTLESS_SEQUENCE_ENTRY_STATE"513case yaml_PARSE_BLOCK_MAPPING_FIRST_KEY_STATE:514return "yaml_PARSE_BLOCK_MAPPING_FIRST_KEY_STATE"515case yaml_PARSE_BLOCK_MAPPING_KEY_STATE:516return "yaml_PARSE_BLOCK_MAPPING_KEY_STATE"517case yaml_PARSE_BLOCK_MAPPING_VALUE_STATE:518return "yaml_PARSE_BLOCK_MAPPING_VALUE_STATE"519case yaml_PARSE_FLOW_SEQUENCE_FIRST_ENTRY_STATE:520return "yaml_PARSE_FLOW_SEQUENCE_FIRST_ENTRY_STATE"521case yaml_PARSE_FLOW_SEQUENCE_ENTRY_STATE:522return "yaml_PARSE_FLOW_SEQUENCE_ENTRY_STATE"523case yaml_PARSE_FLOW_SEQUENCE_ENTRY_MAPPING_KEY_STATE:524return "yaml_PARSE_FLOW_SEQUENCE_ENTRY_MAPPING_KEY_STATE"525case yaml_PARSE_FLOW_SEQUENCE_ENTRY_MAPPING_VALUE_STATE:526return "yaml_PARSE_FLOW_SEQUENCE_ENTRY_MAPPING_VALUE_STATE"527case yaml_PARSE_FLOW_SEQUENCE_ENTRY_MAPPING_END_STATE:528return "yaml_PARSE_FLOW_SEQUENCE_ENTRY_MAPPING_END_STATE"529case yaml_PARSE_FLOW_MAPPING_FIRST_KEY_STATE:530return "yaml_PARSE_FLOW_MAPPING_FIRST_KEY_STATE"531case yaml_PARSE_FLOW_MAPPING_KEY_STATE:532return "yaml_PARSE_FLOW_MAPPING_KEY_STATE"533case yaml_PARSE_FLOW_MAPPING_VALUE_STATE:534return "yaml_PARSE_FLOW_MAPPING_VALUE_STATE"535case yaml_PARSE_FLOW_MAPPING_EMPTY_VALUE_STATE:536return "yaml_PARSE_FLOW_MAPPING_EMPTY_VALUE_STATE"537case yaml_PARSE_END_STATE:538return "yaml_PARSE_END_STATE"539}540return "<unknown parser state>"541}542543// This structure holds aliases data.544type yaml_alias_data_t struct {545anchor []byte // The anchor.546index int // The node id.547mark yaml_mark_t // The anchor mark.548}549550// The parser structure.551//552// All members are internal. Manage the structure using the553// yaml_parser_ family of functions.554type yaml_parser_t struct {555556// Error handling557558error yaml_error_type_t // Error type.559560problem string // Error description.561562// The byte about which the problem occurred.563problem_offset int564problem_value int565problem_mark yaml_mark_t566567// The error context.568context string569context_mark yaml_mark_t570571// Reader stuff572573read_handler yaml_read_handler_t // Read handler.574575input_reader io.Reader // File input data.576input []byte // String input data.577input_pos int578579eof bool // EOF flag580581buffer []byte // The working buffer.582buffer_pos int // The current position of the buffer.583584unread int // The number of unread characters in the buffer.585586newlines int // The number of line breaks since last non-break/non-blank character587588raw_buffer []byte // The raw buffer.589raw_buffer_pos int // The current position of the buffer.590591encoding yaml_encoding_t // The input encoding.592593offset int // The offset of the current position (in bytes).594mark yaml_mark_t // The mark of the current position.595596// Comments597598head_comment []byte // The current head comments599line_comment []byte // The current line comments600foot_comment []byte // The current foot comments601tail_comment []byte // Foot comment that happens at the end of a block.602stem_comment []byte // Comment in item preceding a nested structure (list inside list item, etc)603604comments []yaml_comment_t // The folded comments for all parsed tokens605comments_head int606607// Scanner stuff608609stream_start_produced bool // Have we started to scan the input stream?610stream_end_produced bool // Have we reached the end of the input stream?611612flow_level int // The number of unclosed '[' and '{' indicators.613614tokens []yaml_token_t // The tokens queue.615tokens_head int // The head of the tokens queue.616tokens_parsed int // The number of tokens fetched from the queue.617token_available bool // Does the tokens queue contain a token ready for dequeueing.618619indent int // The current indentation level.620indents []int // The indentation levels stack.621622simple_key_allowed bool // May a simple key occur at the current position?623simple_keys []yaml_simple_key_t // The stack of simple keys.624simple_keys_by_tok map[int]int // possible simple_key indexes indexed by token_number625626// Parser stuff627628state yaml_parser_state_t // The current parser state.629states []yaml_parser_state_t // The parser states stack.630marks []yaml_mark_t // The stack of marks.631tag_directives []yaml_tag_directive_t // The list of TAG directives.632633// Dumper stuff634635aliases []yaml_alias_data_t // The alias data.636637document *yaml_document_t // The currently parsed document.638}639640type yaml_comment_t struct {641642scan_mark yaml_mark_t // Position where scanning for comments started643token_mark yaml_mark_t // Position after which tokens will be associated with this comment644start_mark yaml_mark_t // Position of '#' comment mark645end_mark yaml_mark_t // Position where comment terminated646647head []byte648line []byte649foot []byte650}651652// Emitter Definitions653654// The prototype of a write handler.655//656// The write handler is called when the emitter needs to flush the accumulated657// characters to the output. The handler should write @a size bytes of the658// @a buffer to the output.659//660// @param[in,out] data A pointer to an application data specified by661// yaml_emitter_set_output().662// @param[in] buffer The buffer with bytes to be written.663// @param[in] size The size of the buffer.664//665// @returns On success, the handler should return @c 1. If the handler failed,666// the returned value should be @c 0.667//668type yaml_write_handler_t func(emitter *yaml_emitter_t, buffer []byte) error669670type yaml_emitter_state_t int671672// The emitter states.673const (674// Expect STREAM-START.675yaml_EMIT_STREAM_START_STATE yaml_emitter_state_t = iota676677yaml_EMIT_FIRST_DOCUMENT_START_STATE // Expect the first DOCUMENT-START or STREAM-END.678yaml_EMIT_DOCUMENT_START_STATE // Expect DOCUMENT-START or STREAM-END.679yaml_EMIT_DOCUMENT_CONTENT_STATE // Expect the content of a document.680yaml_EMIT_DOCUMENT_END_STATE // Expect DOCUMENT-END.681yaml_EMIT_FLOW_SEQUENCE_FIRST_ITEM_STATE // Expect the first item of a flow sequence.682yaml_EMIT_FLOW_SEQUENCE_TRAIL_ITEM_STATE // Expect the next item of a flow sequence, with the comma already written out683yaml_EMIT_FLOW_SEQUENCE_ITEM_STATE // Expect an item of a flow sequence.684yaml_EMIT_FLOW_MAPPING_FIRST_KEY_STATE // Expect the first key of a flow mapping.685yaml_EMIT_FLOW_MAPPING_TRAIL_KEY_STATE // Expect the next key of a flow mapping, with the comma already written out686yaml_EMIT_FLOW_MAPPING_KEY_STATE // Expect a key of a flow mapping.687yaml_EMIT_FLOW_MAPPING_SIMPLE_VALUE_STATE // Expect a value for a simple key of a flow mapping.688yaml_EMIT_FLOW_MAPPING_VALUE_STATE // Expect a value of a flow mapping.689yaml_EMIT_BLOCK_SEQUENCE_FIRST_ITEM_STATE // Expect the first item of a block sequence.690yaml_EMIT_BLOCK_SEQUENCE_ITEM_STATE // Expect an item of a block sequence.691yaml_EMIT_BLOCK_MAPPING_FIRST_KEY_STATE // Expect the first key of a block mapping.692yaml_EMIT_BLOCK_MAPPING_KEY_STATE // Expect the key of a block mapping.693yaml_EMIT_BLOCK_MAPPING_SIMPLE_VALUE_STATE // Expect a value for a simple key of a block mapping.694yaml_EMIT_BLOCK_MAPPING_VALUE_STATE // Expect a value of a block mapping.695yaml_EMIT_END_STATE // Expect nothing.696)697698// The emitter structure.699//700// All members are internal. Manage the structure using the @c yaml_emitter_701// family of functions.702type yaml_emitter_t struct {703704// Error handling705706error yaml_error_type_t // Error type.707problem string // Error description.708709// Writer stuff710711write_handler yaml_write_handler_t // Write handler.712713output_buffer *[]byte // String output data.714output_writer io.Writer // File output data.715716buffer []byte // The working buffer.717buffer_pos int // The current position of the buffer.718719raw_buffer []byte // The raw buffer.720raw_buffer_pos int // The current position of the buffer.721722encoding yaml_encoding_t // The stream encoding.723724// Emitter stuff725726canonical bool // If the output is in the canonical style?727best_indent int // The number of indentation spaces.728best_width int // The preferred width of the output lines.729unicode bool // Allow unescaped non-ASCII characters?730line_break yaml_break_t // The preferred line break.731732state yaml_emitter_state_t // The current emitter state.733states []yaml_emitter_state_t // The stack of states.734735events []yaml_event_t // The event queue.736events_head int // The head of the event queue.737738indents []int // The stack of indentation levels.739740tag_directives []yaml_tag_directive_t // The list of tag directives.741742indent int // The current indentation level.743744flow_level int // The current flow level.745746root_context bool // Is it the document root context?747sequence_context bool // Is it a sequence context?748mapping_context bool // Is it a mapping context?749simple_key_context bool // Is it a simple mapping key context?750751line int // The current line.752column int // The current column.753whitespace bool // If the last character was a whitespace?754indention bool // If the last character was an indentation character (' ', '-', '?', ':')?755open_ended bool // If an explicit document end is required?756757space_above bool // Is there's an empty line above?758foot_indent int // The indent used to write the foot comment above, or -1 if none.759760// Anchor analysis.761anchor_data struct {762anchor []byte // The anchor value.763alias bool // Is it an alias?764}765766// Tag analysis.767tag_data struct {768handle []byte // The tag handle.769suffix []byte // The tag suffix.770}771772// Scalar analysis.773scalar_data struct {774value []byte // The scalar value.775multiline bool // Does the scalar contain line breaks?776flow_plain_allowed bool // Can the scalar be expessed in the flow plain style?777block_plain_allowed bool // Can the scalar be expressed in the block plain style?778single_quoted_allowed bool // Can the scalar be expressed in the single quoted style?779block_allowed bool // Can the scalar be expressed in the literal or folded styles?780style yaml_scalar_style_t // The output style.781}782783// Comments784head_comment []byte785line_comment []byte786foot_comment []byte787tail_comment []byte788789key_line_comment []byte790791// Dumper stuff792793opened bool // If the stream was already opened?794closed bool // If the stream was already closed?795796// The information associated with the document nodes.797anchors *struct {798references int // The number of references.799anchor int // The anchor id.800serialized bool // If the node has been emitted?801}802803last_anchor_id int // The last assigned anchor id.804805document *yaml_document_t // The currently emitted document.806}807808809