hclparse

package
v0.56.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 4, 2024 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Attribute

type Attribute struct {
	*File
	*hcl.Attribute
}

func (*Attribute) ValidateIdentifier

func (attr *Attribute) ValidateIdentifier() error

func (*Attribute) Value

func (attr *Attribute) Value(evalCtx *hcl.EvalContext) (cty.Value, error)

type Attributes

type Attributes []*Attribute

func NewAttributes

func NewAttributes(file *File, hclAttrs hcl.Attributes) Attributes

func (Attributes) ValidateIdentifier

func (attrs Attributes) ValidateIdentifier() error

type Block

type Block struct {
	*File
	*hcl.Block
}

func (*Block) JustAttributes

func (block *Block) JustAttributes() (Attributes, error)

GetAttrs loads the block into name expression pairs to assist with evaluation of the attrs prior to evaluating the whole config. Note that this is exactly the same as terraform/configs/named_values.go:decodeLocalsBlock

type File

type File struct {
	*Parser
	*hcl.File
	ConfigPath string
}

func (*File) Blocks

func (file *File) Blocks(name string, isMultipleAllowed bool) ([]*Block, error)

GetBlock takes a parsed HCL file and extracts a reference to the `name` block, if there are defined.

func (*File) Content

func (file *File) Content() string

func (*File) Decode

func (file *File) Decode(out interface{}, evalContext *hcl.EvalContext) (err error)

Decode uses the HCL2 parser to decode the parsed HCL into the struct specified by out.

Note that we take a two pass approach to support parsing include blocks without a label. Ideally we can parse include blocks with and without labels in a single pass, but the HCL parser is fairly restrictive when it comes to parsing blocks with labels, requiring the exact number of expected labels in the parsing step. To handle this restriction, we first see if there are any include blocks without any labels, and if there is, we modify it in the file object to inject the label as "".

func (*File) JustAttributes

func (file *File) JustAttributes() (Attributes, error)

func (*File) Update

func (file *File) Update(content []byte) error

Update reparses the file with the new `content`.

type Option

type Option func(Parser) Parser

func WithFileUpdate

func WithFileUpdate(fn func(*File) error) Option

WithFileUpdate sets the `fileUpdateHandlerFunc` func which is run before each file decoding.

func WithHaltOnErrorOnlyForBlocks

func WithHaltOnErrorOnlyForBlocks(blockNames []string) Option

WithHaltOnErrorOnlyForBlocks configures a diagnostic error handler that runs when diagnostic errors occur. If errors occur in the given `blockNames` blocks, parser returns the error to its caller, otherwise it skips the error.

func WithLogger

func WithLogger(logger *logrus.Entry) Option

type PanicWhileParsingConfigError

type PanicWhileParsingConfigError struct {
	ConfigFile     string
	RecoveredValue interface{}
}

func (PanicWhileParsingConfigError) Error

type Parser

type Parser struct {
	*hclparse.Parser
	// contains filtered or unexported fields
}

func NewParser

func NewParser() *Parser

func (*Parser) ParseFromBytes

func (parser *Parser) ParseFromBytes(content []byte, configPath string) (file *File, err error)

func (*Parser) ParseFromFile

func (parser *Parser) ParseFromFile(configPath string) (*File, error)

func (*Parser) ParseFromString

func (parser *Parser) ParseFromString(content, configPath string) (file *File, err error)

ParseFromString uses the HCL2 parser to parse the given string into an HCL file body.

func (*Parser) WithOptions

func (parser *Parser) WithOptions(opts ...Option) *Parser

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL