ast

package
v0.0.0-...-2f30d10 Latest Latest
Warning

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

Go to latest
Published: Mar 21, 2024 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AnnotationParamsTo

func AnnotationParamsTo[T any](val *T, a *Annotation) (t *T, err error)

func FindCommentLocationCommentGroup

func FindCommentLocationCommentGroup(fileNode *ast.File, fileSet *token.FileSet, pos token.Pos) *ast.CommentGroup

func FindDocLocationCommentGroup

func FindDocLocationCommentGroup(fileNode *ast.File, fileSet *token.FileSet, pos token.Pos) *ast.CommentGroup

func GetCommentText

func GetCommentText(comment *Comment) string

func GetCommentsText

func GetCommentsText(comments []*Comment) string

func GetRecvType

func GetRecvType(fd *ast.FuncDecl) *ast.TypeSpec

func InspectMapper

func InspectMapper[From any, To any](fileNode *ast.File, fileSet *token.FileSet, mapper func(*From) *To) []*To

func ParseFile

func ParseFile(inputFile string) (*ast.File, *token.FileSet, error)

Types

type Annotation

type Annotation struct {
	BeforeUseless *string    `(~(Comment | "@"))*`
	Comments      []*Comment `@@*`
	Name          Name       `"@" @@`
	Params        *Params    `@@?`
	Extends       *Extends   `@@?`
	Comment       *Comment   `@@?`
	AfterUseless  *string    `(~(Comment | "@"))*`
}

type AnnotationExtend

type AnnotationExtend struct {
	Pos      lexer.Position
	Comments []*Comment `@@*`
	Name     Name       `@@`
	Values   []Value    `("(" @@* ")")?`
	Value    Value      `("=" @@)? ","?`
	Comment  *Comment   `@@?`
}

type AnnotationGroup

type AnnotationGroup struct {
	Annotations []*Annotation `@@*`
}

func ParseAnnotation

func ParseAnnotation(fileName string, text string) (*AnnotationGroup, error)

func (*AnnotationGroup) FindAnnotationByName

func (ag *AnnotationGroup) FindAnnotationByName(name string) *Annotation

type AnnotationParam

type AnnotationParam struct {
	Pos      lexer.Position
	Comments []*Comment `@@*`
	Key      Key        `@@`
	Value    Value      `@@? ","?`
	Comment  *Comment   `@@?`
}

type BaseGenerator

type BaseGenerator[T any] struct {
	Tmpl     *template.Template
	DataList []*T
}

func (*BaseGenerator[T]) ExecuteTemplate

func (bg *BaseGenerator[T]) ExecuteTemplate(wr io.Writer, name string) error

func (*BaseGenerator[T]) GetImports

func (bg *BaseGenerator[T]) GetImports() []string

func (*BaseGenerator[T]) WriteBody

func (bg *BaseGenerator[T]) WriteBody(wr io.Writer) error

func (*BaseGenerator[T]) WriteConst

func (bg *BaseGenerator[T]) WriteConst(wr io.Writer) error

func (*BaseGenerator[T]) WriteInitFunc

func (bg *BaseGenerator[T]) WriteInitFunc(wr io.Writer) error

type Bool

type Bool struct {
	V Boolean `@("true" | "false") ","? `
}

func (Bool) Value

func (b Bool) Value() any

type Boolean

type Boolean bool

func (*Boolean) Capture

func (b *Boolean) Capture(values []string) error

type ClosedBracket

type ClosedBracket struct {
	Pos           lexer.Position
	ClosedBracket string `"}"`
}

type ClosedParenthesis

type ClosedParenthesis struct {
	Pos               lexer.Position
	ClosedParenthesis string `")"`
}

type Comment

type Comment struct {
	Pos  lexer.Position
	Text string `@Comment`
}

type Extends

type Extends struct {
	List          []*AnnotationExtend `"{" @@*`
	ClosedBracket ClosedBracket       `@@`
}

type Float

type Float struct {
	V float64 `@Float ","? `
}

func (Float) Value

func (f Float) Value() any

type Generator

type Generator interface {
	GetImports() []string
	WriteConst(wr io.Writer) error
	WriteInitFunc(wr io.Writer) error
	WriteBody(wr io.Writer) error
	ExecuteTemplate(wr io.Writer, name string) error
}

type Int

type Int struct {
	V int `@(("-" | "+")? Int) ","? `
}

func (Int) Value

func (i Int) Value() any

type Key

type Key struct {
	Pos  lexer.Position
	Text string `@Ident "="?`
}

type Name

type Name struct {
	Pos  lexer.Position
	Text string `@Ident`
}

type Params

type Params struct {
	List              []*AnnotationParam `"(" @@*`
	ClosedParenthesis ClosedParenthesis  `@@`
}

type String

type String struct {
	V string `@(String | Ident) ","? `
}

func (String) Value

func (s String) Value() any

type Uint

type Uint struct {
	V uint `@Int ","? `
}

func (Uint) Value

func (u Uint) Value() any

type Value

type Value interface{ Value() any }

Jump to

Keyboard shortcuts

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