astutil

package
v0.0.0-...-5b643b5 Latest Latest
Warning

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

Go to latest
Published: Aug 31, 2025 License: Apache-2.0 Imports: 21 Imported by: 0

Documentation

Overview

Package astutil defines utilities for ast and dst.

parser defines general utilities for codegen.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BufPrintf

func BufPrintf(w io.Writer) (func(format string, args ...any), func() error)

BufPrintf wraps w and returns it in a function which works as like printf. Call second return value to retrieve io error in case it happens.

func FieldAst

func FieldAst(st *ast.StructType) iter.Seq[FieldDescAst]

func FieldDst

func FieldDst(st *dst.StructType) iter.Seq[FieldDescDst]

func Nth

func Nth[I ints](d I) string

func PrintAstExprPanicking

func PrintAstExprPanicking(expr ast.Expr) string

func PrintFieldDesc

func PrintFieldDesc(typeName string, i int, field *types.Var) string

func PrintFileHeader

func PrintFileHeader(w io.Writer, af *ast.File, fset *token.FileSet) error

func PrintTypeParamsAst

func PrintTypeParamsAst(ts *ast.TypeSpec) string

func PrintTypeParamsDst

func PrintTypeParamsDst(ts *dst.TypeSpec) string

func TrimPackageComment

func TrimPackageComment(f *dst.File)

TrimPackageComment removes all package comment lines except build constratints.

func TypeToAst

func TypeToAst(ty types.Type, pkgPath string, importMap imports.ImportMap) ast.Expr

func TypeToDst

func TypeToDst(ty types.Type, pkgPath string, importMap imports.ImportMap) dst.Expr

Types

type FieldDescAst

type FieldDescAst struct {
	// Pos indicates ith field of the type.
	Pos int
	// Name is field name.
	Name  string
	Field *ast.Field
}

type FieldDescDst

type FieldDescDst struct {
	Pos   int
	Name  string
	Field *dst.Field
}

type Parser

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

Parser is as much similar as `go/parser` but ignores specific nodes in file.

func NewParser

func NewParser(dir string) *Parser

func (*Parser) ParseFile

func (p *Parser) ParseFile(fset *token.FileSet, filename string, src []byte) (*ast.File, error)

Jump to

Keyboard shortcuts

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