Path: blob/main/vendor/go.yaml.in/yaml/v3/yamlh.go
2872 views
//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//441// yaml_parser_set_input().442//443// [out] buffer The buffer to write the data from the source.444// [in] size The size of the buffer.445// [out] size_read The actual number of bytes read from the source.446//447// On success, the handler should return 1. If the handler failed,448// the returned value should be 0. On EOF, the handler should set the449// size_read to 0 and return 1.450type yaml_read_handler_t func(parser *yaml_parser_t, buffer []byte) (n int, err error)451452// This structure holds information about a potential simple key.453type yaml_simple_key_t struct {454possible bool // Is a simple key possible?455required bool // Is a simple key required?456token_number int // The number of the token.457mark yaml_mark_t // The position mark.458}459460// The states of the parser.461type yaml_parser_state_t int462463const (464yaml_PARSE_STREAM_START_STATE yaml_parser_state_t = iota465466yaml_PARSE_IMPLICIT_DOCUMENT_START_STATE // Expect the beginning of an implicit document.467yaml_PARSE_DOCUMENT_START_STATE // Expect DOCUMENT-START.468yaml_PARSE_DOCUMENT_CONTENT_STATE // Expect the content of a document.469yaml_PARSE_DOCUMENT_END_STATE // Expect DOCUMENT-END.470yaml_PARSE_BLOCK_NODE_STATE // Expect a block node.471yaml_PARSE_BLOCK_NODE_OR_INDENTLESS_SEQUENCE_STATE // Expect a block node or indentless sequence.472yaml_PARSE_FLOW_NODE_STATE // Expect a flow node.473yaml_PARSE_BLOCK_SEQUENCE_FIRST_ENTRY_STATE // Expect the first entry of a block sequence.474yaml_PARSE_BLOCK_SEQUENCE_ENTRY_STATE // Expect an entry of a block sequence.475yaml_PARSE_INDENTLESS_SEQUENCE_ENTRY_STATE // Expect an entry of an indentless sequence.476yaml_PARSE_BLOCK_MAPPING_FIRST_KEY_STATE // Expect the first key of a block mapping.477yaml_PARSE_BLOCK_MAPPING_KEY_STATE // Expect a block mapping key.478yaml_PARSE_BLOCK_MAPPING_VALUE_STATE // Expect a block mapping value.479yaml_PARSE_FLOW_SEQUENCE_FIRST_ENTRY_STATE // Expect the first entry of a flow sequence.480yaml_PARSE_FLOW_SEQUENCE_ENTRY_STATE // Expect an entry of a flow sequence.481yaml_PARSE_FLOW_SEQUENCE_ENTRY_MAPPING_KEY_STATE // Expect a key of an ordered mapping.482yaml_PARSE_FLOW_SEQUENCE_ENTRY_MAPPING_VALUE_STATE // Expect a value of an ordered mapping.483yaml_PARSE_FLOW_SEQUENCE_ENTRY_MAPPING_END_STATE // Expect the and of an ordered mapping entry.484yaml_PARSE_FLOW_MAPPING_FIRST_KEY_STATE // Expect the first key of a flow mapping.485yaml_PARSE_FLOW_MAPPING_KEY_STATE // Expect a key of a flow mapping.486yaml_PARSE_FLOW_MAPPING_VALUE_STATE // Expect a value of a flow mapping.487yaml_PARSE_FLOW_MAPPING_EMPTY_VALUE_STATE // Expect an empty value of a flow mapping.488yaml_PARSE_END_STATE // Expect nothing.489)490491func (ps yaml_parser_state_t) String() string {492switch ps {493case yaml_PARSE_STREAM_START_STATE:494return "yaml_PARSE_STREAM_START_STATE"495case yaml_PARSE_IMPLICIT_DOCUMENT_START_STATE:496return "yaml_PARSE_IMPLICIT_DOCUMENT_START_STATE"497case yaml_PARSE_DOCUMENT_START_STATE:498return "yaml_PARSE_DOCUMENT_START_STATE"499case yaml_PARSE_DOCUMENT_CONTENT_STATE:500return "yaml_PARSE_DOCUMENT_CONTENT_STATE"501case yaml_PARSE_DOCUMENT_END_STATE:502return "yaml_PARSE_DOCUMENT_END_STATE"503case yaml_PARSE_BLOCK_NODE_STATE:504return "yaml_PARSE_BLOCK_NODE_STATE"505case yaml_PARSE_BLOCK_NODE_OR_INDENTLESS_SEQUENCE_STATE:506return "yaml_PARSE_BLOCK_NODE_OR_INDENTLESS_SEQUENCE_STATE"507case yaml_PARSE_FLOW_NODE_STATE:508return "yaml_PARSE_FLOW_NODE_STATE"509case yaml_PARSE_BLOCK_SEQUENCE_FIRST_ENTRY_STATE:510return "yaml_PARSE_BLOCK_SEQUENCE_FIRST_ENTRY_STATE"511case yaml_PARSE_BLOCK_SEQUENCE_ENTRY_STATE:512return "yaml_PARSE_BLOCK_SEQUENCE_ENTRY_STATE"513case yaml_PARSE_INDENTLESS_SEQUENCE_ENTRY_STATE:514return "yaml_PARSE_INDENTLESS_SEQUENCE_ENTRY_STATE"515case yaml_PARSE_BLOCK_MAPPING_FIRST_KEY_STATE:516return "yaml_PARSE_BLOCK_MAPPING_FIRST_KEY_STATE"517case yaml_PARSE_BLOCK_MAPPING_KEY_STATE:518return "yaml_PARSE_BLOCK_MAPPING_KEY_STATE"519case yaml_PARSE_BLOCK_MAPPING_VALUE_STATE:520return "yaml_PARSE_BLOCK_MAPPING_VALUE_STATE"521case yaml_PARSE_FLOW_SEQUENCE_FIRST_ENTRY_STATE:522return "yaml_PARSE_FLOW_SEQUENCE_FIRST_ENTRY_STATE"523case yaml_PARSE_FLOW_SEQUENCE_ENTRY_STATE:524return "yaml_PARSE_FLOW_SEQUENCE_ENTRY_STATE"525case yaml_PARSE_FLOW_SEQUENCE_ENTRY_MAPPING_KEY_STATE:526return "yaml_PARSE_FLOW_SEQUENCE_ENTRY_MAPPING_KEY_STATE"527case yaml_PARSE_FLOW_SEQUENCE_ENTRY_MAPPING_VALUE_STATE:528return "yaml_PARSE_FLOW_SEQUENCE_ENTRY_MAPPING_VALUE_STATE"529case yaml_PARSE_FLOW_SEQUENCE_ENTRY_MAPPING_END_STATE:530return "yaml_PARSE_FLOW_SEQUENCE_ENTRY_MAPPING_END_STATE"531case yaml_PARSE_FLOW_MAPPING_FIRST_KEY_STATE:532return "yaml_PARSE_FLOW_MAPPING_FIRST_KEY_STATE"533case yaml_PARSE_FLOW_MAPPING_KEY_STATE:534return "yaml_PARSE_FLOW_MAPPING_KEY_STATE"535case yaml_PARSE_FLOW_MAPPING_VALUE_STATE:536return "yaml_PARSE_FLOW_MAPPING_VALUE_STATE"537case yaml_PARSE_FLOW_MAPPING_EMPTY_VALUE_STATE:538return "yaml_PARSE_FLOW_MAPPING_EMPTY_VALUE_STATE"539case yaml_PARSE_END_STATE:540return "yaml_PARSE_END_STATE"541}542return "<unknown parser state>"543}544545// This structure holds aliases data.546type yaml_alias_data_t struct {547anchor []byte // The anchor.548index int // The node id.549mark yaml_mark_t // The anchor mark.550}551552// The parser structure.553//554// All members are internal. Manage the structure using the555// yaml_parser_ family of functions.556type yaml_parser_t struct {557558// Error handling559560error yaml_error_type_t // Error type.561562problem string // Error description.563564// The byte about which the problem occurred.565problem_offset int566problem_value int567problem_mark yaml_mark_t568569// The error context.570context string571context_mark yaml_mark_t572573// Reader stuff574575read_handler yaml_read_handler_t // Read handler.576577input_reader io.Reader // File input data.578input []byte // String input data.579input_pos int580581eof bool // EOF flag582583buffer []byte // The working buffer.584buffer_pos int // The current position of the buffer.585586unread int // The number of unread characters in the buffer.587588newlines int // The number of line breaks since last non-break/non-blank character589590raw_buffer []byte // The raw buffer.591raw_buffer_pos int // The current position of the buffer.592593encoding yaml_encoding_t // The input encoding.594595offset int // The offset of the current position (in bytes).596mark yaml_mark_t // The mark of the current position.597598// Comments599600head_comment []byte // The current head comments601line_comment []byte // The current line comments602foot_comment []byte // The current foot comments603tail_comment []byte // Foot comment that happens at the end of a block.604stem_comment []byte // Comment in item preceding a nested structure (list inside list item, etc)605606comments []yaml_comment_t // The folded comments for all parsed tokens607comments_head int608609// Scanner stuff610611stream_start_produced bool // Have we started to scan the input stream?612stream_end_produced bool // Have we reached the end of the input stream?613614flow_level int // The number of unclosed '[' and '{' indicators.615616tokens []yaml_token_t // The tokens queue.617tokens_head int // The head of the tokens queue.618tokens_parsed int // The number of tokens fetched from the queue.619token_available bool // Does the tokens queue contain a token ready for dequeueing.620621indent int // The current indentation level.622indents []int // The indentation levels stack.623624simple_key_allowed bool // May a simple key occur at the current position?625simple_keys []yaml_simple_key_t // The stack of simple keys.626simple_keys_by_tok map[int]int // possible simple_key indexes indexed by token_number627628// Parser stuff629630state yaml_parser_state_t // The current parser state.631states []yaml_parser_state_t // The parser states stack.632marks []yaml_mark_t // The stack of marks.633tag_directives []yaml_tag_directive_t // The list of TAG directives.634635// Dumper stuff636637aliases []yaml_alias_data_t // The alias data.638639document *yaml_document_t // The currently parsed document.640}641642type yaml_comment_t struct {643scan_mark yaml_mark_t // Position where scanning for comments started644token_mark yaml_mark_t // Position after which tokens will be associated with this comment645start_mark yaml_mark_t // Position of '#' comment mark646end_mark yaml_mark_t // Position where comment terminated647648head []byte649line []byte650foot []byte651}652653// Emitter Definitions654655// The prototype of a write handler.656//657// The write handler is called when the emitter needs to flush the accumulated658// characters to the output. The handler should write @a size bytes of the659// @a buffer to the output.660//661// @param[in,out] data A pointer to an application data specified by662//663// yaml_emitter_set_output().664//665// @param[in] buffer The buffer with bytes to be written.666// @param[in] size The size of the buffer.667//668// @returns On success, the handler should return @c 1. If the handler failed,669// the returned value should be @c 0.670type yaml_write_handler_t func(emitter *yaml_emitter_t, buffer []byte) error671672type yaml_emitter_state_t int673674// The emitter states.675const (676// Expect STREAM-START.677yaml_EMIT_STREAM_START_STATE yaml_emitter_state_t = iota678679yaml_EMIT_FIRST_DOCUMENT_START_STATE // Expect the first DOCUMENT-START or STREAM-END.680yaml_EMIT_DOCUMENT_START_STATE // Expect DOCUMENT-START or STREAM-END.681yaml_EMIT_DOCUMENT_CONTENT_STATE // Expect the content of a document.682yaml_EMIT_DOCUMENT_END_STATE // Expect DOCUMENT-END.683yaml_EMIT_FLOW_SEQUENCE_FIRST_ITEM_STATE // Expect the first item of a flow sequence.684yaml_EMIT_FLOW_SEQUENCE_TRAIL_ITEM_STATE // Expect the next item of a flow sequence, with the comma already written out685yaml_EMIT_FLOW_SEQUENCE_ITEM_STATE // Expect an item of a flow sequence.686yaml_EMIT_FLOW_MAPPING_FIRST_KEY_STATE // Expect the first key of a flow mapping.687yaml_EMIT_FLOW_MAPPING_TRAIL_KEY_STATE // Expect the next key of a flow mapping, with the comma already written out688yaml_EMIT_FLOW_MAPPING_KEY_STATE // Expect a key of a flow mapping.689yaml_EMIT_FLOW_MAPPING_SIMPLE_VALUE_STATE // Expect a value for a simple key of a flow mapping.690yaml_EMIT_FLOW_MAPPING_VALUE_STATE // Expect a value of a flow mapping.691yaml_EMIT_BLOCK_SEQUENCE_FIRST_ITEM_STATE // Expect the first item of a block sequence.692yaml_EMIT_BLOCK_SEQUENCE_ITEM_STATE // Expect an item of a block sequence.693yaml_EMIT_BLOCK_MAPPING_FIRST_KEY_STATE // Expect the first key of a block mapping.694yaml_EMIT_BLOCK_MAPPING_KEY_STATE // Expect the key of a block mapping.695yaml_EMIT_BLOCK_MAPPING_SIMPLE_VALUE_STATE // Expect a value for a simple key of a block mapping.696yaml_EMIT_BLOCK_MAPPING_VALUE_STATE // Expect a value of a block mapping.697yaml_EMIT_END_STATE // Expect nothing.698)699700// The emitter structure.701//702// All members are internal. Manage the structure using the @c yaml_emitter_703// family of functions.704type yaml_emitter_t struct {705706// Error handling707708error yaml_error_type_t // Error type.709problem string // Error description.710711// Writer stuff712713write_handler yaml_write_handler_t // Write handler.714715output_buffer *[]byte // String output data.716output_writer io.Writer // File output data.717718buffer []byte // The working buffer.719buffer_pos int // The current position of the buffer.720721raw_buffer []byte // The raw buffer.722raw_buffer_pos int // The current position of the buffer.723724encoding yaml_encoding_t // The stream encoding.725726// Emitter stuff727728canonical bool // If the output is in the canonical style?729best_indent int // The number of indentation spaces.730best_width int // The preferred width of the output lines.731unicode bool // Allow unescaped non-ASCII characters?732line_break yaml_break_t // The preferred line break.733734state yaml_emitter_state_t // The current emitter state.735states []yaml_emitter_state_t // The stack of states.736737events []yaml_event_t // The event queue.738events_head int // The head of the event queue.739740indents []int // The stack of indentation levels.741742tag_directives []yaml_tag_directive_t // The list of tag directives.743744indent int // The current indentation level.745746compact_sequence_indent bool // Is '- ' is considered part of the indentation for sequence elements?747748flow_level int // The current flow level.749750root_context bool // Is it the document root context?751sequence_context bool // Is it a sequence context?752mapping_context bool // Is it a mapping context?753simple_key_context bool // Is it a simple mapping key context?754755line int // The current line.756column int // The current column.757whitespace bool // If the last character was a whitespace?758indention bool // If the last character was an indentation character (' ', '-', '?', ':')?759open_ended bool // If an explicit document end is required?760761space_above bool // Is there's an empty line above?762foot_indent int // The indent used to write the foot comment above, or -1 if none.763764// Anchor analysis.765anchor_data struct {766anchor []byte // The anchor value.767alias bool // Is it an alias?768}769770// Tag analysis.771tag_data struct {772handle []byte // The tag handle.773suffix []byte // The tag suffix.774}775776// Scalar analysis.777scalar_data struct {778value []byte // The scalar value.779multiline bool // Does the scalar contain line breaks?780flow_plain_allowed bool // Can the scalar be expessed in the flow plain style?781block_plain_allowed bool // Can the scalar be expressed in the block plain style?782single_quoted_allowed bool // Can the scalar be expressed in the single quoted style?783block_allowed bool // Can the scalar be expressed in the literal or folded styles?784style yaml_scalar_style_t // The output style.785}786787// Comments788head_comment []byte789line_comment []byte790foot_comment []byte791tail_comment []byte792793key_line_comment []byte794795// Dumper stuff796797opened bool // If the stream was already opened?798closed bool // If the stream was already closed?799800// The information associated with the document nodes.801anchors *struct {802references int // The number of references.803anchor int // The anchor id.804serialized bool // If the node has been emitted?805}806807last_anchor_id int // The last assigned anchor id.808809document *yaml_document_t // The currently emitted document.810}811812813