format

package
v2.12.1 Latest Latest
Warning

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

Go to latest
Published: Oct 23, 2020 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ExpressionGenerator

type ExpressionGenerator interface {
	// GetPrecedence returns the precedence for the indicated expression. Lower numbers bind more tightly than higher
	// numbers.
	GetPrecedence(expr model.Expression) int

	// GenAnonymousFunctionExpression generates code for an AnonymousFunctionExpression.
	GenAnonymousFunctionExpression(w io.Writer, expr *model.AnonymousFunctionExpression)
	// GenBinaryOpExpression generates code for a BinaryOpExpression.
	GenBinaryOpExpression(w io.Writer, expr *model.BinaryOpExpression)
	// GenConditionalExpression generates code for a ConditionalExpression.
	GenConditionalExpression(w io.Writer, expr *model.ConditionalExpression)
	// GenForExpression generates code for a ForExpression.
	GenForExpression(w io.Writer, expr *model.ForExpression)
	// GenFunctionCallExpression generates code for a FunctionCallExpression.
	GenFunctionCallExpression(w io.Writer, expr *model.FunctionCallExpression)
	// GenIndexExpression generates code for an IndexExpression.
	GenIndexExpression(w io.Writer, expr *model.IndexExpression)
	// GenLiteralValueExpression generates code for a LiteralValueExpression.
	GenLiteralValueExpression(w io.Writer, expr *model.LiteralValueExpression)
	// GenObjectConsExpression generates code for an ObjectConsExpression.
	GenObjectConsExpression(w io.Writer, expr *model.ObjectConsExpression)
	// GenRelativeTraversalExpression generates code for a RelativeTraversalExpression.
	GenRelativeTraversalExpression(w io.Writer, expr *model.RelativeTraversalExpression)
	// GenScopeTraversalExpression generates code for a ScopeTraversalExpression.
	GenScopeTraversalExpression(w io.Writer, expr *model.ScopeTraversalExpression)
	// GenSplatExpression generates code for a SplatExpression.
	GenSplatExpression(w io.Writer, expr *model.SplatExpression)
	// GenTemplateExpression generates code for a TemplateExpression.
	GenTemplateExpression(w io.Writer, expr *model.TemplateExpression)
	// GenTemplateJoinExpression generates code for a TemplateJoinExpression.
	GenTemplateJoinExpression(w io.Writer, expr *model.TemplateJoinExpression)
	// GenTupleConsExpression generates code for a TupleConsExpression.
	GenTupleConsExpression(w io.Writer, expr *model.TupleConsExpression)
	// GenUnaryOpExpression generates code for a UnaryOpExpression.
	GenUnaryOpExpression(w io.Writer, expr *model.UnaryOpExpression)
}

ExpressionGenerator is an interface that can be implemented in order to generate code for semantically-analyzed HCL2 expressions using a Formatter.

type Formatter

type Formatter struct {
	// The current indent level as a string.
	Indent string
	// contains filtered or unexported fields
}

Formatter is a convenience type that implements a number of common utilities used to emit source code. It implements the io.Writer interface.

func NewFormatter

func NewFormatter(g ExpressionGenerator) *Formatter

NewFormatter creates a new emitter targeting the given io.Writer that will use the given ExpressionGenerator when generating code.

func (*Formatter) Fgen

func (e *Formatter) Fgen(w io.Writer, vs ...interface{})

Fgen generates code for a list of strings and expression trees. The former are written directly to the destination; the latter are recursively generated using the appropriate gen* functions.

func (*Formatter) Fgenf

func (e *Formatter) Fgenf(w io.Writer, format string, args ...interface{})

Fgenf generates code using a format string and its arguments. Any arguments that are BoundNode values are wrapped in a Func that calls the appropriate recursive generation function. This allows for the composition of standard format strings with expression/property code gen (e.e. `e.genf(w, ".apply(__arg0 => %v)", then)`, where `then` is an expression tree).

func (*Formatter) Fprint

func (e *Formatter) Fprint(w io.Writer, a ...interface{})

Fprint prints one or more values to the generator's output stream.

func (*Formatter) Fprintf

func (e *Formatter) Fprintf(w io.Writer, format string, a ...interface{})

Fprintf prints a formatted message to the generator's output stream.

func (*Formatter) Fprintln

func (e *Formatter) Fprintln(w io.Writer, a ...interface{})

Fprintln prints one or more values to the generator's output stream, followed by a newline.

func (*Formatter) Indented

func (e *Formatter) Indented(f func())

Indented bumps the current indentation level, invokes the given function, and then resets the indentation level to its prior value.

type Func

type Func func(f fmt.State, c rune)

Func is a function type that implements the fmt.Formatter interface. This can be used to conveniently implement this interface for types defined in other packages.

func (Func) Format

func (p Func) Format(f fmt.State, c rune)

Format invokes the Func's underlying function.

Jump to

Keyboard shortcuts

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