grinder

package
v0.0.0-...-2dcfb05 Latest Latest
Warning

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

Go to latest
Published: Jun 24, 2021 License: BSD-3-Clause Imports: 16 Imported by: 5

Documentation

Overview

Package grinder defines the API for individual grinding bits.

Index

Constants

View Source
const (
	Insert = 1 + iota
	Delete
)

Variables

This section is empty.

Functions

func BlockList

func BlockList(x ast.Node) []ast.Stmt

BlockList returns the list of statements contained by the block x, when x is an *ast.BlockStmt, *ast.CommClause, or *ast.CaseClause. Otherwise BlockList returns nil.

func Diff

func Diff(old, new string) []byte

func GrindFuncDecls

func GrindFuncDecls(ctxt *Context, pkg *Package, fn func(ctxt *Context, pkg *Package, edit *EditBuffer, decl *ast.FuncDecl))

func IsGotoTarget

func IsGotoTarget(blocks *block.Graph, x ast.Stmt) bool

func IsTerminatingStmt

func IsTerminatingStmt(blocks *block.Graph, x ast.Stmt) bool

func Unlabel

func Unlabel(x ast.Stmt) ast.Stmt

Types

type Context

type Context struct {
	Logf     func(format string, args ...interface{})
	Errors   bool
	Grinders []Func
}

func (*Context) Errorf

func (ctxt *Context) Errorf(format string, args ...interface{})

func (*Context) GrindFiles

func (ctxt *Context) GrindFiles(files ...string) *Package

func (*Context) GrindPackage

func (ctxt *Context) GrindPackage(path string) *Package

type EditBuffer

type EditBuffer struct {
	// contains filtered or unexported fields
}

func NewEditBuffer

func NewEditBuffer(pkg *Package, filename string, f *ast.File) *EditBuffer

func (*EditBuffer) Apply

func (b *EditBuffer) Apply() string

func (*EditBuffer) BeforeComments

func (b *EditBuffer) BeforeComments(start token.Pos) token.Pos

BeforeComments rewinds start past any blank lines or line comments and return the result. It does not rewind past leading blank lines: the returned position, if changed, is always the start of a non-blank line.

func (*EditBuffer) CopyLine

func (b *EditBuffer) CopyLine(startp, endp, insertp token.Pos)

func (*EditBuffer) Delete

func (b *EditBuffer) Delete(startp, endp token.Pos)

func (*EditBuffer) DeleteLine

func (b *EditBuffer) DeleteLine(startp, endp token.Pos)

func (*EditBuffer) End

func (b *EditBuffer) End(x ast.Node) token.Pos

End returns x.End() except that it works around buggy results from the implementation of *ast.LabeledStmt and *ast.EmptyStmt. The node x must be located within b's source file. See golang.org/issue/9979.

func (*EditBuffer) Insert

func (b *EditBuffer) Insert(p token.Pos, text string)

func (*EditBuffer) NumEdits

func (b *EditBuffer) NumEdits() int

func (*EditBuffer) Replace

func (b *EditBuffer) Replace(start, end token.Pos, text string)

func (*EditBuffer) TextAt

func (b *EditBuffer) TextAt(start, end token.Pos) string

type Func

type Func func(*Context, *Package)

type Package

type Package struct {
	ImportPath string
	Files      []*ast.File
	Filenames  []string
	FileSet    *token.FileSet
	Types      *types.Package
	TypesError error
	Info       types.Info
	// contains filtered or unexported fields
}

func (*Package) LookupAtPos

func (pkg *Package) LookupAtPos(fn *ast.FuncDecl, pos token.Pos, name string) types.Object

func (*Package) Modified

func (p *Package) Modified(name string) bool

func (*Package) OrigSrc

func (p *Package) OrigSrc(name string) string

func (*Package) Rewrite

func (p *Package) Rewrite(name, content string)

func (*Package) Src

func (p *Package) Src(name string) string

Jump to

Keyboard shortcuts

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