ast

package
v1.10.28 Latest Latest
Warning

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

Go to latest
Published: Jun 7, 2021 License: MIT Imports: 9 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func EqualDoc

func EqualDoc(spec1, spec2 Spec) bool

func NewTextExpr

func NewTextExpr(v string) *defaultExpr

Types

type Api

type Api struct {
	LinePrefix string
	Syntax     *SyntaxExpr
	Import     []*ImportExpr

	Info *InfoExpr
	Type []TypeExpr

	Service []*Service
	// contains filtered or unexported fields
}

func (*Api) Equal

func (a *Api) Equal(v interface{}) bool

func (*Api) Format

func (a *Api) Format() error

type ApiVisitor

type ApiVisitor struct {
	api.BaseApiParserVisitor
	// contains filtered or unexported fields
}

func NewApiVisitor

func NewApiVisitor(options ...VisitorOption) *ApiVisitor

func (*ApiVisitor) VisitAnonymousFiled

func (v *ApiVisitor) VisitAnonymousFiled(ctx *api.AnonymousFiledContext) interface{}

func (*ApiVisitor) VisitApi

func (v *ApiVisitor) VisitApi(ctx *api.ApiContext) interface{}

func (*ApiVisitor) VisitArrayType

func (v *ApiVisitor) VisitArrayType(ctx *api.ArrayTypeContext) interface{}

func (*ApiVisitor) VisitAtDoc

func (v *ApiVisitor) VisitAtDoc(ctx *api.AtDocContext) interface{}

func (*ApiVisitor) VisitAtHandler

func (v *ApiVisitor) VisitAtHandler(ctx *api.AtHandlerContext) interface{}

func (*ApiVisitor) VisitAtServer

func (v *ApiVisitor) VisitAtServer(ctx *api.AtServerContext) interface{}

func (*ApiVisitor) VisitBody

func (v *ApiVisitor) VisitBody(ctx *api.BodyContext) interface{}

func (*ApiVisitor) VisitDataType

func (v *ApiVisitor) VisitDataType(ctx *api.DataTypeContext) interface{}

func (*ApiVisitor) VisitField

func (v *ApiVisitor) VisitField(ctx *api.FieldContext) interface{}

func (*ApiVisitor) VisitImportBlock

func (v *ApiVisitor) VisitImportBlock(ctx *api.ImportBlockContext) interface{}

func (*ApiVisitor) VisitImportBlockValue

func (v *ApiVisitor) VisitImportBlockValue(ctx *api.ImportBlockValueContext) interface{}

func (*ApiVisitor) VisitImportLit

func (v *ApiVisitor) VisitImportLit(ctx *api.ImportLitContext) interface{}

func (*ApiVisitor) VisitImportSpec

func (v *ApiVisitor) VisitImportSpec(ctx *api.ImportSpecContext) interface{}

func (*ApiVisitor) VisitImportValue

func (v *ApiVisitor) VisitImportValue(ctx *api.ImportValueContext) interface{}

func (*ApiVisitor) VisitInfoSpec

func (v *ApiVisitor) VisitInfoSpec(ctx *api.InfoSpecContext) interface{}

func (*ApiVisitor) VisitKvLit

func (v *ApiVisitor) VisitKvLit(ctx *api.KvLitContext) interface{}

func (*ApiVisitor) VisitMapType

func (v *ApiVisitor) VisitMapType(ctx *api.MapTypeContext) interface{}

func (*ApiVisitor) VisitNormalField

func (v *ApiVisitor) VisitNormalField(ctx *api.NormalFieldContext) interface{}

func (*ApiVisitor) VisitPointerType

func (v *ApiVisitor) VisitPointerType(ctx *api.PointerTypeContext) interface{}

func (*ApiVisitor) VisitReplybody

func (v *ApiVisitor) VisitReplybody(ctx *api.ReplybodyContext) interface{}

note: forward compatible

func (*ApiVisitor) VisitRoute

func (v *ApiVisitor) VisitRoute(ctx *api.RouteContext) interface{}

func (*ApiVisitor) VisitServiceApi

func (v *ApiVisitor) VisitServiceApi(ctx *api.ServiceApiContext) interface{}

func (*ApiVisitor) VisitServiceRoute

func (v *ApiVisitor) VisitServiceRoute(ctx *api.ServiceRouteContext) interface{}

func (*ApiVisitor) VisitServiceSpec

func (v *ApiVisitor) VisitServiceSpec(ctx *api.ServiceSpecContext) interface{}

func (*ApiVisitor) VisitSpec

func (v *ApiVisitor) VisitSpec(ctx *api.SpecContext) interface{}

func (*ApiVisitor) VisitSyntaxLit

func (v *ApiVisitor) VisitSyntaxLit(ctx *api.SyntaxLitContext) interface{}

func (*ApiVisitor) VisitTypeAlias

func (v *ApiVisitor) VisitTypeAlias(ctx *api.TypeAliasContext) interface{}

func (*ApiVisitor) VisitTypeBlock

func (v *ApiVisitor) VisitTypeBlock(ctx *api.TypeBlockContext) interface{}

func (*ApiVisitor) VisitTypeBlockAlias

func (v *ApiVisitor) VisitTypeBlockAlias(ctx *api.TypeBlockAliasContext) interface{}

func (*ApiVisitor) VisitTypeBlockBody

func (v *ApiVisitor) VisitTypeBlockBody(ctx *api.TypeBlockBodyContext) interface{}

func (*ApiVisitor) VisitTypeBlockStruct

func (v *ApiVisitor) VisitTypeBlockStruct(ctx *api.TypeBlockStructContext) interface{}

func (*ApiVisitor) VisitTypeLit

func (v *ApiVisitor) VisitTypeLit(ctx *api.TypeLitContext) interface{}

func (*ApiVisitor) VisitTypeLitBody

func (v *ApiVisitor) VisitTypeLitBody(ctx *api.TypeLitBodyContext) interface{}

func (*ApiVisitor) VisitTypeSpec

func (v *ApiVisitor) VisitTypeSpec(ctx *api.TypeSpecContext) interface{}

func (*ApiVisitor) VisitTypeStruct

func (v *ApiVisitor) VisitTypeStruct(ctx *api.TypeStructContext) interface{}

type Array

type Array struct {
	ArrayExpr Expr
	LBrack    Expr
	RBrack    Expr
	Literal   DataType
}

func (*Array) Equal

func (a *Array) Equal(dt DataType) bool

func (*Array) Expr

func (a *Array) Expr() Expr

func (*Array) Format

func (a *Array) Format() error

func (*Array) IsNotNil

func (a *Array) IsNotNil() bool

type AtDoc

type AtDoc struct {
	AtDocToken Expr
	Lp         Expr
	Rp         Expr
	LineDoc    Expr
	Kv         []*KvExpr
}

func (*AtDoc) Equal

func (a *AtDoc) Equal(v interface{}) bool

func (*AtDoc) Format

func (a *AtDoc) Format() error

type AtHandler

type AtHandler struct {
	AtHandlerToken Expr
	Name           Expr
	DocExpr        []Expr
	CommentExpr    Expr
}

func (*AtHandler) Comment

func (a *AtHandler) Comment() Expr

func (*AtHandler) Doc

func (a *AtHandler) Doc() []Expr

func (*AtHandler) Equal

func (a *AtHandler) Equal(v interface{}) bool

func (*AtHandler) Format

func (a *AtHandler) Format() error

type AtServer

type AtServer struct {
	AtServerToken Expr
	Lp            Expr
	Rp            Expr
	Kv            KV
}

func (*AtServer) Equal

func (a *AtServer) Equal(v interface{}) bool

func (*AtServer) Format

func (a *AtServer) Format() error

type Body

type Body struct {
	Lp   Expr
	Rp   Expr
	Name DataType
}

func (*Body) Equal

func (b *Body) Equal(v interface{}) bool

func (*Body) Format

func (b *Body) Format() error

type DataType

type DataType interface {
	Expr() Expr
	Equal(dt DataType) bool
	Format() error
	IsNotNil() bool
}

Literal, Interface, Map, Array, Time, Pointer

type Expr

type Expr interface {
	Prefix() string
	Line() int
	Column() int
	Text() string
	SetText(text string)
	Start() int
	Stop() int
	Equal(expr Expr) bool
	IsNotNil() bool
}

type ImportExpr

type ImportExpr struct {
	Import      Expr
	Value       Expr
	DocExpr     []Expr
	CommentExpr Expr
}

func (*ImportExpr) Comment

func (i *ImportExpr) Comment() Expr

func (*ImportExpr) Doc

func (i *ImportExpr) Doc() []Expr

func (*ImportExpr) Equal

func (i *ImportExpr) Equal(v interface{}) bool

func (*ImportExpr) Format

func (i *ImportExpr) Format() error

type InfoExpr

type InfoExpr struct {
	Info Expr
	Lp   Expr
	Rp   Expr
	Kvs  []*KvExpr
}

func (*InfoExpr) Equal

func (i *InfoExpr) Equal(v interface{}) bool

func (*InfoExpr) Format

func (i *InfoExpr) Format() error

type Interface

type Interface struct {
	Literal Expr
}

func (*Interface) Equal

func (i *Interface) Equal(dt DataType) bool

func (*Interface) Expr

func (i *Interface) Expr() Expr

func (*Interface) Format

func (i *Interface) Format() error

func (*Interface) IsNotNil

func (i *Interface) IsNotNil() bool

type KV

type KV []*KvExpr

func (KV) Get

func (kv KV) Get(key string) Expr

type KvExpr

type KvExpr struct {
	Key         Expr
	Value       Expr
	DocExpr     []Expr
	CommentExpr Expr
}

func (*KvExpr) Comment

func (k *KvExpr) Comment() Expr

func (*KvExpr) Doc

func (k *KvExpr) Doc() []Expr

func (*KvExpr) Equal

func (k *KvExpr) Equal(v interface{}) bool

func (*KvExpr) Format

func (k *KvExpr) Format() error

type Literal

type Literal struct {
	Literal Expr
}

int, bool, Foo,...

func (*Literal) Equal

func (l *Literal) Equal(dt DataType) bool

func (*Literal) Expr

func (l *Literal) Expr() Expr

func (*Literal) Format

func (l *Literal) Format() error

func (*Literal) IsNotNil

func (l *Literal) IsNotNil() bool

type Map

type Map struct {
	MapExpr Expr
	Map     Expr
	LBrack  Expr
	RBrack  Expr
	Key     Expr
	Value   DataType
}

func (*Map) Equal

func (m *Map) Equal(dt DataType) bool

func (*Map) Expr

func (m *Map) Expr() Expr

func (*Map) Format

func (m *Map) Format() error

func (*Map) IsNotNil

func (m *Map) IsNotNil() bool

type Parser

type Parser struct {
	antlr.DefaultErrorListener
	// contains filtered or unexported fields
}

func NewParser

func NewParser(options ...ParserOption) *Parser

func (*Parser) Accept

func (p *Parser) Accept(fn func(p *api.ApiParserParser, visitor *ApiVisitor) interface{}, content string) (v interface{}, err error)

Accept can parse any terminalNode of api tree by fn. -- for debug

func (*Parser) Parse

func (p *Parser) Parse(filename string) (*Api, error)

Parse is used to parse the api from the specified file name

func (*Parser) ParseContent

func (p *Parser) ParseContent(content string) (*Api, error)

ParseContent is used to parse the api from the specified content

func (*Parser) SyntaxError

func (p *Parser) SyntaxError(_ antlr.Recognizer, _ interface{}, line, column int, msg string, _ antlr.RecognitionException)

type ParserOption

type ParserOption func(p *Parser)

func WithParserDebug

func WithParserDebug() ParserOption

func WithParserPrefix

func WithParserPrefix(prefix string) ParserOption

type PlaceHolder

type PlaceHolder struct{}
var Holder PlaceHolder

type Pointer

type Pointer struct {
	PointerExpr Expr
	Star        Expr
	Name        Expr
}

func (*Pointer) Equal

func (p *Pointer) Equal(dt DataType) bool

func (*Pointer) Expr

func (p *Pointer) Expr() Expr

func (*Pointer) Format

func (p *Pointer) Format() error

func (*Pointer) IsNotNil

func (p *Pointer) IsNotNil() bool

type Route

type Route struct {
	Method      Expr
	Path        Expr
	Req         *Body
	ReturnToken Expr
	Reply       *Body
	DocExpr     []Expr
	CommentExpr Expr
}

func (*Route) Comment

func (r *Route) Comment() Expr

func (*Route) Doc

func (r *Route) Doc() []Expr

func (*Route) Equal

func (r *Route) Equal(v interface{}) bool

func (*Route) Format

func (r *Route) Format() error

type Service

type Service struct {
	AtServer   *AtServer
	ServiceApi *ServiceApi
}

func (*Service) Equal

func (s *Service) Equal(v interface{}) bool

func (*Service) Format

func (s *Service) Format() error

type ServiceApi

type ServiceApi struct {
	ServiceToken Expr
	Name         Expr
	Lbrace       Expr
	Rbrace       Expr
	ServiceRoute []*ServiceRoute
}

func (*ServiceApi) Equal

func (a *ServiceApi) Equal(v interface{}) bool

func (*ServiceApi) Format

func (a *ServiceApi) Format() error

type ServiceRoute

type ServiceRoute struct {
	AtDoc     *AtDoc
	AtServer  *AtServer
	AtHandler *AtHandler
	Route     *Route
}

func (*ServiceRoute) Equal

func (s *ServiceRoute) Equal(v interface{}) bool

func (*ServiceRoute) Format

func (s *ServiceRoute) Format() error

func (*ServiceRoute) GetHandler

func (s *ServiceRoute) GetHandler() Expr

type Spec

type Spec interface {
	Doc() []Expr
	Comment() Expr
	Format() error
	Equal(v interface{}) bool
}

type SyntaxExpr

type SyntaxExpr struct {
	Syntax      Expr
	Assign      Expr
	Version     Expr
	DocExpr     []Expr
	CommentExpr Expr
}

func (*SyntaxExpr) Comment

func (s *SyntaxExpr) Comment() Expr

func (*SyntaxExpr) Doc

func (s *SyntaxExpr) Doc() []Expr

func (*SyntaxExpr) Equal

func (s *SyntaxExpr) Equal(v interface{}) bool

func (*SyntaxExpr) Format

func (s *SyntaxExpr) Format() error

type Time

type Time struct {
	Literal Expr
}

func (*Time) Equal

func (t *Time) Equal(dt DataType) bool

func (*Time) Expr

func (t *Time) Expr() Expr

func (*Time) Format

func (t *Time) Format() error

func (*Time) IsNotNil

func (t *Time) IsNotNil() bool

type TokenStream

type TokenStream interface {
	GetStart() antlr.Token
	GetStop() antlr.Token
	GetParser() antlr.Parser
}

type TypeAlias

type TypeAlias struct {
	Name        Expr
	Assign      Expr
	DataType    DataType
	DocExpr     []Expr
	CommentExpr Expr
}

func (*TypeAlias) Comment

func (a *TypeAlias) Comment() Expr

func (*TypeAlias) Doc

func (a *TypeAlias) Doc() []Expr

func (*TypeAlias) Equal

func (a *TypeAlias) Equal(v interface{}) bool

func (*TypeAlias) Format

func (a *TypeAlias) Format() error

func (*TypeAlias) NameExpr

func (a *TypeAlias) NameExpr() Expr

type TypeExpr

type TypeExpr interface {
	Doc() []Expr
	Format() error
	Equal(v interface{}) bool
	NameExpr() Expr
}

TypeAlias、 TypeStruct

type TypeField

type TypeField struct {
	IsAnonymous bool
	// Name is nil if IsAnonymous
	Name        Expr
	DataType    DataType
	Tag         Expr
	DocExpr     []Expr
	CommentExpr Expr
}

func (*TypeField) Comment

func (t *TypeField) Comment() Expr

func (*TypeField) Doc

func (t *TypeField) Doc() []Expr

func (*TypeField) Equal

func (t *TypeField) Equal(v interface{}) bool

func (*TypeField) Format

func (t *TypeField) Format() error

type TypeStruct

type TypeStruct struct {
	Name    Expr
	Struct  Expr
	LBrace  Expr
	RBrace  Expr
	DocExpr []Expr
	Fields  []*TypeField
}

func (*TypeStruct) Doc

func (s *TypeStruct) Doc() []Expr

func (*TypeStruct) Equal

func (s *TypeStruct) Equal(dt interface{}) bool

func (*TypeStruct) Format

func (s *TypeStruct) Format() error

func (*TypeStruct) NameExpr

func (s *TypeStruct) NameExpr() Expr

type VisitorOption

type VisitorOption func(v *ApiVisitor)

func WithVisitorDebug

func WithVisitorDebug() VisitorOption

func WithVisitorPrefix

func WithVisitorPrefix(prefix string) VisitorOption

Jump to

Keyboard shortcuts

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