astparser

package
v0.0.40-alpha4 Latest Latest
Warning

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

Go to latest
Published: May 9, 2022 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetBooleanValueFromExpr

func GetBooleanValueFromExpr(expr ast.Expr) bool

func GetComposeLitInUnaryExpr

func GetComposeLitInUnaryExpr(expr ast.Expr) *ast.CompositeLit

func GetCompositeStmtInFunc

func GetCompositeStmtInFunc(fn *ast.FuncDecl) *ast.CompositeLit

func GetEltsInFunc

func GetEltsInFunc(fn *ast.FuncDecl) []ast.Expr

given a function node, it gets the list of elts in the func works for both edges in GetEdges() func and list of privacy rules in Rules

func GetExprToBasicLit

func GetExprToBasicLit(expr ast.Expr) *ast.BasicLit

func GetExprToCompositeLit

func GetExprToCompositeLit(expr ast.Expr) *ast.CompositeLit

func GetExprToCompositeLitAllowUnaryExpr

func GetExprToCompositeLitAllowUnaryExpr(expr ast.Expr) *ast.CompositeLit

func GetExprToIdent

func GetExprToIdent(expr ast.Expr) *ast.Ident

func GetExprToKeyValueExpr

func GetExprToKeyValueExpr(expr ast.Expr) *ast.KeyValueExpr

func GetExprToSelectorExpr

func GetExprToSelectorExpr(expr ast.Expr) *ast.SelectorExpr

func GetExprToUnaryExpr

func GetExprToUnaryExpr(expr ast.Expr) *ast.UnaryExpr

func GetLastExpr

func GetLastExpr(exprs []ast.Expr) ast.Expr

func GetLastReturnStmtExpr

func GetLastReturnStmtExpr(fn *ast.FuncDecl) ast.Expr

func GetLastStatement

func GetLastStatement(stmts []ast.Stmt) ast.Stmt

func GetStringList

func GetStringList(result *Result) []string

func GetStringListFromExpr

func GetStringListFromExpr(expr ast.Expr) []string

func GetTypeNameFromExpr

func GetTypeNameFromExpr(expr ast.Expr) string

GetTypeNameFromExpr takes an ast Expr and returns the underlying type Given the following Expr:

(*ast.SelectorExpr)(0xc000256440)({
	X: (*ast.Ident)(0xc000256400)(ent),
	Sel: (*ast.Ident)(0xc000256420)(ActionConfig)
 }),

function returns ent.ActionConfig

func GetUnderylingStringFromLiteralExpr

func GetUnderylingStringFromLiteralExpr(expr ast.Expr) string

Takes an Expr and converts it to the underlying string without quotes For example: in the GetEdges method below,

return ent.EdgeMap{
	"User": ent.AssociationEdgeGroup{
   GroupStatusName: "Rsvp",

...

	},
}

Calling this with the "User" Expr returns `User` and calling it with the "Rsvp" Expr returns `Rsvp`

func IsFalseBooleanResult

func IsFalseBooleanResult(result *Result) bool

func IsTrueBooleanResult

func IsTrueBooleanResult(result *Result) bool

Types

type Format

type Format string

Format indicates whether identName in Result is a function or type

const (
	// FunctionFormat is for declarations like field.IntType()
	FunctionFormat Format = "func"

	// TypFormat is for declarations like &field.StringDataType{}
	TypFormat Format = "type"
)

type Result

type Result struct {
	ContainsMap bool
	Slice       bool
	PkgName     string
	IdentName   string
	Format      Format
	Literal     string
	LiteralKind token.Token
	Pointer     bool

	Key   string  // key if Result is a Map
	Value *Result // Value if Result is a Map

	Elems      Results // Sub-elements in a slice or map
	Args       Results // Arguments to a function
	Attributes Results // Attributes/configurations on the object.

	Expr ast.Expr
	// contains filtered or unexported fields
}

Result is returned by Parse after parsing an AST. It encodes the tree in a more-friendly way It's not exhaustive and only supports what has currently been tested

func Parse

func Parse(expr ast.Expr) (*Result, error)

Parse takes an element received from an AST tree and parses it into a more-friendly format

func ParseFieldType

func ParseFieldType(field *ast.Field) (*Result, error)

ParseFieldType is a helper function to parse the type of a field

func (*Result) GetTypeName

func (result *Result) GetTypeName() string

func (*Result) IsScalarType

func (result *Result) IsScalarType(name string) bool

type Results

type Results []*Result

Results is a named type for a list of Results

Jump to

Keyboard shortcuts

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