syntax

package
v1.14.1 Latest Latest
Warning

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

Go to latest
Published: Apr 13, 2020 License: Apache-2.0 Imports: 10 Imported by: 0

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 added in v1.14.1

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 added in v1.14.1

func NewAttributeTokens(name string) *AttributeTokens

func (*AttributeTokens) GetEquals added in v1.14.1

func (t *AttributeTokens) GetEquals() Token

func (*AttributeTokens) GetName added in v1.14.1

func (t *AttributeTokens) GetName() Token

type BinaryOpTokens

type BinaryOpTokens struct {
	Operator Token
}

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

func NewBinaryOpTokens added in v1.14.1

func NewBinaryOpTokens(operation *hclsyntax.Operation) *BinaryOpTokens

func (*BinaryOpTokens) GetOperator added in v1.14.1

func (t *BinaryOpTokens) GetOperator() Token

type BlockTokens

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

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

func NewBlockTokens added in v1.14.1

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

func (*BlockTokens) GetCloseBrace added in v1.14.1

func (t *BlockTokens) GetCloseBrace() Token

func (*BlockTokens) GetLabels added in v1.14.1

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

func (*BlockTokens) GetOpenBrace added in v1.14.1

func (t *BlockTokens) GetOpenBrace() Token

func (*BlockTokens) GetType added in v1.14.1

func (t *BlockTokens) GetType() Token

type BodyTokens

type BodyTokens struct {
	EndOfFile *Token
}

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

func (*BodyTokens) GetEndOfFile added in v1.14.1

func (t *BodyTokens) GetEndOfFile() *Token

type BracketTraverserTokens

type BracketTraverserTokens struct {
	OpenBracket  Token
	Index        Token
	CloseBracket Token
}

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

func NewBracketTraverserTokens added in v1.14.1

func NewBracketTraverserTokens(index string) *BracketTraverserTokens

func (*BracketTraverserTokens) GetCloseBracket added in v1.14.1

func (t *BracketTraverserTokens) GetCloseBracket() Token

func (*BracketTraverserTokens) GetIndex added in v1.14.1

func (t *BracketTraverserTokens) GetIndex() Token

func (*BracketTraverserTokens) GetOpenBracket added in v1.14.1

func (t *BracketTraverserTokens) GetOpenBracket() Token

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 {
	QuestionMark Token
	Colon        Token
}

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

func NewConditionalTokens added in v1.14.1

func NewConditionalTokens() *ConditionalTokens

func (*ConditionalTokens) GetColon added in v1.14.1

func (t *ConditionalTokens) GetColon() Token

func (*ConditionalTokens) GetQuestionMark added in v1.14.1

func (t *ConditionalTokens) GetQuestionMark() Token

type DotTraverserTokens

type DotTraverserTokens struct {
	Dot   Token
	Index Token
}

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

func NewDotTraverserTokens added in v1.14.1

func NewDotTraverserTokens(index string) *DotTraverserTokens

func (*DotTraverserTokens) GetDot added in v1.14.1

func (t *DotTraverserTokens) GetDot() Token

func (*DotTraverserTokens) GetIndex added in v1.14.1

func (t *DotTraverserTokens) GetIndex() Token

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 {
	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 added in v1.14.1

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

func (*ForTokens) GetArrow added in v1.14.1

func (t *ForTokens) GetArrow() *Token

func (*ForTokens) GetClose added in v1.14.1

func (t *ForTokens) GetClose() Token

func (*ForTokens) GetColon added in v1.14.1

func (t *ForTokens) GetColon() Token

func (*ForTokens) GetComma added in v1.14.1

func (t *ForTokens) GetComma() *Token

func (*ForTokens) GetFor added in v1.14.1

func (t *ForTokens) GetFor() Token

func (*ForTokens) GetGroup added in v1.14.1

func (t *ForTokens) GetGroup() *Token

func (*ForTokens) GetIf added in v1.14.1

func (t *ForTokens) GetIf() *Token

func (*ForTokens) GetIn added in v1.14.1

func (t *ForTokens) GetIn() Token

func (*ForTokens) GetKey added in v1.14.1

func (t *ForTokens) GetKey() *Token

func (*ForTokens) GetOpen added in v1.14.1

func (t *ForTokens) GetOpen() Token

func (*ForTokens) GetValue added in v1.14.1

func (t *ForTokens) GetValue() Token

type FunctionCallTokens

type FunctionCallTokens struct {
	Name       Token
	OpenParen  Token
	Commas     []Token
	CloseParen Token
}

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

func NewFunctionCallTokens added in v1.14.1

func NewFunctionCallTokens(name string, argCount int) *FunctionCallTokens

func (*FunctionCallTokens) GetCloseParen added in v1.14.1

func (t *FunctionCallTokens) GetCloseParen() Token

func (*FunctionCallTokens) GetCommas added in v1.14.1

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

func (*FunctionCallTokens) GetName added in v1.14.1

func (t *FunctionCallTokens) GetName() Token

func (*FunctionCallTokens) GetOpenParen added in v1.14.1

func (t *FunctionCallTokens) GetOpenParen() Token

type IndexTokens

type IndexTokens struct {
	OpenBracket  Token
	CloseBracket Token
}

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

func NewIndexTokens added in v1.14.1

func NewIndexTokens() *IndexTokens

func (*IndexTokens) GetCloseBracket added in v1.14.1

func (t *IndexTokens) GetCloseBracket() Token

func (*IndexTokens) GetOpenBracket added in v1.14.1

func (t *IndexTokens) GetOpenBracket() Token

type LiteralValueTokens

type LiteralValueTokens struct {
	Value []Token
}

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

func NewLiteralValueTokens added in v1.14.1

func NewLiteralValueTokens(tokens ...Token) *LiteralValueTokens

func (*LiteralValueTokens) GetValue added in v1.14.1

func (t *LiteralValueTokens) GetValue() []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.

type ObjectConsTokens

type ObjectConsTokens struct {
	OpenBrace  Token
	Items      []ObjectConsItemTokens
	CloseBrace Token
}

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

func NewObjectConsTokens added in v1.14.1

func NewObjectConsTokens(itemCount int) *ObjectConsTokens

func (*ObjectConsTokens) GetCloseBrace added in v1.14.1

func (t *ObjectConsTokens) GetCloseBrace() Token

func (*ObjectConsTokens) GetItems added in v1.14.1

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

func (*ObjectConsTokens) GetOpenBrace added in v1.14.1

func (t *ObjectConsTokens) GetOpenBrace() Token

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 {
	Traversal []TraverserTokens
}

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

func NewRelativeTraversalTokens added in v1.14.1

func NewRelativeTraversalTokens(traversers ...TraverserTokens) *RelativeTraversalTokens

func (*RelativeTraversalTokens) GetTraversal added in v1.14.1

func (t *RelativeTraversalTokens) GetTraversal() []TraverserTokens

type ScopeTraversalTokens

type ScopeTraversalTokens struct {
	Root      Token
	Traversal []TraverserTokens
}

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

func NewScopeTraversalTokens added in v1.14.1

func NewScopeTraversalTokens(root string, traversers ...TraverserTokens) *ScopeTraversalTokens

func (*ScopeTraversalTokens) GetRoot added in v1.14.1

func (t *ScopeTraversalTokens) GetRoot() Token

func (*ScopeTraversalTokens) GetTraversal added in v1.14.1

func (t *ScopeTraversalTokens) GetTraversal() []TraverserTokens

type SplatTokens

type SplatTokens struct {
	Open  Token
	Star  Token
	Close *Token
}

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

func NewSplatTokens added in v1.14.1

func NewSplatTokens(dotted bool) *SplatTokens

func (*SplatTokens) GetClose added in v1.14.1

func (t *SplatTokens) GetClose() *Token

func (*SplatTokens) GetOpen added in v1.14.1

func (t *SplatTokens) GetOpen() Token

func (*SplatTokens) GetStar added in v1.14.1

func (t *SplatTokens) GetStar() Token

type TemplateConditionalTokens added in v1.14.1

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 added in v1.14.1

func NewTemplateConditionalTokens(hasElse bool) *TemplateConditionalTokens

type TemplateDelimiter added in v1.14.1

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 (TemplateDelimiter) Bytes added in v1.14.1

func (t TemplateDelimiter) Bytes() []byte

Bytes returns the raw bytes that comprise the delimiter.

func (TemplateDelimiter) Range added in v1.14.1

func (t TemplateDelimiter) Range() hcl.Range

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

type TemplateForTokens added in v1.14.1

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 added in v1.14.1

func NewTemplateForTokens(keyVariable, valueVariable string) *TemplateForTokens

func (*TemplateForTokens) GetComma added in v1.14.1

func (t *TemplateForTokens) GetComma() *Token

func (*TemplateForTokens) GetEndfor added in v1.14.1

func (t *TemplateForTokens) GetEndfor() Token

func (*TemplateForTokens) GetFor added in v1.14.1

func (t *TemplateForTokens) GetFor() Token

func (*TemplateForTokens) GetIn added in v1.14.1

func (t *TemplateForTokens) GetIn() Token

func (*TemplateForTokens) GetKey added in v1.14.1

func (t *TemplateForTokens) GetKey() *Token

func (*TemplateForTokens) GetValue added in v1.14.1

func (t *TemplateForTokens) GetValue() Token

type TemplateTokens

type TemplateTokens struct {
	Open  Token
	Close Token
}

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

func NewTemplateTokens added in v1.14.1

func NewTemplateTokens() *TemplateTokens

func (*TemplateTokens) GetClose added in v1.14.1

func (t *TemplateTokens) GetClose() Token

func (*TemplateTokens) GetOpen added in v1.14.1

func (t *TemplateTokens) GetOpen() Token

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 added in v1.14.1

func (t Token) AllTrivia() TriviaList

func (Token) Format added in v1.14.1

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

func (Token) Or added in v1.14.1

func (t Token) Or(typ hclsyntax.TokenType, s ...string) Token

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 {
	GetIndex() Token
	// contains filtered or unexported methods
}

TraverserTokens is a closed interface implemented by DotTraverserTokens and BracketTraverserTokens

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 added in v1.14.1

type TriviaList []Trivia

TriviaList is a list of trivia.

func (TriviaList) CollapseWhitespace added in v1.14.1

func (trivia TriviaList) CollapseWhitespace() TriviaList

func (TriviaList) Format added in v1.14.1

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

type TupleConsTokens

type TupleConsTokens struct {
	OpenBracket  Token
	Commas       []Token
	CloseBracket Token
}

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

func NewTupleConsTokens added in v1.14.1

func NewTupleConsTokens(elementCount int) *TupleConsTokens

func (*TupleConsTokens) GetCloseBracket added in v1.14.1

func (t *TupleConsTokens) GetCloseBracket() Token

func (*TupleConsTokens) GetCommas added in v1.14.1

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

func (*TupleConsTokens) GetOpenBracket added in v1.14.1

func (t *TupleConsTokens) GetOpenBracket() Token

type UnaryOpTokens

type UnaryOpTokens struct {
	Operator Token
}

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

func NewUnaryOpTokens added in v1.14.1

func NewUnaryOpTokens(operation *hclsyntax.Operation) *UnaryOpTokens

func (*UnaryOpTokens) GetOperator added in v1.14.1

func (t *UnaryOpTokens) GetOperator() Token

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 added in v1.14.1

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