syntax

package
v1.13.0 Latest Latest
Warning

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

Go to latest
Published: Mar 18, 2020 License: Apache-2.0 Imports: 8 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.

Types

type AttributeTokens

type AttributeTokens struct {
	Name   Token
	Equals Token
}

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

type BinaryOpTokens

type BinaryOpTokens struct {
	Operator Token
}

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

type BlockTokens

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

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

type BodyTokens

type BodyTokens struct {
	EndOfFile Token
}

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

type BracketTraverserTokens

type BracketTraverserTokens struct {
	OpenBracket  Token
	Index        Token
	CloseBracket Token
}

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

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.

type DotTraverserTokens

type DotTraverserTokens struct {
	Dot   Token
	Index Token
}

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

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.

type FunctionCallTokens

type FunctionCallTokens struct {
	Name       Token
	OpenParen  Token
	CloseParen Token
}

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

type IndexTokens

type IndexTokens struct {
	OpenBracket  Token
	CloseBracket Token
}

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

type LiteralValueTokens

type LiteralValueTokens struct {
	Value []Token
}

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

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.

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.

type ScopeTraversalTokens

type ScopeTraversalTokens struct {
	Root      Token
	Traversal []TraverserTokens
}

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

type SplatTokens

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

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

type TemplateTokens

type TemplateTokens struct {
	Open  Token
	Close Token
}

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

type Token

type Token struct {
	Raw            hclsyntax.Token
	LeadingTrivia  []Trivia
	TrailingTrivia []Trivia
}

Token represents an HCL2 syntax token with attached leading trivia.

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

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 {
	// 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 TupleConsTokens

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

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

type UnaryOpTokens

type UnaryOpTokens struct {
	Operator Token
}

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

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 (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