Documentation
¶
Index ¶
- Constants
- func DefaultDepthCheck(depth int, ctx *DepthContext) error
- func ParseYAMLScriptEvents(input string) (any, error)
- func ParserGetEvents(in []byte) (string, error)
- func StartCompileProgress(pending, success, failure string) func(bool)
- func WriteNewTextFile(path, text string, mode int64) error
- func WriteTextFile(path, text string, mode int64) error
- type AliasData
- type Comment
- type Composer
- type DepthContext
- type DepthKind
- type DumpError
- type EmitterError
- type Encoding
- type ErrorType
- type Event
- func (e *Event) Delete()
- func (e *Event) GetEncoding() Encoding
- func (e *Event) GetQuotedImplicit() bool
- func (e *Event) GetTagDirectives() []TagDirective
- func (e *Event) GetVersionDirective() *VersionDirective
- func (e *Event) MappingStyle() MappingStyle
- func (e *Event) ScalarStyle() ScalarStyle
- func (e *Event) SequenceStyle() SequenceStyle
- type EventType
- type IndentConfig
- type IndentMode
- type IndentScope
- type IndentStyle
- type LineBreak
- type LoadError
- type LoadErrors
- type MappingStyle
- type Mark
- type Parser
- func (parser *Parser) Delete()
- func (parser *Parser) GetCommentsHead() int
- func (parser *Parser) GetPendingComments() []Comment
- func (parser *Parser) Parse(event *Event) error
- func (parser *Parser) Scan(token *Token) error
- func (parser *Parser) SetEncoding(encoding Encoding)
- func (parser *Parser) SetIndentConfig(config *IndentConfig)
- func (parser *Parser) SetInputEvents(events []Event)
- func (parser *Parser) SetInputReader(r io.Reader)
- func (parser *Parser) SetInputString(input []byte)
- func (parser *Parser) SetInputTokens(tokens []Token, comments []Comment)
- func (parser *Parser) SetSkipComments(skip bool)
- func (parser *Parser) UnfoldComments(token *Token)
- type ParserState
- type QuoteStyle
- type ReadHandler
- type ScalarStyle
- type SequenceStyle
- type SimpleKey
- type Stage
- type Style
- type TagDirective
- type Token
- func (t *Token) GetEncoding() Encoding
- func (t *Token) GetPrefix() string
- func (t *Token) GetSuffix() string
- func (t *Token) GetVersion() (int, int)
- func (t *Token) SetEncoding(encoding Encoding)
- func (t *Token) SetPrefix(prefix string)
- func (t *Token) SetSuffix(suffix string)
- func (t *Token) SetVersion(major, minor int)
- type TokenType
- type TypeErrordeprecated
- type VersionDirective
- type WriterError
- type YAMLError
Constants ¶
const ( NULL_TAG = "tag:yaml.org,2002:null" // The tag !!null with the only possible value: null. BOOL_TAG = "tag:yaml.org,2002:bool" // The tag !!bool with the values: true and false. STR_TAG = "tag:yaml.org,2002:str" // The tag !!str for string values. INT_TAG = "tag:yaml.org,2002:int" // The tag !!int for integer values. FLOAT_TAG = "tag:yaml.org,2002:float" // The tag !!float for float values. TIMESTAMP_TAG = "tag:yaml.org,2002:timestamp" // The tag !!timestamp for date and time values. SEQ_TAG = "tag:yaml.org,2002:seq" // The tag !!seq is used to denote sequences. MAP_TAG = "tag:yaml.org,2002:map" // The tag !!map is used to denote mapping. // Not in original libyaml. BINARY_TAG = "tag:yaml.org,2002:binary" MERGE_TAG = "tag:yaml.org,2002:merge" DEFAULT_SCALAR_TAG = STR_TAG // The default scalar tag is !!str. DEFAULT_SEQUENCE_TAG = SEQ_TAG // The default sequence tag is !!seq. DEFAULT_MAPPING_TAG = MAP_TAG // The default mapping tag is !!map. )
Nodes
Variables ¶
This section is empty.
Functions ¶
func DefaultDepthCheck ¶
func DefaultDepthCheck(depth int, ctx *DepthContext) error
func ParseYAMLScriptEvents ¶
func ParserGetEvents ¶
ParserGetEvents parses the YAML input and returns the generated event stream.
func StartCompileProgress ¶
StartCompileProgress returns a completion callback that stops its ticker.
func WriteNewTextFile ¶
WriteNewTextFile writes compiled source without replacing an existing path.
func WriteTextFile ¶
Types ¶
type AliasData ¶
type AliasData struct {
// contains filtered or unexported fields
}
AliasData holds information about aliases.
type Comment ¶
type Comment struct {
ScanMark Mark // Position where scanning for comments started
TokenMark Mark // Position after which tokens will be associated with this comment
StartMark Mark // Position of '#' comment mark
EndMark Mark // Position where comment terminated
Head []byte
Line []byte
Foot []byte
}
Comment holds information about a comment in the YAML stream.
type DepthContext ¶
type DepthContext struct {
Kind DepthKind
}
type DumpError ¶
type DumpError struct {
Stage Stage // Processing stage where error occurred
Message string // Error description
// contains filtered or unexported fields
}
DumpError represents an error that occurred while dumping a YAML document.
It identifies the processing stage where the error occurred and provides an optional underlying cause via Unwrap.
func NewDumpError ¶
NewDumpError creates a DumpError with an underlying cause. The cause is accessible via Unwrap for use with errors.Is and errors.As.
type EmitterError ¶
type EmitterError struct {
Message string
}
EmitterError represents an error that occurred during emitting.
type ErrorType ¶
type ErrorType int
ErrorType represents the category of error that occurred during processing.
const ( // No error is produced. NO_ERROR ErrorType = iota MEMORY_ERROR // Cannot allocate or reallocate a block of memory. READER_ERROR // Cannot read or decode the input stream. SCANNER_ERROR // Cannot scan the input stream. PARSER_ERROR // Cannot parse the input stream. COMPOSER_ERROR // Cannot compose a YAML document. WRITER_ERROR // Cannot write to the output stream. EMITTER_ERROR // Cannot emit a YAML stream. )
Many bad things could happen with the parser and emitter.
type Event ¶
type Event struct {
// The event type.
Type EventType
// The start and end of the event.
StartMark, EndMark Mark
// The comments
HeadComment []byte
LineComment []byte
FootComment []byte
TailComment []byte
// The Anchor (for SCALAR_EVENT, SEQUENCE_START_EVENT, MAPPING_START_EVENT, ALIAS_EVENT).
Anchor []byte
// The Tag (for SCALAR_EVENT, SEQUENCE_START_EVENT, MAPPING_START_EVENT).
Tag []byte
// The scalar Value (for SCALAR_EVENT).
Value []byte
// Is the document start/end indicator Implicit, or the tag optional?
// (for DOCUMENT_START_EVENT, DOCUMENT_END_EVENT, SEQUENCE_START_EVENT, MAPPING_START_EVENT, SCALAR_EVENT).
Implicit bool
// The Style (for SCALAR_EVENT, SEQUENCE_START_EVENT, MAPPING_START_EVENT).
Style Style
// contains filtered or unexported fields
}
Event holds information about a parsing or emitting event.
func (*Event) GetEncoding ¶
GetEncoding returns the stream encoding (for STREAM_START_EVENT).
func (*Event) GetQuotedImplicit ¶
GetQuotedImplicit reports whether a scalar tag may be omitted for a non-plain scalar style.
func (*Event) GetTagDirectives ¶
func (e *Event) GetTagDirectives() []TagDirective
GetTagDirectives returns the tag directives (for DOCUMENT_START_EVENT).
func (*Event) GetVersionDirective ¶
func (e *Event) GetVersionDirective() *VersionDirective
GetVersionDirective returns the version directive (for DOCUMENT_START_EVENT).
func (*Event) MappingStyle ¶
func (e *Event) MappingStyle() MappingStyle
MappingStyle returns the style of a mapping event.
func (*Event) ScalarStyle ¶
func (e *Event) ScalarStyle() ScalarStyle
ScalarStyle returns the style of a scalar event.
func (*Event) SequenceStyle ¶
func (e *Event) SequenceStyle() SequenceStyle
SequenceStyle returns the style of a sequence event.
type EventType ¶
type EventType int8
EventType represents the type of a parsing or emitting event.
const ( // An empty event. NO_EVENT EventType = iota STREAM_START_EVENT // A STREAM-START event. STREAM_END_EVENT // A STREAM-END event. DOCUMENT_START_EVENT // A DOCUMENT-START event. DOCUMENT_END_EVENT // A DOCUMENT-END event. ALIAS_EVENT // An ALIAS event. SCALAR_EVENT // A SCALAR event. SEQUENCE_START_EVENT // A SEQUENCE-START event. SEQUENCE_END_EVENT // A SEQUENCE-END event. MAPPING_START_EVENT // A MAPPING-START event. MAPPING_END_EVENT // A MAPPING-END event. TAIL_COMMENT_EVENT )
Event types.
type IndentConfig ¶
type IndentConfig struct {
Mode IndentMode
LoadStyle IndentStyle
DumpStyle IndentStyle
Scope IndentScope
}
type IndentMode ¶
type IndentMode string
const ( IndentModeAuto IndentMode = "auto" IndentModeTabs IndentMode = "tabs" )
type IndentScope ¶
type IndentScope string
const ( IndentScopeDocument IndentScope = "document" IndentScopeStream IndentScope = "stream" )
type IndentStyle ¶
type IndentStyle string
const ( IndentStyleAuto IndentStyle = "auto" IndentStyleSpaces IndentStyle = "spaces" IndentStyleTabs IndentStyle = "tabs" )
type LoadError ¶
type LoadError struct {
Stage Stage // Processing stage where error occurred
Message string // Error description
// Position information
Mark Mark // Primary error position
ContextMark Mark // Optional context position (e.g., start of construct)
ContextMsg string // Optional context message
// contains filtered or unexported fields
}
LoadError represents an error that occurred while loading a YAML document.
It provides detailed location information and identifies the processing stage where the error occurred.
func NewLoadError ¶
NewLoadError creates a LoadError with an underlying cause. The cause is accessible via Unwrap for use with errors.Is and errors.As.
type LoadErrors ¶
type LoadErrors struct {
Errors []*LoadError
}
LoadErrors is returned when one or more fields cannot be properly decoded.
func (*LoadErrors) As ¶
func (e *LoadErrors) As(target any) bool
As implements errors.As for Go versions prior to 1.20 that don't support the Unwrap() []error interface. It allows LoadErrors to match against *LoadError or *TypeError targets.
func (*LoadErrors) Error ¶
func (e *LoadErrors) Error() string
Error returns a formatted error message listing all construct errors.
type MappingStyle ¶
type MappingStyle styleInt
MappingStyle represents the formatting style of a mapping node.
const ( // Let the emitter choose the style. ANY_MAPPING_STYLE MappingStyle = iota BLOCK_MAPPING_STYLE // The block mapping style. FLOW_MAPPING_STYLE // The flow mapping style. )
Mapping styles.
type Mark ¶
type Mark struct {
Index int // The position index.
Line int // The position line (1-indexed; 0 means unknown).
Column int // The position column (1-indexed; 0 means unknown).
}
Mark holds the pointer position.
type Parser ¶
type Parser struct {
HeadComment []byte // The current head comments
LineComment []byte // The current line comments
FootComment []byte // The current foot comments
// contains filtered or unexported fields
}
Parser structure holds all information about the current state of the parser.
func (*Parser) GetCommentsHead ¶
GetCommentsHead returns the current position in the comment queue.
func (*Parser) GetPendingComments ¶
GetPendingComments returns the parser's comment queue for CLI access.
func (*Parser) SetEncoding ¶
SetEncoding sets the source encoding.
func (*Parser) SetIndentConfig ¶
func (parser *Parser) SetIndentConfig(config *IndentConfig)
SetIndentConfig configures tab-aware indentation scanning.
func (*Parser) SetInputEvents ¶
SetInputEvents sets a pre-parsed event stream. It is intended for internal pipeline tooling that needs to resume processing at the composer stage.
func (*Parser) SetInputReader ¶
SetInputReader sets a file input.
func (*Parser) SetInputString ¶
SetInputString sets a string input.
func (*Parser) SetInputTokens ¶
SetInputTokens sets a pre-tokenized input stream. It is intended for internal pipeline tooling that needs to resume processing at the parser stage.
func (*Parser) SetSkipComments ¶
SetSkipComments enables or disables comment scanning. When enabled, the scanner skips comment tokens for better performance.
func (*Parser) UnfoldComments ¶
UnfoldComments walks through the comments queue and joins all comments behind the position of the provided token into the respective top-level comment slices in the parser.
type ParserState ¶
type ParserState int
ParserState represents the state of the parser.
const ( PARSE_STREAM_START_STATE ParserState = iota PARSE_IMPLICIT_DOCUMENT_START_STATE // Expect the beginning of an implicit document. PARSE_DOCUMENT_START_STATE // Expect DOCUMENT-START. PARSE_DOCUMENT_CONTENT_STATE // Expect the content of a document. PARSE_DOCUMENT_END_STATE // Expect DOCUMENT-END. PARSE_BLOCK_NODE_STATE // Expect a block node. PARSE_BLOCK_SEQUENCE_FIRST_ENTRY_STATE // Expect the first entry of a block sequence. PARSE_BLOCK_SEQUENCE_ENTRY_STATE // Expect an entry of a block sequence. PARSE_INDENTLESS_SEQUENCE_ENTRY_STATE // Expect an entry of an indentless sequence. PARSE_BLOCK_MAPPING_FIRST_KEY_STATE // Expect the first key of a block mapping. PARSE_BLOCK_MAPPING_KEY_STATE // Expect a block mapping key. PARSE_BLOCK_MAPPING_VALUE_STATE // Expect a block mapping value. PARSE_FLOW_SEQUENCE_FIRST_ENTRY_STATE // Expect the first entry of a flow sequence. PARSE_FLOW_SEQUENCE_ENTRY_STATE // Expect an entry of a flow sequence. PARSE_FLOW_SEQUENCE_ENTRY_MAPPING_KEY_STATE // Expect a key of an ordered mapping. PARSE_FLOW_SEQUENCE_ENTRY_MAPPING_VALUE_STATE // Expect a value of an ordered mapping. PARSE_FLOW_SEQUENCE_ENTRY_MAPPING_END_STATE // Expect the and of an ordered mapping entry. PARSE_FLOW_MAPPING_FIRST_KEY_STATE // Expect the first key of a flow mapping. PARSE_FLOW_MAPPING_KEY_STATE // Expect a key of a flow mapping. PARSE_FLOW_MAPPING_VALUE_STATE // Expect a value of a flow mapping. PARSE_FLOW_MAPPING_EMPTY_VALUE_STATE // Expect an empty value of a flow mapping. PARSE_END_STATE // Expect nothing. )
Parser state constants define the different states the parser can be in.
func (ParserState) String ¶
func (ps ParserState) String() string
String returns a string representation of the parser state.
type QuoteStyle ¶
type QuoteStyle int
QuoteStyle represents the preferred quote style for scalar values.
const ( QuoteSingle QuoteStyle = iota // Prefer single quotes when quoting is required. QuoteDouble // Prefer double quotes when quoting is required. QuoteLegacy // Legacy behavior: double in representer, single in emitter. )
Quote style types for required quoting.
func (QuoteStyle) ScalarStyle ¶
func (q QuoteStyle) ScalarStyle() ScalarStyle
ScalarStyle returns the scalar style for this quote preference in the representer/serializer context. In this context, both QuoteDouble and QuoteLegacy use double quotes.
type ReadHandler ¶
ReadHandler is called by the Parser when it needs to read more bytes from the input source. The handler should fill the provided buffer with up to len(buffer) bytes from the input source.
The arguments are as follows:
[in] parser The parser object. [out] buffer The buffer for reading. [out] size_read The actual number of bytes read from the source.
On success, the handler should return 1. If the handler failed, the returned value should be 0. On EOF, the handler should set the size_read to 0 and return 1.
type ScalarStyle ¶
type ScalarStyle styleInt
ScalarStyle represents the formatting style of a scalar value.
const ( // Let the emitter choose the style. ANY_SCALAR_STYLE ScalarStyle = 0 PLAIN_SCALAR_STYLE ScalarStyle = 1 << iota // The plain scalar style. SINGLE_QUOTED_SCALAR_STYLE // The single-quoted scalar style. DOUBLE_QUOTED_SCALAR_STYLE // The double-quoted scalar style. LITERAL_SCALAR_STYLE // The literal scalar style. FOLDED_SCALAR_STYLE // The folded scalar style. )
Scalar styles.
func (ScalarStyle) String ¶
func (style ScalarStyle) String() string
String returns a string representation of a ScalarStyle.
type SequenceStyle ¶
type SequenceStyle styleInt
SequenceStyle represents the formatting style of a sequence node.
const ( // Let the emitter choose the style. ANY_SEQUENCE_STYLE SequenceStyle = iota BLOCK_SEQUENCE_STYLE // The block sequence style. FLOW_SEQUENCE_STYLE // The flow sequence style. )
Sequence styles.
type SimpleKey ¶
type SimpleKey struct {
// contains filtered or unexported fields
}
SimpleKey holds information about a potential simple key.
type Stage ¶
type Stage string
Stage identifies the processing stage where an error occurred during YAML loading or dumping.
const ( // Load stages ReaderStage Stage = "reader" // Input reading and encoding ScannerStage Stage = "scanner" // Tokenization ParserStage Stage = "parser" // Event stream parsing ComposerStage Stage = "composer" // Node tree construction ResolverStage Stage = "resolver" // Tag resolution ConstructorStage Stage = "constructor" // Go value construction // Dump stages RepresenterStage Stage = "representer" // Go value to Node tree SerializerStage Stage = "serializer" // Node tree to events EmitterStage Stage = "emitter" // Events to YAML bytes WriterStage Stage = "writer" // Output writing )
type TagDirective ¶
type TagDirective struct {
// contains filtered or unexported fields
}
TagDirective holds the YAML tag directive data.
func NewTagDirective ¶
func NewTagDirective(handle, prefix string) TagDirective
NewTagDirective creates YAML tag directive data.
func (*TagDirective) GetHandle ¶
func (t *TagDirective) GetHandle() string
GetHandle returns the tag handle.
func (*TagDirective) GetPrefix ¶
func (t *TagDirective) GetPrefix() string
GetPrefix returns the tag prefix.
type Token ¶
type Token struct {
// The token type.
Type TokenType
// The start/end of the token.
StartMark, EndMark Mark
// The alias/anchor/scalar Value or tag/tag directive handle
// (for ALIAS_TOKEN, ANCHOR_TOKEN, SCALAR_TOKEN, TAG_TOKEN, TAG_DIRECTIVE_TOKEN).
Value []byte
// The scalar Style (for SCALAR_TOKEN).
Style ScalarStyle
// contains filtered or unexported fields
}
Token holds information about a scanning token.
func (*Token) GetEncoding ¶
GetEncoding returns the stream encoding carried by a STREAM-START token.
func (*Token) GetVersion ¶
GetVersion returns the version carried by a VERSION-DIRECTIVE token.
func (*Token) SetEncoding ¶
SetEncoding sets the stream encoding carried by a STREAM-START token.
func (*Token) SetVersion ¶
SetVersion sets the version carried by a VERSION-DIRECTIVE token.
type TokenType ¶
type TokenType int
TokenType represents the type of a scanned token.
const ( // An empty token. NO_TOKEN TokenType = iota STREAM_START_TOKEN // A STREAM-START token. STREAM_END_TOKEN // A STREAM-END token. VERSION_DIRECTIVE_TOKEN // A VERSION-DIRECTIVE token. TAG_DIRECTIVE_TOKEN // A TAG-DIRECTIVE token. DOCUMENT_START_TOKEN // A DOCUMENT-START token. DOCUMENT_END_TOKEN // A DOCUMENT-END token. BLOCK_SEQUENCE_START_TOKEN // A BLOCK-SEQUENCE-START token. BLOCK_MAPPING_START_TOKEN // A BLOCK-SEQUENCE-END token. BLOCK_END_TOKEN // A BLOCK-END token. FLOW_SEQUENCE_START_TOKEN // A FLOW-SEQUENCE-START token. FLOW_SEQUENCE_END_TOKEN // A FLOW-SEQUENCE-END token. FLOW_MAPPING_START_TOKEN // A FLOW-MAPPING-START token. FLOW_MAPPING_END_TOKEN // A FLOW-MAPPING-END token. BLOCK_ENTRY_TOKEN // A BLOCK-ENTRY token. FLOW_ENTRY_TOKEN // A FLOW-ENTRY token. KEY_TOKEN // A KEY token. VALUE_TOKEN // A VALUE token. ALIAS_TOKEN // An ALIAS token. ANCHOR_TOKEN // An ANCHOR token. TAG_TOKEN // A TAG token. SCALAR_TOKEN // A SCALAR token. COMMENT_TOKEN // A COMMENT token. )
Token types.
type TypeError
deprecated
type TypeError struct {
Errors []string
}
TypeError is a legacy error type retained for compatibility.
A TypeError is returned by Unmarshal when one or more fields in the YAML document cannot be properly decoded into the requested types. When this error is returned, the value is still unmarshaled partially.
Deprecated: Use LoadErrors instead.
type VersionDirective ¶
type VersionDirective struct {
// contains filtered or unexported fields
}
VersionDirective holds the YAML version directive data.
func NewVersionDirective ¶
func NewVersionDirective(major, minor int) *VersionDirective
NewVersionDirective creates YAML version directive data.
func (*VersionDirective) Major ¶
func (v *VersionDirective) Major() int
Major returns the major version number.
func (*VersionDirective) Minor ¶
func (v *VersionDirective) Minor() int
Minor returns the minor version number.
type WriterError ¶
type WriterError struct {
Err error
}
WriterError represents an error that occurred while writing output.
func (WriterError) Unwrap ¶
func (e WriterError) Unwrap() error
Unwrap returns the underlying error.