Documentation ¶
Overview ¶
Package prnt provides common functionality for code generators.
Index ¶
- type Generator
- func (g *Generator) AddError(err error)
- func (g *Generator) BuildConstraint(expr string)
- func (g *Generator) Comment(lines ...string)
- func (g *Generator) Dedent()
- func (g *Generator) Indent()
- func (g *Generator) Linef(format string, args ...any)
- func (g *Generator) NL()
- func (g *Generator) Printf(format string, args ...any)
- func (g *Generator) Raw() io.Writer
- func (g *Generator) Result() ([]byte, error)
- func (g *Generator) SetIndentString(indent string)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Generator ¶
type Generator struct {
// contains filtered or unexported fields
}
Generator provides convenience methods for code generators. In particular it provides fmt-like methods which print to an internal buffer. It also allows any errors to be stored so they can be checked at the end, rather than having error checks obscuring the code generation.
func (*Generator) AddError ¶
AddError records an error in code generation. The first non-nil error will prevent printing operations from writing anything else, and the error will be returned from Result().
func (*Generator) BuildConstraint ¶ added in v0.6.0
BuildConstraint outputs a build constraint.
func (*Generator) Dedent ¶ added in v0.3.0
func (g *Generator) Dedent()
Dedent decrements the indent level.
func (*Generator) Indent ¶ added in v0.3.0
func (g *Generator) Indent()
Indent increments the indent level.
func (*Generator) Result ¶
Result returns the printed bytes. If any error was recorded with AddError during code generation, the first such error will be returned here.
func (*Generator) SetIndentString ¶ added in v0.3.0
SetIndentString sets the string used for one level of indentation. Use Indent() and Dedent() to control indent level.