ast

package
v1.6.3 Latest Latest
Warning

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

Go to latest
Published: Dec 20, 2023 License: GPL-3.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	NilIndent  = ""
	WhiteSpace = " "
	Indent     = "\t"
	NewLine    = "\n"
)

Variables

This section is empty.

Functions

func DuplicateStmtError

func DuplicateStmtError(pos token.Position, msg string) error

DuplicateStmtError represents a duplicate statement error.

func Fprint

func Fprint(w io.Writer, x interface{}, f FieldFilter) error

Fprint prints the value of x to the writer w.

func NotNilFilter

func NotNilFilter(_ string, v reflect.Value) bool

NotNilFilter returns true for field values that are not nil, it returns false otherwise.

func Print

func Print(x interface{}) error

func SyntaxError

func SyntaxError(pos token.Position, format string, v ...interface{}) error

SyntaxError represents a syntax error.

Types

type AST

type AST struct {
	Filename string
	Stmts    []Stmt
	// contains filtered or unexported fields
}

AST represents a parsed API file.

func (*AST) Format

func (a *AST) Format(w io.Writer)

Format formats the AST.

func (*AST) FormatForUnitTest

func (a *AST) FormatForUnitTest(w io.Writer)

FormatForUnitTest formats the AST for unit test.

func (*AST) Print

func (a *AST) Print()

Print prints the AST.

type AnyDataType

type AnyDataType struct {
	// Any is the any token node.
	Any *TokenNode
	// contains filtered or unexported fields
}

AnyDataType is the any data type.

func (*AnyDataType) CanEqual

func (t *AnyDataType) CanEqual() bool

func (*AnyDataType) CommentGroup

func (t *AnyDataType) CommentGroup() (head, leading CommentGroup)

func (*AnyDataType) ContainsStruct

func (t *AnyDataType) ContainsStruct() bool

func (*AnyDataType) End

func (t *AnyDataType) End() token.Position

func (*AnyDataType) Format

func (t *AnyDataType) Format(prefix ...string) string

func (*AnyDataType) HasHeadCommentGroup

func (t *AnyDataType) HasHeadCommentGroup() bool

func (*AnyDataType) HasLeadingCommentGroup

func (t *AnyDataType) HasLeadingCommentGroup() bool

func (*AnyDataType) Pos

func (t *AnyDataType) Pos() token.Position

func (*AnyDataType) RawText

func (t *AnyDataType) RawText() string

type ArrayDataType

type ArrayDataType struct {
	// LB is the left bracket token node.
	LBrack *TokenNode
	// Len is the array length.
	Length *TokenNode
	// RB is the right bracket token node.
	RBrack *TokenNode
	// DataType is the array data type.
	DataType DataType
	// contains filtered or unexported fields
}

ArrayDataType is the array data type.

func (*ArrayDataType) CanEqual

func (t *ArrayDataType) CanEqual() bool

func (*ArrayDataType) CommentGroup

func (t *ArrayDataType) CommentGroup() (head, leading CommentGroup)

func (*ArrayDataType) ContainsStruct

func (t *ArrayDataType) ContainsStruct() bool

func (*ArrayDataType) End

func (t *ArrayDataType) End() token.Position

func (*ArrayDataType) Format

func (t *ArrayDataType) Format(prefix ...string) string

func (*ArrayDataType) HasHeadCommentGroup

func (t *ArrayDataType) HasHeadCommentGroup() bool

func (*ArrayDataType) HasLeadingCommentGroup

func (t *ArrayDataType) HasLeadingCommentGroup() bool

func (*ArrayDataType) Pos

func (t *ArrayDataType) Pos() token.Position

func (*ArrayDataType) RawText

func (t *ArrayDataType) RawText() string

type AtDocGroupStmt

type AtDocGroupStmt struct {
	AtDoc  *TokenNode
	LParen *TokenNode
	Values []*KVExpr
	RParen *TokenNode
}

func (*AtDocGroupStmt) CommentGroup

func (a *AtDocGroupStmt) CommentGroup() (head, leading CommentGroup)

func (*AtDocGroupStmt) End

func (a *AtDocGroupStmt) End() token.Position

func (*AtDocGroupStmt) Format

func (a *AtDocGroupStmt) Format(prefix ...string) string

func (*AtDocGroupStmt) HasHeadCommentGroup

func (a *AtDocGroupStmt) HasHeadCommentGroup() bool

func (*AtDocGroupStmt) HasLeadingCommentGroup

func (a *AtDocGroupStmt) HasLeadingCommentGroup() bool

func (*AtDocGroupStmt) Pos

func (a *AtDocGroupStmt) Pos() token.Position

type AtDocLiteralStmt

type AtDocLiteralStmt struct {
	AtDoc *TokenNode
	Value *TokenNode
}

func (*AtDocLiteralStmt) CommentGroup

func (a *AtDocLiteralStmt) CommentGroup() (head, leading CommentGroup)

func (*AtDocLiteralStmt) End

func (a *AtDocLiteralStmt) End() token.Position

func (*AtDocLiteralStmt) Format

func (a *AtDocLiteralStmt) Format(prefix ...string) string

func (*AtDocLiteralStmt) HasHeadCommentGroup

func (a *AtDocLiteralStmt) HasHeadCommentGroup() bool

func (*AtDocLiteralStmt) HasLeadingCommentGroup

func (a *AtDocLiteralStmt) HasLeadingCommentGroup() bool

func (*AtDocLiteralStmt) Pos

func (a *AtDocLiteralStmt) Pos() token.Position

type AtDocStmt

type AtDocStmt interface {
	Stmt
	// contains filtered or unexported methods
}

type AtHandlerStmt

type AtHandlerStmt struct {
	AtHandler *TokenNode
	Name      *TokenNode
}

func (*AtHandlerStmt) CommentGroup

func (a *AtHandlerStmt) CommentGroup() (head, leading CommentGroup)

func (*AtHandlerStmt) End

func (a *AtHandlerStmt) End() token.Position

func (*AtHandlerStmt) Format

func (a *AtHandlerStmt) Format(prefix ...string) string

func (*AtHandlerStmt) HasHeadCommentGroup

func (a *AtHandlerStmt) HasHeadCommentGroup() bool

func (*AtHandlerStmt) HasLeadingCommentGroup

func (a *AtHandlerStmt) HasLeadingCommentGroup() bool

func (*AtHandlerStmt) Pos

func (a *AtHandlerStmt) Pos() token.Position

type AtServerStmt

type AtServerStmt struct {
	// AtServer is the @server token.
	AtServer *TokenNode
	// LParen is the left parenthesis token.
	LParen *TokenNode
	// Values is the key-value pairs.
	Values []*KVExpr
	// RParen is the right parenthesis token.
	RParen *TokenNode
}

AtServerStmt represents @server statement.

func (*AtServerStmt) CommentGroup

func (a *AtServerStmt) CommentGroup() (head, leading CommentGroup)

func (*AtServerStmt) End

func (a *AtServerStmt) End() token.Position

func (*AtServerStmt) Format

func (a *AtServerStmt) Format(prefix ...string) string

func (*AtServerStmt) HasHeadCommentGroup

func (a *AtServerStmt) HasHeadCommentGroup() bool

func (*AtServerStmt) HasLeadingCommentGroup

func (a *AtServerStmt) HasLeadingCommentGroup() bool

func (*AtServerStmt) Pos

func (a *AtServerStmt) Pos() token.Position

type BaseDataType

type BaseDataType struct {
	// Base is the base token node.
	Base *TokenNode
	// contains filtered or unexported fields
}

BaseDataType is a common id type which contains bool, uint8, uint16, uint32, uint64, int8, int16, int32, int64, float32, float64, complex64, complex128, string, int, uint, uintptr, byte, rune, any.

func (*BaseDataType) CanEqual

func (t *BaseDataType) CanEqual() bool

func (*BaseDataType) CommentGroup

func (t *BaseDataType) CommentGroup() (head, leading CommentGroup)

func (*BaseDataType) ContainsStruct

func (t *BaseDataType) ContainsStruct() bool

func (*BaseDataType) End

func (t *BaseDataType) End() token.Position

func (*BaseDataType) Format

func (t *BaseDataType) Format(prefix ...string) string

func (*BaseDataType) HasHeadCommentGroup

func (t *BaseDataType) HasHeadCommentGroup() bool

func (*BaseDataType) HasLeadingCommentGroup

func (t *BaseDataType) HasLeadingCommentGroup() bool

func (*BaseDataType) Pos

func (t *BaseDataType) Pos() token.Position

func (*BaseDataType) RawText

func (t *BaseDataType) RawText() string

type BodyExpr

type BodyExpr struct {
	LBrack *TokenNode
	RBrack *TokenNode
	Star   *TokenNode
	Value  *TokenNode
}

func (*BodyExpr) CommentGroup

func (e *BodyExpr) CommentGroup() (head, leading CommentGroup)

func (*BodyExpr) End

func (e *BodyExpr) End() token.Position

func (*BodyExpr) Format

func (e *BodyExpr) Format(...string) string

func (*BodyExpr) HasHeadCommentGroup

func (e *BodyExpr) HasHeadCommentGroup() bool

func (*BodyExpr) HasLeadingCommentGroup

func (e *BodyExpr) HasLeadingCommentGroup() bool

func (*BodyExpr) Pos

func (e *BodyExpr) Pos() token.Position

type BodyStmt

type BodyStmt struct {
	LParen *TokenNode
	Body   *BodyExpr
	RParen *TokenNode
}

func (*BodyStmt) CommentGroup

func (b *BodyStmt) CommentGroup() (head, leading CommentGroup)

func (*BodyStmt) End

func (b *BodyStmt) End() token.Position

func (*BodyStmt) Format

func (b *BodyStmt) Format(...string) string

func (*BodyStmt) HasHeadCommentGroup

func (b *BodyStmt) HasHeadCommentGroup() bool

func (*BodyStmt) HasLeadingCommentGroup

func (b *BodyStmt) HasLeadingCommentGroup() bool

func (*BodyStmt) Pos

func (b *BodyStmt) Pos() token.Position

type CommentGroup

type CommentGroup []*CommentStmt

CommentGroup represents a list of comments.

func (CommentGroup) Join

func (cg CommentGroup) Join(sep string) string

Join joins the comments with the given separator.

func (CommentGroup) List

func (cg CommentGroup) List() []string

List returns the list of comments.

func (CommentGroup) String

func (cg CommentGroup) String() string

String joins and returns the comment text.

func (CommentGroup) Valid

func (cg CommentGroup) Valid() bool

Valid returns true if the comment is valid.

type CommentStmt

type CommentStmt struct {
	// Comment is the comment token.
	Comment token.Token
}

CommentStmt represents a comment statement.

func (*CommentStmt) CommentGroup

func (c *CommentStmt) CommentGroup() (head, leading CommentGroup)

func (*CommentStmt) End

func (c *CommentStmt) End() token.Position

func (*CommentStmt) Format

func (c *CommentStmt) Format(prefix ...string) string

func (*CommentStmt) HasHeadCommentGroup

func (c *CommentStmt) HasHeadCommentGroup() bool

func (*CommentStmt) HasLeadingCommentGroup

func (c *CommentStmt) HasLeadingCommentGroup() bool

func (*CommentStmt) Pos

func (c *CommentStmt) Pos() token.Position

type DataType

type DataType interface {
	Expr

	// CanEqual returns true if the data type can be equal.
	CanEqual() bool
	// ContainsStruct returns true if the data type contains struct.
	ContainsStruct() bool
	// RawText returns the raw text of the data type.
	RawText() string
	// contains filtered or unexported methods
}

DataType represents the data type.

type ElemExpr

type ElemExpr struct {
	// Name is the field element name.
	Name []*TokenNode
	// DataType is the field data type.
	DataType DataType
	// Tag is the field tag.
	Tag *TokenNode
}

ElemExpr is the element expression.

func (*ElemExpr) CommentGroup

func (e *ElemExpr) CommentGroup() (head, leading CommentGroup)

func (*ElemExpr) End

func (e *ElemExpr) End() token.Position

func (*ElemExpr) Format

func (e *ElemExpr) Format(prefix ...string) string

func (*ElemExpr) HasHeadCommentGroup

func (e *ElemExpr) HasHeadCommentGroup() bool

func (*ElemExpr) HasLeadingCommentGroup

func (e *ElemExpr) HasLeadingCommentGroup() bool

func (*ElemExpr) IsAnonymous

func (e *ElemExpr) IsAnonymous() bool

IsAnonymous returns true if the element is anonymous.

func (*ElemExpr) Pos

func (e *ElemExpr) Pos() token.Position

type ElemExprList

type ElemExprList []*ElemExpr

ElemExprList is the element expression list.

type Expr

type Expr interface {
	Node
	// contains filtered or unexported methods
}

Expr represents an expression in the AST.

type FieldFilter

type FieldFilter func(name string, value reflect.Value) bool

A FieldFilter may be provided to Fprint to control the output.

type ImportGroupStmt

type ImportGroupStmt struct {
	// Import is the import token.
	Import *TokenNode
	// LParen is the left parenthesis token.
	LParen *TokenNode
	// Values is the import values.
	Values []*TokenNode
	// RParen is the right parenthesis token.
	RParen *TokenNode
}

func (*ImportGroupStmt) CommentGroup

func (i *ImportGroupStmt) CommentGroup() (head, leading CommentGroup)

func (*ImportGroupStmt) End

func (i *ImportGroupStmt) End() token.Position

func (*ImportGroupStmt) Format

func (i *ImportGroupStmt) Format(prefix ...string) string

func (*ImportGroupStmt) HasHeadCommentGroup

func (i *ImportGroupStmt) HasHeadCommentGroup() bool

func (*ImportGroupStmt) HasLeadingCommentGroup

func (i *ImportGroupStmt) HasLeadingCommentGroup() bool

func (*ImportGroupStmt) Pos

func (i *ImportGroupStmt) Pos() token.Position

type ImportLiteralStmt

type ImportLiteralStmt struct {
	// Import is the import token.
	Import *TokenNode
	// Value is the import value.
	Value *TokenNode
}

ImportLiteralStmt represents an import literal statement.

func (*ImportLiteralStmt) CommentGroup

func (i *ImportLiteralStmt) CommentGroup() (head, leading CommentGroup)

func (*ImportLiteralStmt) End

func (i *ImportLiteralStmt) End() token.Position

func (*ImportLiteralStmt) Format

func (i *ImportLiteralStmt) Format(prefix ...string) (result string)

func (*ImportLiteralStmt) HasHeadCommentGroup

func (i *ImportLiteralStmt) HasHeadCommentGroup() bool

func (*ImportLiteralStmt) HasLeadingCommentGroup

func (i *ImportLiteralStmt) HasLeadingCommentGroup() bool

func (*ImportLiteralStmt) Pos

func (i *ImportLiteralStmt) Pos() token.Position

type ImportStmt

type ImportStmt interface {
	Stmt
	// contains filtered or unexported methods
}

ImportStmt represents an import statement.

type InfoStmt

type InfoStmt struct {
	// Info is the info keyword.
	Info *TokenNode
	// LParen is the left parenthesis.
	LParen *TokenNode
	// Values is the info values.
	Values []*KVExpr
	// RParen is the right parenthesis.
	RParen *TokenNode
}

InfoStmt is the info statement.

func (*InfoStmt) CommentGroup

func (i *InfoStmt) CommentGroup() (head, leading CommentGroup)

func (*InfoStmt) End

func (i *InfoStmt) End() token.Position

func (*InfoStmt) Format

func (i *InfoStmt) Format(prefix ...string) string

func (*InfoStmt) HasHeadCommentGroup

func (i *InfoStmt) HasHeadCommentGroup() bool

func (*InfoStmt) HasLeadingCommentGroup

func (i *InfoStmt) HasLeadingCommentGroup() bool

func (*InfoStmt) Pos

func (i *InfoStmt) Pos() token.Position

type InterfaceDataType

type InterfaceDataType struct {
	// Interface is the interface token node.
	Interface *TokenNode
	// contains filtered or unexported fields
}

InterfaceDataType is the interface data type.

func (*InterfaceDataType) CanEqual

func (t *InterfaceDataType) CanEqual() bool

func (*InterfaceDataType) CommentGroup

func (t *InterfaceDataType) CommentGroup() (head, leading CommentGroup)

func (*InterfaceDataType) ContainsStruct

func (t *InterfaceDataType) ContainsStruct() bool

func (*InterfaceDataType) End

func (t *InterfaceDataType) End() token.Position

func (*InterfaceDataType) Format

func (t *InterfaceDataType) Format(prefix ...string) string

func (*InterfaceDataType) HasHeadCommentGroup

func (t *InterfaceDataType) HasHeadCommentGroup() bool

func (*InterfaceDataType) HasLeadingCommentGroup

func (t *InterfaceDataType) HasLeadingCommentGroup() bool

func (*InterfaceDataType) Pos

func (t *InterfaceDataType) Pos() token.Position

func (*InterfaceDataType) RawText

func (t *InterfaceDataType) RawText() string

type KVExpr

type KVExpr struct {
	// Key is the key of the key value expression.
	Key *TokenNode
	// Value is the value of the key value expression.
	Value *TokenNode
}

KVExpr is a key value expression.

func (*KVExpr) CommentGroup

func (i *KVExpr) CommentGroup() (head, leading CommentGroup)

func (*KVExpr) End

func (i *KVExpr) End() token.Position

func (*KVExpr) Format

func (i *KVExpr) Format(prefix ...string) string

func (*KVExpr) HasHeadCommentGroup

func (i *KVExpr) HasHeadCommentGroup() bool

func (*KVExpr) HasLeadingCommentGroup

func (i *KVExpr) HasLeadingCommentGroup() bool

func (*KVExpr) Pos

func (i *KVExpr) Pos() token.Position

type MapDataType

type MapDataType struct {
	// Map is the map token node.
	Map *TokenNode
	// Lbrack is the left bracket token node.
	LBrack *TokenNode
	// Key is the map key data type.
	Key DataType
	// Rbrack is the right bracket token node.
	RBrack *TokenNode
	// Value is the map value data type.
	Value DataType
	// contains filtered or unexported fields
}

MapDataType is the map data type.

func (*MapDataType) CanEqual

func (t *MapDataType) CanEqual() bool

func (*MapDataType) CommentGroup

func (t *MapDataType) CommentGroup() (head, leading CommentGroup)

func (*MapDataType) ContainsStruct

func (t *MapDataType) ContainsStruct() bool

func (*MapDataType) End

func (t *MapDataType) End() token.Position

func (*MapDataType) Format

func (t *MapDataType) Format(prefix ...string) string

func (*MapDataType) HasHeadCommentGroup

func (t *MapDataType) HasHeadCommentGroup() bool

func (*MapDataType) HasLeadingCommentGroup

func (t *MapDataType) HasLeadingCommentGroup() bool

func (*MapDataType) Pos

func (t *MapDataType) Pos() token.Position

func (*MapDataType) RawText

func (t *MapDataType) RawText() string

type Node

type Node interface {
	// Pos returns the position of the first character belonging to the node.
	Pos() token.Position
	// End returns the position of the first character immediately after the node.
	End() token.Position
	// Format returns the node's text after format.
	Format(...string) string
	// HasHeadCommentGroup returns true if the node has head comment group.
	HasHeadCommentGroup() bool
	// HasLeadingCommentGroup returns true if the node has leading comment group.
	HasLeadingCommentGroup() bool
	// CommentGroup returns the node's head comment group and leading comment group.
	CommentGroup() (head, leading CommentGroup)
}

Node represents a node in the AST.

type Option

type Option func(o *option)

type PathExpr

type PathExpr struct {
	Value *TokenNode
}

func (*PathExpr) CommentGroup

func (p *PathExpr) CommentGroup() (head, leading CommentGroup)

func (*PathExpr) End

func (p *PathExpr) End() token.Position

func (*PathExpr) Format

func (p *PathExpr) Format(prefix ...string) string

func (*PathExpr) HasHeadCommentGroup

func (p *PathExpr) HasHeadCommentGroup() bool

func (*PathExpr) HasLeadingCommentGroup

func (p *PathExpr) HasLeadingCommentGroup() bool

func (*PathExpr) Pos

func (p *PathExpr) Pos() token.Position

type PointerDataType

type PointerDataType struct {
	// Star is the star token node.
	Star *TokenNode
	// DataType is the pointer data type.
	DataType DataType
	// contains filtered or unexported fields
}

PointerDataType is the pointer data type.

func (*PointerDataType) CanEqual

func (t *PointerDataType) CanEqual() bool

func (*PointerDataType) CommentGroup

func (t *PointerDataType) CommentGroup() (head, leading CommentGroup)

func (*PointerDataType) ContainsStruct

func (t *PointerDataType) ContainsStruct() bool

func (*PointerDataType) End

func (t *PointerDataType) End() token.Position

func (*PointerDataType) Format

func (t *PointerDataType) Format(prefix ...string) string

func (*PointerDataType) HasHeadCommentGroup

func (t *PointerDataType) HasHeadCommentGroup() bool

func (*PointerDataType) HasLeadingCommentGroup

func (t *PointerDataType) HasLeadingCommentGroup() bool

func (*PointerDataType) Pos

func (t *PointerDataType) Pos() token.Position

func (*PointerDataType) RawText

func (t *PointerDataType) RawText() string

type RouteStmt

type RouteStmt struct {
	Method   *TokenNode
	Path     *PathExpr
	Request  *BodyStmt
	Returns  *TokenNode
	Response *BodyStmt
}

func (*RouteStmt) CommentGroup

func (r *RouteStmt) CommentGroup() (head, leading CommentGroup)

func (*RouteStmt) End

func (r *RouteStmt) End() token.Position

func (*RouteStmt) Format

func (r *RouteStmt) Format(prefix ...string) string

func (*RouteStmt) HasHeadCommentGroup

func (r *RouteStmt) HasHeadCommentGroup() bool

func (*RouteStmt) HasLeadingCommentGroup

func (r *RouteStmt) HasLeadingCommentGroup() bool

func (*RouteStmt) Pos

func (r *RouteStmt) Pos() token.Position

type ServiceItemStmt

type ServiceItemStmt struct {
	AtDoc     AtDocStmt
	AtHandler *AtHandlerStmt
	Route     *RouteStmt
}

func (*ServiceItemStmt) CommentGroup

func (s *ServiceItemStmt) CommentGroup() (head, leading CommentGroup)

func (*ServiceItemStmt) End

func (s *ServiceItemStmt) End() token.Position

func (*ServiceItemStmt) Format

func (s *ServiceItemStmt) Format(prefix ...string) string

func (*ServiceItemStmt) HasHeadCommentGroup

func (s *ServiceItemStmt) HasHeadCommentGroup() bool

func (*ServiceItemStmt) HasLeadingCommentGroup

func (s *ServiceItemStmt) HasLeadingCommentGroup() bool

func (*ServiceItemStmt) Pos

func (s *ServiceItemStmt) Pos() token.Position

type ServiceNameExpr

type ServiceNameExpr struct {
	Name *TokenNode
}

func (*ServiceNameExpr) CommentGroup

func (s *ServiceNameExpr) CommentGroup() (head, leading CommentGroup)

func (*ServiceNameExpr) End

func (s *ServiceNameExpr) End() token.Position

func (*ServiceNameExpr) Format

func (s *ServiceNameExpr) Format(...string) string

func (*ServiceNameExpr) HasHeadCommentGroup

func (s *ServiceNameExpr) HasHeadCommentGroup() bool

func (*ServiceNameExpr) HasLeadingCommentGroup

func (s *ServiceNameExpr) HasLeadingCommentGroup() bool

func (*ServiceNameExpr) Pos

func (s *ServiceNameExpr) Pos() token.Position

type ServiceStmt

type ServiceStmt struct {
	AtServerStmt *AtServerStmt
	Service      *TokenNode
	Name         *ServiceNameExpr
	LBrace       *TokenNode
	Routes       []*ServiceItemStmt
	RBrace       *TokenNode
}

func (*ServiceStmt) CommentGroup

func (s *ServiceStmt) CommentGroup() (head, leading CommentGroup)

func (*ServiceStmt) End

func (s *ServiceStmt) End() token.Position

func (*ServiceStmt) Format

func (s *ServiceStmt) Format(prefix ...string) string

func (*ServiceStmt) HasHeadCommentGroup

func (s *ServiceStmt) HasHeadCommentGroup() bool

func (*ServiceStmt) HasLeadingCommentGroup

func (s *ServiceStmt) HasLeadingCommentGroup() bool

func (*ServiceStmt) Pos

func (s *ServiceStmt) Pos() token.Position

type SliceDataType

type SliceDataType struct {
	// Lbrack is the left bracket token node.
	LBrack *TokenNode
	// Rbrack is the right bracket token node.
	RBrack *TokenNode
	// DataType is the slice data type.
	DataType DataType
	// contains filtered or unexported fields
}

SliceDataType is the slice data type.

func (*SliceDataType) CanEqual

func (t *SliceDataType) CanEqual() bool

func (*SliceDataType) CommentGroup

func (t *SliceDataType) CommentGroup() (head, leading CommentGroup)

func (*SliceDataType) ContainsStruct

func (t *SliceDataType) ContainsStruct() bool

func (*SliceDataType) End

func (t *SliceDataType) End() token.Position

func (*SliceDataType) Format

func (t *SliceDataType) Format(prefix ...string) string

func (*SliceDataType) HasHeadCommentGroup

func (t *SliceDataType) HasHeadCommentGroup() bool

func (*SliceDataType) HasLeadingCommentGroup

func (t *SliceDataType) HasLeadingCommentGroup() bool

func (*SliceDataType) Pos

func (t *SliceDataType) Pos() token.Position

func (*SliceDataType) RawText

func (t *SliceDataType) RawText() string

type Stmt

type Stmt interface {
	Node
	// contains filtered or unexported methods
}

Stmt represents a statement in the AST.

type StructDataType

type StructDataType struct {
	// Lbrace is the left brace token node.
	LBrace *TokenNode
	// Elements is the structure elements.
	Elements ElemExprList
	// Rbrace is the right brace token node.
	RBrace *TokenNode
	// contains filtered or unexported fields
}

StructDataType is the structure data type.

func (*StructDataType) CanEqual

func (t *StructDataType) CanEqual() bool

func (*StructDataType) CommentGroup

func (t *StructDataType) CommentGroup() (head, leading CommentGroup)

func (*StructDataType) ContainsStruct

func (t *StructDataType) ContainsStruct() bool

func (*StructDataType) End

func (t *StructDataType) End() token.Position

func (*StructDataType) Format

func (t *StructDataType) Format(prefix ...string) string

func (*StructDataType) HasHeadCommentGroup

func (t *StructDataType) HasHeadCommentGroup() bool

func (*StructDataType) HasLeadingCommentGroup

func (t *StructDataType) HasLeadingCommentGroup() bool

func (*StructDataType) Pos

func (t *StructDataType) Pos() token.Position

func (*StructDataType) RawText

func (t *StructDataType) RawText() string

type SyntaxStmt

type SyntaxStmt struct {
	// Syntax is the syntax token.
	Syntax *TokenNode
	// Assign is the assign token.
	Assign *TokenNode
	// Value is the syntax value.
	Value *TokenNode
}

SyntaxStmt represents a syntax statement.

func (*SyntaxStmt) CommentGroup

func (s *SyntaxStmt) CommentGroup() (head, leading CommentGroup)

func (*SyntaxStmt) End

func (s *SyntaxStmt) End() token.Position

func (*SyntaxStmt) Format

func (s *SyntaxStmt) Format(prefix ...string) string

func (*SyntaxStmt) HasHeadCommentGroup

func (s *SyntaxStmt) HasHeadCommentGroup() bool

func (*SyntaxStmt) HasLeadingCommentGroup

func (s *SyntaxStmt) HasLeadingCommentGroup() bool

func (*SyntaxStmt) Pos

func (s *SyntaxStmt) Pos() token.Position

type TokenNode

type TokenNode struct {
	// HeadCommentGroup are the comments in prev lines.
	HeadCommentGroup CommentGroup
	// Token is the token of the node.
	Token token.Token
	// LeadingCommentGroup are the tail comments in same line.
	LeadingCommentGroup CommentGroup
	// contains filtered or unexported fields
}

TokenNode represents a token node in the AST.

func NewTokenNode

func NewTokenNode(tok token.Token) *TokenNode

NewTokenNode creates and returns a new TokenNode.

func (*TokenNode) CommentGroup

func (t *TokenNode) CommentGroup() (head, leading CommentGroup)

func (*TokenNode) End

func (t *TokenNode) End() token.Position

func (*TokenNode) Equal

func (t *TokenNode) Equal(s string) bool

Equal returns true if the node's text is equal to the given text.

func (*TokenNode) Format

func (t *TokenNode) Format(prefix ...string) string

func (*TokenNode) HasHeadCommentGroup

func (t *TokenNode) HasHeadCommentGroup() bool

func (*TokenNode) HasLeadingCommentGroup

func (t *TokenNode) HasLeadingCommentGroup() bool

func (*TokenNode) IsEmptyString

func (t *TokenNode) IsEmptyString() bool

IsEmptyString returns true if the node is empty string.

func (*TokenNode) IsZeroString

func (t *TokenNode) IsZeroString() bool

IsZeroString returns true if the node is zero string.

func (*TokenNode) PeekFirstHeadComment

func (t *TokenNode) PeekFirstHeadComment() *CommentStmt

PeekFirstHeadComment returns the first head comment of the node.

func (*TokenNode) PeekFirstLeadingComment

func (t *TokenNode) PeekFirstLeadingComment() *CommentStmt

PeekFirstLeadingComment returns the first leading comment of the node.

func (*TokenNode) Pos

func (t *TokenNode) Pos() token.Position

func (*TokenNode) SetLeadingCommentGroup

func (t *TokenNode) SetLeadingCommentGroup(cg CommentGroup)

SetLeadingCommentGroup sets the node's leading comment group.

type TypeExpr

type TypeExpr struct {
	// Name is the type name.
	Name *TokenNode
	// Assign is the assign operator.
	Assign *TokenNode
	// DataType is the data type.
	DataType DataType
}

TypeExpr is the type expression.

func (*TypeExpr) CommentGroup

func (e *TypeExpr) CommentGroup() (head, leading CommentGroup)

func (*TypeExpr) End

func (e *TypeExpr) End() token.Position

func (*TypeExpr) Format

func (e *TypeExpr) Format(prefix ...string) string

func (*TypeExpr) HasHeadCommentGroup

func (e *TypeExpr) HasHeadCommentGroup() bool

func (*TypeExpr) HasLeadingCommentGroup

func (e *TypeExpr) HasLeadingCommentGroup() bool

func (*TypeExpr) Pos

func (e *TypeExpr) Pos() token.Position

type TypeGroupStmt

type TypeGroupStmt struct {
	// Type is the type keyword.
	Type *TokenNode
	// LParen is the left parenthesis.
	LParen *TokenNode
	// ExprList is the type expression list.
	ExprList []*TypeExpr
	// RParen is the right parenthesis.
	RParen *TokenNode
}

TypeGroupStmt is the type statement for type group.

func (*TypeGroupStmt) CommentGroup

func (t *TypeGroupStmt) CommentGroup() (head, leading CommentGroup)

func (*TypeGroupStmt) End

func (t *TypeGroupStmt) End() token.Position

func (*TypeGroupStmt) Format

func (t *TypeGroupStmt) Format(prefix ...string) string

func (*TypeGroupStmt) HasHeadCommentGroup

func (t *TypeGroupStmt) HasHeadCommentGroup() bool

func (*TypeGroupStmt) HasLeadingCommentGroup

func (t *TypeGroupStmt) HasLeadingCommentGroup() bool

func (*TypeGroupStmt) Pos

func (t *TypeGroupStmt) Pos() token.Position

type TypeLiteralStmt

type TypeLiteralStmt struct {
	// Type is the type keyword.
	Type *TokenNode
	// Expr is the type expression.
	Expr *TypeExpr
}

TypeLiteralStmt is the type statement for type literal.

func (*TypeLiteralStmt) CommentGroup

func (t *TypeLiteralStmt) CommentGroup() (head, leading CommentGroup)

func (*TypeLiteralStmt) End

func (t *TypeLiteralStmt) End() token.Position

func (*TypeLiteralStmt) Format

func (t *TypeLiteralStmt) Format(prefix ...string) string

func (*TypeLiteralStmt) HasHeadCommentGroup

func (t *TypeLiteralStmt) HasHeadCommentGroup() bool

func (*TypeLiteralStmt) HasLeadingCommentGroup

func (t *TypeLiteralStmt) HasLeadingCommentGroup() bool

func (*TypeLiteralStmt) Pos

func (t *TypeLiteralStmt) Pos() token.Position

type TypeStmt

type TypeStmt interface {
	Stmt
	// contains filtered or unexported methods
}

TypeStmt is the interface for type statement.

type WriteMode

type WriteMode int

WriteMode is the mode of writing.

const (

	// ModeAuto is the default mode, which will automatically
	//determine whether to write a newline.
	ModeAuto WriteMode

	// ModeExpectInSameLine will write in the same line.
	ModeExpectInSameLine
)

type Writer

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

Writer is the writer of ast.

func NewBufferWriter

func NewBufferWriter() *Writer

NewBufferWriter returns a new buffer Writer.

func NewWriter

func NewWriter(writer io.Writer) *Writer

NewWriter returns a new Writer.

func (*Writer) Flush

func (w *Writer) Flush()

Flush flushes the buffer.

func (*Writer) NewLine

func (w *Writer) NewLine()

NewLine writes a new line.

func (*Writer) String

func (w *Writer) String() string

String returns the string of the buffer.

func (*Writer) Write

func (w *Writer) Write(opts ...Option)

Write writes the node.

func (*Writer) WriteText

func (w *Writer) WriteText(text string)

WriteText writes the text.

Jump to

Keyboard shortcuts

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