Documentation ¶
Index ¶
- type ExpressionGenerator
- type Formatter
- func (e *Formatter) Fgen(w io.Writer, vs ...interface{})
- func (e *Formatter) Fgenf(w io.Writer, format string, args ...interface{})
- func (e *Formatter) Fprint(w io.Writer, a ...interface{})
- func (e *Formatter) Fprintf(w io.Writer, format string, a ...interface{})
- func (e *Formatter) Fprintln(w io.Writer, a ...interface{})
- func (e *Formatter) Indented(f func())
- type Func
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ExpressionGenerator ¶
type ExpressionGenerator interface { // 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 ¶
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 ¶
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).