Package printer
import "go/printer"
The printer package implements printing of AST nodes.
Package files
nodes.go printer.goConstants
General printing is controlled with these Config.Mode flags.
const (
GenHTML uint = 1 << iota // generate HTML
RawFormat // do not use a tabwriter; if set, UseSpaces is ignored
TabIndent // use tabs for indentation independent of UseSpaces
UseSpaces // use spaces instead of tabs for alignment
)
func Fprint
func Fprint(output io.Writer, node interface{}) os.Error
Fprint "pretty-prints" an AST node to output. It calls Config.Fprint with default settings.
type Config
A Config node controls the output of Fprint.
type Config struct {
Mode uint // default: 0
Tabwidth int // default: 8
Styler Styler // default: nil
}
func (*Config) Fprint
func (cfg *Config) Fprint(output io.Writer, node interface{}) (int, os.Error)
Fprint "pretty-prints" an AST node to output and returns the number of bytes written and an error (if any) for a given configuration cfg. The node type must be *ast.File, or assignment-compatible to ast.Expr, ast.Decl, or ast.Stmt.
type HTMLTag
An HTMLTag specifies a start and end tag.
type HTMLTag struct {
Start, End string // empty if tags are absent
}
type Styler
A Styler specifies formatting of line tags and elementary Go words. A format consists of text and a (possibly empty) surrounding HTML tag.
type Styler interface {
LineTag(line int) ([]byte, HTMLTag)
Comment(c *ast.Comment, line []byte) ([]byte, HTMLTag)
BasicLit(x *ast.BasicLit) ([]byte, HTMLTag)
Ident(id *ast.Ident) ([]byte, HTMLTag)
Token(tok token.Token) ([]byte, HTMLTag)
}
