parser

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Oct 7, 2021 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Parse

func Parse(fset *token.FileSet, target string, src interface{}, mode parser.Mode) (pkgs map[string]*ast.Package, err error)

Parse parses a single Go source file. The target specifies the Go source file. If the file couldn't be read, a nil map and the respective error are returned.

func ParseDir

func ParseDir(fset *token.FileSet, path string, filter func(os.FileInfo) bool, mode parser.Mode) (pkgs map[string]*ast.Package, first error)

ParseDir calls ParseFSDir by passing a local filesystem.

func ParseFSDir

func ParseFSDir(fset *token.FileSet, fs FileSystem, path string, filter func(os.FileInfo) bool, mode parser.Mode) (pkgs map[string]*ast.Package, first error)

ParseFSDir calls ParseFile for all files with names ending in ".go" in the directory specified by path and returns a map of package name -> package AST with all the packages found.

If filter != nil, only the files with os.FileInfo entries passing through the filter (and ending in ".go") are considered. The mode bits are passed to ParseFile unchanged. Position information is recorded in fset, which must not be nil.

If the directory couldn't be read, a nil map and the respective error are returned. If a parse error occurred, a non-nil but incomplete map and the first error encountered are returned.

func ParseFSFile

func ParseFSFile(fset *token.FileSet, fs FileSystem, filename string, src interface{}, mode parser.Mode) (f *ast.File, err error)

ParseFSFile parses the source code of a single Go source file and returns the corresponding ast.File node.

Types

type FileSystem

type FileSystem interface {
	ReadDir(dirname string) ([]os.FileInfo, error)
	ReadFile(filename string) ([]byte, error)
	Join(elem ...string) string
}

FileSystem represents a file system.

Jump to

Keyboard shortcuts

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