package prnt

import "github.com/mmcloughlin/avo/internal/prnt"

Package prnt provides common functionality for code generators.

Index

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

func (g *Generator) AddError(err error)

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

func (g *Generator) BuildConstraint(expr string)

BuildConstraint outputs a build constraint.

func (*Generator) Comment

func (g *Generator) Comment(lines ...string)

Comment writes comment lines prefixed with "// ".

func (*Generator) Dedent

func (g *Generator) Dedent()

Dedent decrements the indent level.

func (*Generator) Indent

func (g *Generator) Indent()

Indent increments the indent level.

func (*Generator) Linef

func (g *Generator) Linef(format string, args ...any)

Linef prints formatted output terminated with a new line.

func (*Generator) NL

func (g *Generator) NL()

NL prints a new line.

func (*Generator) Printf

func (g *Generator) Printf(format string, args ...any)

Printf prints to the internal buffer.

func (*Generator) Raw

func (g *Generator) Raw() io.Writer

Raw provides direct access to the underlying output stream.

func (*Generator) Result

func (g *Generator) Result() ([]byte, error)

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

func (g *Generator) SetIndentString(indent string)

SetIndentString sets the string used for one level of indentation. Use Indent() and Dedent() to control indent level.

Source Files

printer.go

Version
v0.6.0 (latest)
Published
Jan 7, 2024
Platform
linux/amd64
Imports
5 packages
Last checked
1 month ago

Tools for package owners.