parse

package
v0.0.0-...-aa68b5e Latest Latest
Warning

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

Go to latest
Published: Jan 13, 2021 License: MIT Imports: 10 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

Config is the config used to load file/packages. Config.Dir is overwritten before loading files.

Functions

This section is empty.

Types

type GoFile

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

GoFile define a parsed go file.

func File

func File(filePath string) (*GoFile, error)

File parse the file at the given path and return a new *GoFile. Test file (*_test.go) are not supported.

func (*GoFile) AST

func (f *GoFile) AST() *ast.File

AST return the *ast.File object of the file.

func (*GoFile) Bytes

func (f *GoFile) Bytes() ([]byte, error)

Bytes convert the AST of the file as an array of byte.

func (*GoFile) Dir

func (f *GoFile) Dir() string

Dir return the parent directory of the go file

func (*GoFile) FileSet

func (f *GoFile) FileSet() *token.FileSet

FileSet return a token.FileSet if the GoFile belong to a GoPackage and nil otherwise.

func (*GoFile) Fprint

func (f *GoFile) Fprint(output io.Writer) error

Fprint "pretty-print" the AST of the file to output.

func (*GoFile) Name

func (f *GoFile) Name() string

Name return the name of the file

func (*GoFile) Path

func (f *GoFile) Path() string

Path return the go file absolute path.

func (*GoFile) WriteFile

func (f *GoFile) WriteFile(path string) error

WriteFile method write the GoFile source code in the file at the given path.

type GoPackage

type GoPackage struct {
	Files []*GoFile
	// contains filtered or unexported fields
}

GoPackage define a loaded/parsed go package.

func Package

func Package(pkgPath string, parseSubPkgs bool) (*GoPackage, error)

Package parse an entire package at the given path and return a new *GoPackage.

func (*GoPackage) FileSet

func (p *GoPackage) FileSet() *token.FileSet

FileSet return the fileset of the package.

func (*GoPackage) Name

func (p *GoPackage) Name() string

Name return the package name.

func (*GoPackage) Path

func (p *GoPackage) Path() string

Path return the package absolute path.

func (*GoPackage) PkgPath

func (p *GoPackage) PkgPath() string

PkgPath return the package import path.

func (*GoPackage) SubPkgs

func (p *GoPackage) SubPkgs() []*GoPackage

SubPkgs return all the subpackages.

func (*GoPackage) WritePkg

func (p *GoPackage) WritePkg(path string, writeSubPkgs bool) error

WritePkg method write the go file source code in the file at the given path.

Directories

Path Synopsis
_data

Jump to

Keyboard shortcuts

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