fileparser

package
v0.0.0-...-3c35577 Latest Latest
Warning

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

Go to latest
Published: Apr 4, 2023 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

https://medium.com/justforfunc/understanding-go-programs-with-go-parser-c4e88a6edb87

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ConstValue

type ConstValue struct {
	Name       string
	Value      string
	Node       *Node
	IsTopLevel bool
}

type FileInfo

type FileInfo struct {
	PackageName   string
	FileBuffer    []byte
	RootNode      *Node
	FileConstants []ConstValue
}

FileInfo is the output of ReadFile().

func ReadFile

func ReadFile(filepath string) FileInfo

ReadFile parses a Go source file and returns informations about it.

type Node

type Node struct {
	Bytes           string
	Name            string
	BytesIndexBegin int
	BytesIndexEnd   int
	TypeStr         string

	DepthLevel int
	Father     *Node
	Children   []*Node
	Index      int // index of this node among the children of Father
	// contains filtered or unexported fields
}

func (*Node) ComputeStringExpression

func (n *Node) ComputeStringExpression(fileConstants []ConstValue) (str string, incomplete bool)

ComputeStringExpression compute/concatenate (recursively) a constant string expression, e.g. "foo"+"bar"+string("baz") will return ("foobarbaz", false).

This is a work in process, trying to compute all constants string expressions that we can know at compile-time.

If it contains something which is not processable, it will return incomplete=true and all unprocessable parts will be replaced by "???" in str.

func (*Node) Display

func (n *Node) Display()

func (*Node) IsCommentGroupWithComment

func (n *Node) IsCommentGroupWithComment(comment string) bool

IsCommentGroupWithComment returns true if this is a CommentGroup with the comment in it.

func (*Node) IsInScope

func (n *Node) IsInScope(other *Node) bool

IsInScope returns true if "n" can access "other" i.e. the father of "other" is a father or grand-father or grand-XXX-father or "n".

func (*Node) NextNode

func (n *Node) NextNode() *Node

func (*Node) Visit

func (n *Node) Visit(fnCall func(*Node))

Jump to

Keyboard shortcuts

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