printer

package
v0.7.19 Latest Latest
Warning

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

Go to latest
Published: Mar 15, 2021 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Overview

Package printer implements printing of AST nodes.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Fprint

func Fprint(output io.Writer, fset *token.FileSet, node interface{}) error

Fprint "pretty-prints" an AST node to output. It calls Config.Fprint with default settings. Note that gofmt uses tabs for indentation but spaces for alignment; use format.Node (package golang/format) for output that matches gofmt.

Types

type CommentedNode

type CommentedNode struct {
	Node     interface{} // *ast.File, or ast.Expr, ast.Decl, ast.Spec, or ast.Stmt
	Comments []*ast.CommentGroup
}

A CommentedNode bundles an AST node and corresponding comments. It may be provided as argument to any of the Fprint functions.

type CommentedStmt

type CommentedStmt struct {
	Comments *ast.CommentGroup
	ast.Stmt
}

CommentedStmt represents a statement with comments.

type Config

type Config struct {
	Mode     Mode // default: 0
	Tabwidth int  // default: 8
	Indent   int  // default: 0 (all code is indented at least by this much)
}

A Config node controls the output of Fprint.

func (*Config) Fprint

func (cfg *Config) Fprint(output io.Writer, fset *token.FileSet, node interface{}) error

Fprint "pretty-prints" an AST node to output for a given configuration cfg. Position information is interpreted relative to the file set fset. The node type must be *ast.File, *CommentedNode, []ast.Decl, []ast.Stmt, or assignment-compatible to ast.Expr, ast.Decl, ast.Spec, or ast.Stmt.

type Mode

type Mode uint

A Mode value is a set of flags (or 0). They control printing.

const (
	// RawFormat - do not use a tabwriter; if set, UseSpaces is ignored
	RawFormat Mode = 1 << iota
	// TabIndent - use tabs for indentation independent of UseSpaces
	TabIndent
	// UseSpaces - use spaces instead of tabs for alignment
	UseSpaces
	// SourcePos - emit //line directives to preserve original source positions
	SourcePos
)

type ReservedExpr

type ReservedExpr struct {
	ast.Expr
}

ReservedExpr represents a reserved expression.

Jump to

Keyboard shortcuts

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