---@meta yaml

--------------------------------------------------------------------------------
-- LibYAML C binding module
--------------------------------------------------------------------------------

---@alias yaml_encoding 'ANY'|'UTF8'|'UTF16LE'|'UTF16BE'
---@alias yaml_scalar_style 'ANY'|'PLAIN'|'SINGLE_QUOTED'|'DOUBLE_QUOTED'|'LITERAL'|'FOLDED'
---@alias yaml_collection_style 'ANY'|'BLOCK'|'FLOW'
---@alias yaml_event_type 'STREAM_START'|'STREAM_END'|'DOCUMENT_START'|'DOCUMENT_END'|'ALIAS'|'SCALAR'|'SEQUENCE_START'|'SEQUENCE_END'|'MAPPING_START'|'MAPPING_END'
---@alias yaml_token_type 'STREAM_START'|'STREAM_END'|'VERSION_DIRECTIVE'|'TAG_DIRECTIVE'|'DOCUMENT_START'|'DOCUMENT_END'|'BLOCK_SEQUENCE_START'|'BLOCK_MAPPING_START'|'BLOCK_END'|'FLOW_SEQUENCE_START'|'FLOW_SEQUENCE_END'|'FLOW_MAPPING_START'|'FLOW_MAPPING_END'|'BLOCK_ENTRY'|'FLOW_ENTRY'|'KEY'|'VALUE'|'ALIAS'|'ANCHOR'|'TAG'|'SCALAR'

---@class yaml_mark*
---@field index integer Byte offset
---@field line integer Line number, starting from 0
---@field column integer Column number, starting from 0

---@class yaml_version_directive*
---@field major integer major version
---@field minor integer minor version

---@class yaml_tag_directive*
---@field handle string tag handle
---@field prefix string tag prefix

---@class yaml_marked*
---@field start_mark? yaml_mark* starting position
---@field end_mark? yaml_mark* end position

---@class yaml_stream_start_event*: yaml_marked*
---@field type 'STREAM_START'
---@field encoding yaml_encoding encoding

---@class yaml_stream_end_event*: yaml_marked*
---@field type 'STREAM_END'

---@class yaml_document_start_event*: yaml_marked*
---@field type 'DOCUMENT_START'
---@field implicit? boolean Whether to start implicitly
---@field version_directive? yaml_version_directive* YAML version directive
---@field tag_directives? yaml_tag_directive*[] tag command list

---@class yaml_document_end_event*: yaml_marked*
---@field type 'DOCUMENT_END'
---@field implicit? boolean Whether to end implicitly

---@class yaml_alias_event*: yaml_marked*
---@field type 'ALIAS'
---@field anchor string Anchor name

---@class yaml_scalar_event*: yaml_marked*
---@field type 'SCALAR'
---@field anchor? string Anchor name
---@field tag? string Complete tag
---@field value string scalar literal
---@field plain_implicit? boolean plain Is the form implicit?
---@field quoted_implicit? boolean quoted Is the form implicit?
---@field style? yaml_scalar_style scalar style

---@class yaml_sequence_start_event*: yaml_marked*
---@field type 'SEQUENCE_START'
---@field anchor? string Anchor name
---@field tag? string Complete tag
---@field implicit? boolean Whether to implicitly tag
---@field style? yaml_collection_style sequence style

---@class yaml_sequence_end_event*: yaml_marked*
---@field type 'SEQUENCE_END'

---@class yaml_mapping_start_event*: yaml_marked*
---@field type 'MAPPING_START'
---@field anchor? string Anchor name
---@field tag? string Complete tag
---@field implicit? boolean Whether to implicitly tag
---@field style? yaml_collection_style Mapping style

---@class yaml_mapping_end_event*: yaml_marked*
---@field type 'MAPPING_END'

---@alias yaml_event yaml_stream_start_event*|yaml_stream_end_event*|yaml_document_start_event*|yaml_document_end_event*|yaml_alias_event*|yaml_scalar_event*|yaml_sequence_start_event*|yaml_sequence_end_event*|yaml_mapping_start_event*|yaml_mapping_end_event*

---@class yaml_stream_start_token*: yaml_marked*
---@field type 'STREAM_START'
---@field encoding yaml_encoding encoding

---@class yaml_simple_token*: yaml_marked*
---@field type yaml_token_type token Type

---@class yaml_version_directive_token*: yaml_marked*
---@field type 'VERSION_DIRECTIVE'
---@field major integer major version
---@field minor integer minor version

---@class yaml_tag_directive_token*: yaml_marked*
---@field type 'TAG_DIRECTIVE'
---@field handle string tag handle
---@field prefix string tag prefix

---@class yaml_alias_token*: yaml_marked*
---@field type 'ALIAS'
---@field value string anchor reference

---@class yaml_anchor_token*: yaml_marked*
---@field type 'ANCHOR'
---@field value string Anchor name

---@class yaml_tag_token*: yaml_marked*
---@field type 'TAG'
---@field handle string tag handle
---@field suffix string tag suffix

---@class yaml_scalar_token*: yaml_marked*
---@field type 'SCALAR'
---@field value string scalar literal
---@field length integer scalar length
---@field style yaml_scalar_style scalar style

---@alias yaml_token yaml_stream_start_token*|yaml_simple_token*|yaml_version_directive_token*|yaml_tag_directive_token*|yaml_alias_token*|yaml_anchor_token*|yaml_tag_token*|yaml_scalar_token*

---@class yaml_emitter*
---@field emit fun(event:yaml_event):boolean,string? Send an event; the second return value is YAML text in case of STREAM_END, and the error message in case of failure.
---@field errthread thread error buffer thread
---@field outputthread thread output buffer thread

---@class yaml*
---@field version string C Binding version information
---@type yaml*
local M = {}

--- Create a YAML token scanner.
---@param s string YAML text
---@return fun():yaml_token? next Each call returns the next token
function M.scanner(s) end

--- Create a YAML event parser.
---@param s string YAML text
---@return fun():yaml_event? next Each call returns the next event
function M.parser(s) end

--- Create a YAML event emitter.
---@return yaml_emitter* emitter event emitter
function M.emitter() end

return M
