Documentation ¶
Overview ¶
Package ast provides low level parsing facilities for HCL configuration. It includes extra features like block merging, specific to Terramate needs.
Index ¶
- func AsHCLAttributes(syntaxAttrs hclsyntax.Attributes) hhcl.Attributes
- func CloneExpr(expr hclsyntax.Expression) hclsyntax.Expression
- func ParseExpression(str string, filename string) (hcl.Expression, error)
- func SortRawAttributes(attrs hhcl.Attributes) []*hhcl.Attribute
- func TokensForExpression(expr hcl.Expression) hclwrite.Tokens
- func TokensForValue(value cty.Value) hclwrite.Tokens
- type Attribute
- type AttributeSlice
- type Attributes
- type Block
- type BlockType
- type Blocks
- type CloneExpression
- type LabelBlockType
- type MergedBlock
- type MergedBlocks
- type MergedLabelBlocks
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AsHCLAttributes ¶
func AsHCLAttributes(syntaxAttrs hclsyntax.Attributes) hhcl.Attributes
AsHCLAttributes converts hclsyntax.Attributes to hcl.Attributes.
func CloneExpr ¶
func CloneExpr(expr hclsyntax.Expression) hclsyntax.Expression
CloneExpr clones the given expression.
func ParseExpression ¶
ParseExpression parses the expression str.
func SortRawAttributes ¶
func SortRawAttributes(attrs hhcl.Attributes) []*hhcl.Attribute
SortRawAttributes sorts the raw attributes.
func TokensForExpression ¶
TokensForExpression generates valid tokens for the given expression.
Types ¶
type AttributeSlice ¶
type AttributeSlice []Attribute
AttributeSlice is an sortable Attribute slice.
func (AttributeSlice) Len ¶
func (a AttributeSlice) Len() int
Len returns the size of the attributes slice.
func (AttributeSlice) Less ¶
func (a AttributeSlice) Less(i, j int) bool
Less returns true if i < j, false otherwise.
type Attributes ¶
Attributes represents multiple parsed attributes.
func NewAttributes ¶
func NewAttributes(rootdir string, rawAttrs hhcl.Attributes) Attributes
NewAttributes creates a map of Attributes from the raw hcl.Attributes.
func (Attributes) SortedList ¶
func (a Attributes) SortedList() AttributeSlice
SortedList returns a sorted list of attributes from the map.
type Block ¶
Block is a wrapper to the hclsyntax.Block but with the file origin. The hclsyntax.Block.Attributes are converted to hcl.Attributes.
func (*Block) LabelRanges ¶
func (b *Block) LabelRanges() hcl.Range
LabelRanges computes a range between the first and last label in the case the block has labels or a range for the empty space between the block name and the open brace.
type CloneExpression ¶
type CloneExpression struct {
hclsyntax.Expression
}
CloneExpression is an expression wrapper that
func (*CloneExpression) Value ¶
func (clone *CloneExpression) Value(ctx *hcl.EvalContext) (cty.Value, hcl.Diagnostics)
Value evaluates the wrapped expression.
type LabelBlockType ¶
type LabelBlockType struct { Type BlockType // Type of the block Labels [project.MaxGlobalLabels]string // Labels are the block labels. NumLabels int // NumLabels is the number of defined labels. }
LabelBlockType represents a labelled block type.
func NewEmptyLabelBlockType ¶
func NewEmptyLabelBlockType(typ string) LabelBlockType
NewEmptyLabelBlockType returns a new LabelBlockType with empty labels.
func NewLabelBlockType ¶
func NewLabelBlockType(typ string, labels []string) (LabelBlockType, error)
NewLabelBlockType returns a new LabelBlockType.
type MergedBlock ¶
type MergedBlock struct { // Type is the block type (or name). Type BlockType // Labels is the comma-separated list of labels Labels []string // Attributes are the block's attributes. Attributes Attributes // RawOrigins is the list of original blocks that contributed to this block. RawOrigins Blocks // Blocks maps block types to merged blocks. Blocks map[LabelBlockType]*MergedBlock // RawBlocks keeps a map of block type to original blocks. RawBlocks map[string]Blocks }
MergedBlock represents a block that spans multiple files.
func NewMergedBlock ¶
func NewMergedBlock(typ string, labels []string) *MergedBlock
NewMergedBlock creates a new MergedBlock of type typ.
func (*MergedBlock) MergeBlock ¶
func (mb *MergedBlock) MergeBlock(other *Block, isLabelled bool) error
MergeBlock recursively merges the other block into this one.
func (*MergedBlock) ValidateSubBlocks ¶
func (mb *MergedBlock) ValidateSubBlocks(allowed ...string) error
ValidateSubBlocks checks if the block only has the allowed block types.
type MergedBlocks ¶
type MergedBlocks map[string]*MergedBlock
MergedBlocks maps the block name to the MergedBlock.
func (MergedBlocks) AsBlocks ¶
func (mergedBlocks MergedBlocks) AsBlocks() Blocks
AsBlocks returns a Block list from a MergedBlocks.
type MergedLabelBlocks ¶
type MergedLabelBlocks map[LabelBlockType]*MergedBlock
MergedLabelBlocks maps the block labels/types to the MergedBlock.
func (MergedLabelBlocks) AsBlocks ¶
func (mergedBlocks MergedLabelBlocks) AsBlocks() Blocks
AsBlocks returns a Block list from a MergedBlocks.
func (MergedLabelBlocks) AsList ¶
func (mergedBlocks MergedLabelBlocks) AsList() []*MergedBlock
AsList returns a list of merged blocks sorted by its label strings.