syntax

package
v2.25.2 Latest Latest
Warning

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

Go to latest
Published: Apr 17, 2021 License: Apache-2.0 Imports: 14 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

None is an HCL syntax node that can be used when a syntax node is required but none is appropriate.

Functions

func NewDiagnosticWriter

func NewDiagnosticWriter(w io.Writer, files []*File, width uint, color bool) hcl.DiagnosticWriter

NewDiagnosticWriter creates a new diagnostic writer for the given list of HCL2 files.

func OperationTokenType

func OperationTokenType(operation *hclsyntax.Operation) hclsyntax.TokenType

Types

type AttributeTokens

type AttributeTokens struct {
	Name   Token
	Equals Token
}

AttributeTokens records the tokens associated with an *hclsyntax.Attribute.

func NewAttributeTokens

func NewAttributeTokens(name string) *AttributeTokens

func (*AttributeTokens) GetEquals

func (t *AttributeTokens) GetEquals() Token

func (*AttributeTokens) GetName

func (t *AttributeTokens) GetName(name string) Token

type BinaryOpTokens

type BinaryOpTokens struct {
	Parentheses Parentheses

	Operator Token
}

BinaryOpTokens records the tokens associated with an *hclsyntax.BinaryOpExpr.

func NewBinaryOpTokens

func NewBinaryOpTokens(operation *hclsyntax.Operation) *BinaryOpTokens

func (*BinaryOpTokens) GetOperator

func (t *BinaryOpTokens) GetOperator(operation *hclsyntax.Operation) Token

func (*BinaryOpTokens) GetParentheses

func (t *BinaryOpTokens) GetParentheses() Parentheses

type BlockTokens

type BlockTokens struct {
	Type       Token
	Labels     []Token
	OpenBrace  Token
	CloseBrace Token
}

BlockTokens records the tokens associated with an *hclsyntax.Block.

func NewBlockTokens

func NewBlockTokens(typ string, labels ...string) *BlockTokens

func (*BlockTokens) GetCloseBrace

func (t *BlockTokens) GetCloseBrace() Token

func (*BlockTokens) GetLabels

func (t *BlockTokens) GetLabels(labels []string) []Token

func (*BlockTokens) GetOpenBrace

func (t *BlockTokens) GetOpenBrace() Token

func (*BlockTokens) GetType

func (t *BlockTokens) GetType(typ string) Token

type BodyTokens

type BodyTokens struct {
	EndOfFile *Token
}

BodyTokens records the tokens associated with an *hclsyntax.Body.

func (*BodyTokens) GetEndOfFile

func (t *BodyTokens) GetEndOfFile() *Token

type BracketTraverserTokens

type BracketTraverserTokens struct {
	Parentheses Parentheses

	OpenBracket  Token
	Index        Token
	CloseBracket Token
}

BracketTraverserTokens records the tokens associated with a bracketed traverser (i.e. '[' <index> ']').

func NewBracketTraverserTokens

func NewBracketTraverserTokens(index string) *BracketTraverserTokens

func (*BracketTraverserTokens) Range

func (t *BracketTraverserTokens) Range() hcl.Range

type Comment

type Comment struct {
	// Lines contains the lines of the comment without leading comment characters or trailing newlines.
	Lines []string
	// contains filtered or unexported fields
}

Comment is a piece of trivia that represents a line or block comment in a source file.

func (Comment) Bytes

func (c Comment) Bytes() []byte

Bytes returns the raw bytes that comprise the comment.

func (Comment) Range

func (c Comment) Range() hcl.Range

Range returns the range of the comment in the source file.

type ConditionalTokens

type ConditionalTokens struct {
	Parentheses Parentheses

	QuestionMark Token
	Colon        Token
}

ConditionalTokens records the tokens associated with an *hclsyntax.ConditionalExpr of the form "a ? t : f".

func NewConditionalTokens

func NewConditionalTokens() *ConditionalTokens

type DotTraverserTokens

type DotTraverserTokens struct {
	Parentheses Parentheses

	Dot   Token
	Index Token
}

DotTraverserTokens records the tokens associated with dotted traverser (i.e. '.' <attr>).

func NewDotTraverserTokens

func NewDotTraverserTokens(index string) *DotTraverserTokens

func (*DotTraverserTokens) Range

func (t *DotTraverserTokens) Range() hcl.Range

type File

type File struct {
	Name   string          // The name of the file.
	Body   *hclsyntax.Body // The body of the parsed file.
	Bytes  []byte          // The raw bytes of the source file.
	Tokens TokenMap        // A map from syntax nodes to token information.
}

File represents a single parsed HCL2 source file.

type ForTokens

type ForTokens struct {
	Parentheses Parentheses

	Open  Token
	For   Token
	Key   *Token
	Comma *Token
	Value Token
	In    Token
	Colon Token
	Arrow *Token
	Group *Token
	If    *Token
	Close Token
}

ForTokens records the tokens associated with an *hclsyntax.ForExpr.

func NewForTokens

func NewForTokens(keyVariable, valueVariable string, mapFor, group, conditional bool) *ForTokens

type FunctionCallTokens

type FunctionCallTokens struct {
	Parentheses Parentheses

	Name       Token
	OpenParen  Token
	Commas     []Token
	CloseParen Token
}

FunctionCallTokens records the tokens associated with an *hclsyntax.FunctionCallExpr.

func NewFunctionCallTokens

func NewFunctionCallTokens(name string, argCount int) *FunctionCallTokens

func (*FunctionCallTokens) GetCloseParen

func (t *FunctionCallTokens) GetCloseParen() Token

func (*FunctionCallTokens) GetCommas

func (t *FunctionCallTokens) GetCommas(argCount int) []Token

func (*FunctionCallTokens) GetName

func (t *FunctionCallTokens) GetName(name string) Token

func (*FunctionCallTokens) GetOpenParen

func (t *FunctionCallTokens) GetOpenParen() Token

func (*FunctionCallTokens) GetParentheses

func (t *FunctionCallTokens) GetParentheses() Parentheses

type IndexTokens

type IndexTokens struct {
	Parentheses Parentheses

	OpenBracket  Token
	CloseBracket Token
}

IndexTokens records the tokens associated with an *hclsyntax.IndexExpr.

func NewIndexTokens

func NewIndexTokens() *IndexTokens

func (*IndexTokens) GetCloseBracket

func (t *IndexTokens) GetCloseBracket() Token

func (*IndexTokens) GetOpenBracket

func (t *IndexTokens) GetOpenBracket() Token

func (*IndexTokens) GetParentheses

func (t *IndexTokens) GetParentheses() Parentheses

type LiteralValueTokens

type LiteralValueTokens struct {
	Parentheses Parentheses

	Value []Token
}

LiteralValueTokens records the tokens associated with an *hclsyntax.LiteralValueExpr.

func NewLiteralValueTokens

func NewLiteralValueTokens(value cty.Value) *LiteralValueTokens

func (*LiteralValueTokens) GetParentheses

func (t *LiteralValueTokens) GetParentheses() Parentheses

func (*LiteralValueTokens) GetValue

func (t *LiteralValueTokens) GetValue(value cty.Value) []Token

type NodeTokens

type NodeTokens interface {
	// contains filtered or unexported methods
}

NodeTokens is a closed interface that is used to represent arbitrary *Tokens types in this package.

type ObjectConsItemTokens

type ObjectConsItemTokens struct {
	Equals Token
	Comma  *Token
}

ObjectConsItemTokens records the tokens associated with an hclsyntax.ObjectConsItem.

func NewObjectConsItemTokens

func NewObjectConsItemTokens(last bool) ObjectConsItemTokens

type ObjectConsTokens

type ObjectConsTokens struct {
	Parentheses Parentheses

	OpenBrace  Token
	Items      []ObjectConsItemTokens
	CloseBrace Token
}

ObjectConsTokens records the tokens associated with an *hclsyntax.ObjectConsExpr.

func NewObjectConsTokens

func NewObjectConsTokens(itemCount int) *ObjectConsTokens

func (*ObjectConsTokens) GetCloseBrace

func (t *ObjectConsTokens) GetCloseBrace() Token

func (*ObjectConsTokens) GetItems

func (t *ObjectConsTokens) GetItems(itemCount int) []ObjectConsItemTokens

func (*ObjectConsTokens) GetOpenBrace

func (t *ObjectConsTokens) GetOpenBrace(itemCount int) Token

func (*ObjectConsTokens) GetParentheses

func (t *ObjectConsTokens) GetParentheses() Parentheses

type Parentheses

type Parentheses struct {
	Open  []Token
	Close []Token
}

Parentheses records enclosing parenthesis tokens for expressions.

func (Parentheses) Any

func (parens Parentheses) Any() bool

func (Parentheses) Format

func (parens Parentheses) Format(f fmt.State, c rune)

func (Parentheses) GetLeadingTrivia

func (parens Parentheses) GetLeadingTrivia() TriviaList

func (Parentheses) GetTrailingTrivia

func (parens Parentheses) GetTrailingTrivia() TriviaList

func (Parentheses) SetLeadingTrivia

func (parens Parentheses) SetLeadingTrivia(trivia TriviaList)

func (Parentheses) SetTrailingTrivia

func (parens Parentheses) SetTrailingTrivia(trivia TriviaList)

type Parser

type Parser struct {
	Files       []*File         // The parsed files.
	Diagnostics hcl.Diagnostics // The diagnostics, if any, produced during parsing.
	// contains filtered or unexported fields
}

Parser is a parser for HCL2 source files.

func NewParser

func NewParser() *Parser

NewParser creates a new HCL2 parser.

func (*Parser) NewDiagnosticWriter

func (p *Parser) NewDiagnosticWriter(w io.Writer, width uint, color bool) hcl.DiagnosticWriter

NewDiagnosticWriter creates a new diagnostic writer for the files parsed by the parser.

func (*Parser) ParseFile

func (p *Parser) ParseFile(r io.Reader, filename string) error

ParseFile attempts to parse the contents of the given io.Reader as HCL2. If parsing fails, any diagnostics generated will be added to the parser's diagnostics.

type RelativeTraversalTokens

type RelativeTraversalTokens struct {
	Parentheses Parentheses

	Traversal []TraverserTokens
}

RelativeTraversalTokens records the tokens associated with an *hclsyntax.RelativeTraversalExpr.

func NewRelativeTraversalTokens

func NewRelativeTraversalTokens(traversal hcl.Traversal) *RelativeTraversalTokens

func (*RelativeTraversalTokens) GetParentheses

func (t *RelativeTraversalTokens) GetParentheses() Parentheses

func (*RelativeTraversalTokens) GetTraversal

func (t *RelativeTraversalTokens) GetTraversal(traversal hcl.Traversal) []TraverserTokens

type ScopeTraversalTokens

type ScopeTraversalTokens struct {
	Parentheses Parentheses

	Root      Token
	Traversal []TraverserTokens
}

ScopeTraversalTokens records the tokens associated with an *hclsyntax.ScopeTraversalExpr.

func NewScopeTraversalTokens

func NewScopeTraversalTokens(traversal hcl.Traversal) *ScopeTraversalTokens

func (*ScopeTraversalTokens) GetParentheses

func (t *ScopeTraversalTokens) GetParentheses() Parentheses

func (*ScopeTraversalTokens) GetRoot

func (t *ScopeTraversalTokens) GetRoot(traversal hcl.Traversal) Token

func (*ScopeTraversalTokens) GetTraversal

func (t *ScopeTraversalTokens) GetTraversal(traversal hcl.Traversal) []TraverserTokens

type SplatTokens

type SplatTokens struct {
	Parentheses Parentheses

	Open  Token
	Star  Token
	Close *Token
}

SplatTokens records the tokens associated with an *hclsyntax.SplatExpr.

func NewSplatTokens

func NewSplatTokens(dotted bool) *SplatTokens

func (*SplatTokens) GetClose

func (t *SplatTokens) GetClose() *Token

func (*SplatTokens) GetOpen

func (t *SplatTokens) GetOpen() Token

func (*SplatTokens) GetParentheses

func (t *SplatTokens) GetParentheses() Parentheses

func (*SplatTokens) GetStar

func (t *SplatTokens) GetStar() Token

type TemplateConditionalTokens

type TemplateConditionalTokens struct {
	OpenIf     Token
	If         Token
	CloseIf    Token
	OpenElse   *Token
	Else       *Token
	CloseElse  *Token
	OpenEndif  Token
	Endif      Token
	CloseEndif Token
}

TemplateConditionalTokens records the tokens associated with an *hclsyntax.ConditionalExpr inside a template expression.

func NewTemplateConditionalTokens

func NewTemplateConditionalTokens(hasElse bool) *TemplateConditionalTokens

type TemplateDelimiter

type TemplateDelimiter struct {
	// Type is the type of the delimiter (e.g. hclsyntax.TokenTemplateInterp)
	Type hclsyntax.TokenType
	// contains filtered or unexported fields
}

TemplateDelimiter is a piece of trivia that represents a token that demarcates an interpolation or control sequence inside of a template.

func NewTemplateDelimiter added in v2.7.0

func NewTemplateDelimiter(typ hclsyntax.TokenType) TemplateDelimiter

NewTemplateDelimiter creates a new TemplateDelimiter value with the given delimiter type. If the token type is not a template delimiter, this function will panic.

func (TemplateDelimiter) Bytes

func (t TemplateDelimiter) Bytes() []byte

Bytes returns the raw bytes that comprise the delimiter.

func (TemplateDelimiter) Range

func (t TemplateDelimiter) Range() hcl.Range

Range returns the range of the delimiter in the source file.

type TemplateForTokens

type TemplateForTokens struct {
	OpenFor     Token
	For         Token
	Key         *Token
	Comma       *Token
	Value       Token
	In          Token
	CloseFor    Token
	OpenEndfor  Token
	Endfor      Token
	CloseEndfor Token
}

TemplateForTokens records the tokens associated with an *hclsyntax.ForExpr inside a template.

func NewTemplateForTokens

func NewTemplateForTokens(keyVariable, valueVariable string) *TemplateForTokens

type TemplateTokens

type TemplateTokens struct {
	Parentheses Parentheses

	Open  Token
	Close Token
}

TemplateTokens records the tokens associated with an *hclsyntax.TemplateExpr.

func NewTemplateTokens

func NewTemplateTokens() *TemplateTokens

func (*TemplateTokens) GetClose

func (t *TemplateTokens) GetClose() Token

func (*TemplateTokens) GetOpen

func (t *TemplateTokens) GetOpen() Token

func (*TemplateTokens) GetParentheses

func (t *TemplateTokens) GetParentheses() Parentheses

type Token

type Token struct {
	Raw            hclsyntax.Token
	LeadingTrivia  TriviaList
	TrailingTrivia TriviaList
}

Token represents an HCL2 syntax token with attached leading trivia.

func (Token) AllTrivia

func (t Token) AllTrivia() TriviaList

func (Token) Format

func (t Token) Format(f fmt.State, c rune)

func (Token) Range

func (t Token) Range() hcl.Range

Range returns the total range covered by this token and any leading trivia.

type TokenMap

type TokenMap interface {
	ForNode(n hclsyntax.Node) NodeTokens
	// contains filtered or unexported methods
}

A TokenMap is used to map from syntax nodes to information about their tokens and leading whitespace/comments.

func NewTokenMapForFiles

func NewTokenMapForFiles(files []*File) TokenMap

NewTokenMapForFiles creates a new token map that can be used to look up tokens for nodes in any of the given files.

func ParseExpression

func ParseExpression(expression, filename string, start hcl.Pos) (hclsyntax.Expression, TokenMap, hcl.Diagnostics)

ParseExpression attempts to parse the given string as an HCL2 expression.

type TraverserTokens

type TraverserTokens interface {
	Range() hcl.Range
	// contains filtered or unexported methods
}

TraverserTokens is a closed interface implemented by DotTraverserTokens and BracketTraverserTokens

func NewTraverserTokens

func NewTraverserTokens(traverser hcl.Traverser) TraverserTokens

type Trivia

type Trivia interface {
	// Range returns the range of the trivia in the source file.
	Range() hcl.Range
	// Bytes returns the raw bytes that comprise the trivia.
	Bytes() []byte
	// contains filtered or unexported methods
}

Trivia represents bytes in a source file that are not syntactically meaningful. This includes whitespace and comments.

type TriviaList

type TriviaList []Trivia

TriviaList is a list of trivia.

func (TriviaList) CollapseWhitespace

func (trivia TriviaList) CollapseWhitespace() TriviaList

func (TriviaList) EndsOnNewLine added in v2.6.0

func (trivia TriviaList) EndsOnNewLine() bool

func (TriviaList) Format

func (trivia TriviaList) Format(f fmt.State, c rune)

func (TriviaList) Index added in v2.6.0

func (trivia TriviaList) Index(sep string) (Trivia, int)

func (TriviaList) LeadingWhitespace added in v2.1.0

func (trivia TriviaList) LeadingWhitespace() TriviaList

func (TriviaList) TrailingWhitespace added in v2.1.0

func (trivia TriviaList) TrailingWhitespace() TriviaList

type TupleConsTokens

type TupleConsTokens struct {
	Parentheses Parentheses

	OpenBracket  Token
	Commas       []Token
	CloseBracket Token
}

TupleConsTokens records the tokens associated with an *hclsyntax.TupleConsExpr.

func NewTupleConsTokens

func NewTupleConsTokens(elementCount int) *TupleConsTokens

func (*TupleConsTokens) GetCloseBracket

func (t *TupleConsTokens) GetCloseBracket() Token

func (*TupleConsTokens) GetCommas

func (t *TupleConsTokens) GetCommas(elementCount int) []Token

func (*TupleConsTokens) GetOpenBracket

func (t *TupleConsTokens) GetOpenBracket() Token

func (*TupleConsTokens) GetParentheses

func (t *TupleConsTokens) GetParentheses() Parentheses

type UnaryOpTokens

type UnaryOpTokens struct {
	Parentheses Parentheses

	Operator Token
}

UnaryOpTokens records the tokens associated with an *hclsyntax.UnaryOpExpr.

func NewUnaryOpTokens

func NewUnaryOpTokens(operation *hclsyntax.Operation) *UnaryOpTokens

func (*UnaryOpTokens) GetOperator

func (t *UnaryOpTokens) GetOperator(operation *hclsyntax.Operation) Token

func (*UnaryOpTokens) GetParentheses

func (t *UnaryOpTokens) GetParentheses() Parentheses

type Whitespace

type Whitespace struct {
	// contains filtered or unexported fields
}

Whitespace is a piece of trivia that represents a sequence of whitespace characters in a source file.

func NewWhitespace

func NewWhitespace(bytes ...byte) Whitespace

NewWhitespace returns a new piece of whitespace trivia with the given contents.

func (Whitespace) Bytes

func (w Whitespace) Bytes() []byte

Bytes returns the raw bytes that comprise the whitespace.

func (Whitespace) Range

func (w Whitespace) Range() hcl.Range

Range returns the range of the whitespace in the source file.

Jump to

Keyboard shortcuts

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