Documentation ¶
Overview ¶
Package ast contains types for YAML AST representation.
Index ¶
- func ValidNode(n Node) bool
- type AliasNode
- type AnchorNode
- type BasicNode
- type BlockHeaderNode
- type ChompingType
- type ContentNode
- type IndentNode
- type MappingEntryNode
- type MappingNode
- type Node
- type NodeType
- type NullNode
- type PropertiesNode
- type QuotingType
- type SequenceNode
- type StreamNode
- type TagNode
- type TextNode
- type TextNodeOption
- type Texter
- type TexterNode
- type Visitor
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type AliasNode ¶
type AliasNode struct {
// contains filtered or unexported fields
}
func NewAliasNode ¶
type AnchorNode ¶
type AnchorNode struct {
// contains filtered or unexported fields
}
func NewAnchorNode ¶
func NewAnchorNode(text string) *AnchorNode
func (*AnchorNode) Accept ¶
func (a *AnchorNode) Accept(v Visitor)
func (*AnchorNode) Text ¶
func (a *AnchorNode) Text() string
func (*AnchorNode) Type ¶
func (*AnchorNode) Type() NodeType
type BasicNode ¶
type BasicNode struct {
NodeType NodeType
}
BasicNode is a simple container for given type and used during parsing.
func NewBasicNode ¶
type BlockHeaderNode ¶
type BlockHeaderNode struct {
// contains filtered or unexported fields
}
func NewBlockHeaderNode ¶
func NewBlockHeaderNode(chomping ChompingType, indentation int) *BlockHeaderNode
func (*BlockHeaderNode) Accept ¶
func (*BlockHeaderNode) Accept(Visitor)
func (*BlockHeaderNode) ChompingIndicator ¶
func (b *BlockHeaderNode) ChompingIndicator() ChompingType
ChompingIndicator returns a chomping type defines in block header.
func (*BlockHeaderNode) IndentationIndicator ¶
func (b *BlockHeaderNode) IndentationIndicator() int
IndentationIndicator returns an indentation value that was explicitly set in block header.
func (*BlockHeaderNode) Type ¶
func (*BlockHeaderNode) Type() NodeType
type ChompingType ¶
type ChompingType int8
ChompingType corresponds to YAML chomping type and defines what to do with trailing newlines in literal/folded style.
const ( UnknownChompingType ChompingType = iota // ClipChompingType prescribes removing of trailing newlines except the first one ClipChompingType // StripChompingType prescribes removing of all trailing newlines StripChompingType // KeepChompingType prescribes keeping of all trailing newlines KeepChompingType )
func TokenChompingType ¶
func TokenChompingType(tok token.Token) ChompingType
TokenChompingType derives chomping type from given token
type ContentNode ¶
type ContentNode struct {
// contains filtered or unexported fields
}
func NewContentNode ¶
func NewContentNode(properties, content Node) *ContentNode
func (*ContentNode) Accept ¶
func (c *ContentNode) Accept(v Visitor)
func (*ContentNode) Content ¶
func (c *ContentNode) Content() Node
func (*ContentNode) Properties ¶
func (c *ContentNode) Properties() Node
func (*ContentNode) Type ¶
func (*ContentNode) Type() NodeType
type IndentNode ¶
type IndentNode struct {
// contains filtered or unexported fields
}
func NewIndentNode ¶
func NewIndentNode(indent int) *IndentNode
func (*IndentNode) Accept ¶
func (*IndentNode) Accept(Visitor)
func (*IndentNode) Indent ¶
func (i *IndentNode) Indent() int
func (*IndentNode) Type ¶
func (*IndentNode) Type() NodeType
type MappingEntryNode ¶
type MappingEntryNode struct {
// contains filtered or unexported fields
}
func NewMappingEntryNode ¶
func NewMappingEntryNode(key, value Node) *MappingEntryNode
func (*MappingEntryNode) Accept ¶
func (m *MappingEntryNode) Accept(v Visitor)
func (*MappingEntryNode) Key ¶
func (m *MappingEntryNode) Key() Node
func (*MappingEntryNode) SetKey ¶
func (m *MappingEntryNode) SetKey(n Node)
func (*MappingEntryNode) SetValue ¶
func (m *MappingEntryNode) SetValue(n Node)
func (*MappingEntryNode) Type ¶
func (*MappingEntryNode) Type() NodeType
func (*MappingEntryNode) Value ¶
func (m *MappingEntryNode) Value() Node
type MappingNode ¶
type MappingNode struct {
// contains filtered or unexported fields
}
func NewMappingNode ¶
func NewMappingNode(entries []Node) *MappingNode
func (*MappingNode) Accept ¶
func (m *MappingNode) Accept(v Visitor)
func (*MappingNode) AppendEntry ¶
func (m *MappingNode) AppendEntry(n Node)
func (*MappingNode) Entries ¶
func (m *MappingNode) Entries() []Node
func (*MappingNode) Type ¶
func (*MappingNode) Type() NodeType
type Node ¶
type Node interface { // Type returns the node's type Type() NodeType // Accept implements "Visitor" pattern for AST. Accept(v Visitor) }
Node is a single element of YAML AST
func NewInvalidNode ¶
func NewInvalidNode() Node
type NodeType ¶
type NodeType int8
NodeType represents the type of element in AST
const ( // InvalidType embodies an erroneous element of AST. They usually appear when an error occures during parsing. InvalidType NodeType = iota // DocumentType represents a YAML document. DocumentType // ContentType represents a content element (scalar, sequence or mapping) with properties (tag, anchor). ContentType // MappingType represents a YAML mapping. MappingType // MappingEntryType represents a single mapping entry (key-value pair). MappingEntryType // SequenceType represents a YAML sequence. SequenceType // CommentType represents a YAML comment. CommentType // DirectiveType represents a YAML directive. DirectiveType // TagType represents a YAML tag. TagType // AnchorType represents a YAML anchor. AnchorType // AliasType represents a YAML alias. AliasType // StreamType represents a YAML stream StreamType // DocumentPrefixType represents a YAML document prefix (BOM + comments) DocumentPrefixType // DocumentSuffixType represents a YAML document suffix (document end + comments) DocumentSuffixType // IndentType represents a YAML indentation. IndentType // PropertiesType represents element's properties (tag, anchor). PropertiesType // BlockHeaderType represents literal/folded properties (chomping, explicit indent indicator) BlockHeaderType // TextType represents a text, i.e. single scalar TextType // NullType represents a null scalar. NullType )
type PropertiesNode ¶
type PropertiesNode struct {
// contains filtered or unexported fields
}
func NewPropertiesNode ¶
func NewPropertiesNode(tag, anchor Node) *PropertiesNode
func (*PropertiesNode) Accept ¶
func (p *PropertiesNode) Accept(v Visitor)
func (*PropertiesNode) Anchor ¶
func (p *PropertiesNode) Anchor() Node
func (*PropertiesNode) Tag ¶
func (p *PropertiesNode) Tag() Node
func (*PropertiesNode) Type ¶
func (*PropertiesNode) Type() NodeType
type QuotingType ¶
type QuotingType int8
QuotingType represents a quoting type of string.
const ( UnknownQuotingType QuotingType = iota // AbsentQuotingType means that string has no quotes AbsentQuotingType // SingleQuotingType means that string is enclosed in single quotes SingleQuotingType // DoubleQuotingType means that string is enclosed in double quotes DoubleQuotingType )
type SequenceNode ¶
type SequenceNode struct {
// contains filtered or unexported fields
}
func NewSequenceNode ¶
func NewSequenceNode(entries []Node) *SequenceNode
func (*SequenceNode) Accept ¶
func (s *SequenceNode) Accept(v Visitor)
func (*SequenceNode) AppendEntry ¶
func (s *SequenceNode) AppendEntry(n Node)
func (*SequenceNode) Entries ¶
func (s *SequenceNode) Entries() []Node
func (*SequenceNode) Type ¶
func (*SequenceNode) Type() NodeType
type StreamNode ¶
type StreamNode struct {
// contains filtered or unexported fields
}
func NewStreamNode ¶
func NewStreamNode(documents []Node) *StreamNode
func (*StreamNode) Accept ¶
func (s *StreamNode) Accept(v Visitor)
func (*StreamNode) Documents ¶
func (s *StreamNode) Documents() []Node
func (*StreamNode) Type ¶
func (*StreamNode) Type() NodeType
type TextNode ¶
type TextNode struct {
// contains filtered or unexported fields
}
func NewTextNode ¶
func NewTextNode(text string, opts ...TextNodeOption) *TextNode
func (*TextNode) QuotingType ¶
func (t *TextNode) QuotingType() QuotingType
type TextNodeOption ¶
type TextNodeOption interface {
// contains filtered or unexported methods
}
TextNodeOption allows to modify YAML element associated with TextNode during creation.
func WithQuotingType ¶
func WithQuotingType(t QuotingType) TextNodeOption
WithQuotingType sets given QuotingType for TextNode string.
type Texter ¶
type Texter interface { // Text returns string data associated with Texter node Text() string }
Texter is a more specific kind of Node that has some meaningful string data
type TexterNode ¶
TexterNode is a composite of Node and Texter interfaces
type Visitor ¶
type Visitor interface { VisitStreamNode(n *StreamNode) VisitTagNode(n *TagNode) VisitAnchorNode(n *AnchorNode) VisitAliasNode(n *AliasNode) VisitTextNode(n *TextNode) VisitSequenceNode(n *SequenceNode) VisitMappingNode(n *MappingNode) VisitMappingEntryNode(n *MappingEntryNode) VisitNullNode(n *NullNode) VisitPropertiesNode(n *PropertiesNode) VisitContentNode(n *ContentNode) }
Visitor implements "Visitor" pattern and allows to traverse AST with some custom logic
Directories ¶
Path | Synopsis |
---|---|
Package astcmp contains types and method to compare YAML ASTs.
|
Package astcmp contains types and method to compare YAML ASTs. |
Package astprint contains types and functions for printing and formatting string representation of YAML AST.
|
Package astprint contains types and functions for printing and formatting string representation of YAML AST. |