Documentation ¶
Index ¶
- Variables
- func EqualDoc(spec1, spec2 Spec) bool
- func NewTextExpr(v string) *defaultExpr
- type Api
- type ApiVisitor
- func (v *ApiVisitor) VisitAnonymousFiled(ctx *api.AnonymousFiledContext) any
- func (v *ApiVisitor) VisitApi(ctx *api.ApiContext) any
- func (v *ApiVisitor) VisitArrayType(ctx *api.ArrayTypeContext) any
- func (v *ApiVisitor) VisitAtDoc(ctx *api.AtDocContext) any
- func (v *ApiVisitor) VisitAtHandler(ctx *api.AtHandlerContext) any
- func (v *ApiVisitor) VisitAtServer(ctx *api.AtServerContext) any
- func (v *ApiVisitor) VisitBody(ctx *api.BodyContext) any
- func (v *ApiVisitor) VisitDataType(ctx *api.DataTypeContext) any
- func (v *ApiVisitor) VisitField(ctx *api.FieldContext) any
- func (v *ApiVisitor) VisitImportBlock(ctx *api.ImportBlockContext) any
- func (v *ApiVisitor) VisitImportBlockValue(ctx *api.ImportBlockValueContext) any
- func (v *ApiVisitor) VisitImportLit(ctx *api.ImportLitContext) any
- func (v *ApiVisitor) VisitImportSpec(ctx *api.ImportSpecContext) any
- func (v *ApiVisitor) VisitImportValue(ctx *api.ImportValueContext) any
- func (v *ApiVisitor) VisitInfoSpec(ctx *api.InfoSpecContext) any
- func (v *ApiVisitor) VisitKvLit(ctx *api.KvLitContext) any
- func (v *ApiVisitor) VisitMapType(ctx *api.MapTypeContext) any
- func (v *ApiVisitor) VisitNormalField(ctx *api.NormalFieldContext) any
- func (v *ApiVisitor) VisitPointerType(ctx *api.PointerTypeContext) any
- func (v *ApiVisitor) VisitReplybody(ctx *api.ReplybodyContext) any
- func (v *ApiVisitor) VisitRoute(ctx *api.RouteContext) any
- func (v *ApiVisitor) VisitServiceApi(ctx *api.ServiceApiContext) any
- func (v *ApiVisitor) VisitServiceRoute(ctx *api.ServiceRouteContext) any
- func (v *ApiVisitor) VisitServiceSpec(ctx *api.ServiceSpecContext) any
- func (v *ApiVisitor) VisitSpec(ctx *api.SpecContext) any
- func (v *ApiVisitor) VisitSyntaxLit(ctx *api.SyntaxLitContext) any
- func (v *ApiVisitor) VisitTypeAlias(ctx *api.TypeAliasContext) any
- func (v *ApiVisitor) VisitTypeBlock(ctx *api.TypeBlockContext) any
- func (v *ApiVisitor) VisitTypeBlockAlias(ctx *api.TypeBlockAliasContext) any
- func (v *ApiVisitor) VisitTypeBlockBody(ctx *api.TypeBlockBodyContext) any
- func (v *ApiVisitor) VisitTypeBlockStruct(ctx *api.TypeBlockStructContext) any
- func (v *ApiVisitor) VisitTypeLit(ctx *api.TypeLitContext) any
- func (v *ApiVisitor) VisitTypeLitBody(ctx *api.TypeLitBodyContext) any
- func (v *ApiVisitor) VisitTypeSpec(ctx *api.TypeSpecContext) any
- func (v *ApiVisitor) VisitTypeStruct(ctx *api.TypeStructContext) any
- type Array
- type AtDoc
- type AtHandler
- type AtServer
- type Body
- type DataType
- type Expr
- type ImportExpr
- type InfoExpr
- type Interface
- type KV
- type KvExpr
- type Literal
- type Map
- type Parser
- func (p *Parser) Accept(fn func(p *api.ApiParserParser, visitor *ApiVisitor) any, content string) (v any, err error)
- func (p *Parser) Parse(filename string) (*Api, error)
- func (p *Parser) ParseContent(content string, filename ...string) (*Api, error)
- func (p *Parser) SyntaxError(_ antlr.Recognizer, _ any, line, column int, msg string, ...)
- type ParserOption
- type PlaceHolder
- type Pointer
- type Route
- type Service
- type ServiceApi
- type ServiceRoute
- type Spec
- type SyntaxExpr
- type Time
- type TokenStream
- type TypeAlias
- type TypeExpr
- type TypeField
- type TypeStruct
- type VisitorOption
Constants ¶
This section is empty.
Variables ¶
var ErrImportCycleNotAllowed = errors.New("import cycle not allowed")
ErrImportCycleNotAllowed defines an error for circular importing
Functions ¶
func NewTextExpr ¶
func NewTextExpr(v string) *defaultExpr
NewTextExpr creates a default instance for Expr
Types ¶
type Api ¶
type Api struct { LinePrefix string Syntax *SyntaxExpr Import []*ImportExpr Info *InfoExpr Type []TypeExpr Service []*Service // contains filtered or unexported fields }
Api describes syntax for api
type ApiVisitor ¶
type ApiVisitor struct { *api.BaseApiParserVisitor // contains filtered or unexported fields }
ApiVisitor wraps api.BaseApiParserVisitor to call methods which has prefix Visit to visit node from the api syntax
func NewApiVisitor ¶
func NewApiVisitor(options ...VisitorOption) *ApiVisitor
NewApiVisitor creates an instance for ApiVisitor
func (*ApiVisitor) VisitAnonymousFiled ¶
func (v *ApiVisitor) VisitAnonymousFiled(ctx *api.AnonymousFiledContext) any
VisitAnonymousFiled implements from api.BaseApiParserVisitor
func (*ApiVisitor) VisitApi ¶
func (v *ApiVisitor) VisitApi(ctx *api.ApiContext) any
VisitApi implements from api.BaseApiParserVisitor
func (*ApiVisitor) VisitArrayType ¶
func (v *ApiVisitor) VisitArrayType(ctx *api.ArrayTypeContext) any
VisitArrayType implements from api.BaseApiParserVisitor
func (*ApiVisitor) VisitAtDoc ¶
func (v *ApiVisitor) VisitAtDoc(ctx *api.AtDocContext) any
VisitAtDoc implements from api.BaseApiParserVisitor
func (*ApiVisitor) VisitAtHandler ¶
func (v *ApiVisitor) VisitAtHandler(ctx *api.AtHandlerContext) any
VisitAtHandler implements from api.BaseApiParserVisitor
func (*ApiVisitor) VisitAtServer ¶
func (v *ApiVisitor) VisitAtServer(ctx *api.AtServerContext) any
VisitAtServer implements from api.BaseApiParserVisitor
func (*ApiVisitor) VisitBody ¶
func (v *ApiVisitor) VisitBody(ctx *api.BodyContext) any
VisitBody implements from api.BaseApiParserVisitor
func (*ApiVisitor) VisitDataType ¶
func (v *ApiVisitor) VisitDataType(ctx *api.DataTypeContext) any
VisitDataType implements from api.BaseApiParserVisitor
func (*ApiVisitor) VisitField ¶
func (v *ApiVisitor) VisitField(ctx *api.FieldContext) any
VisitField implements from api.BaseApiParserVisitor
func (*ApiVisitor) VisitImportBlock ¶
func (v *ApiVisitor) VisitImportBlock(ctx *api.ImportBlockContext) any
VisitImportBlock implements from api.BaseApiParserVisitor
func (*ApiVisitor) VisitImportBlockValue ¶
func (v *ApiVisitor) VisitImportBlockValue(ctx *api.ImportBlockValueContext) any
VisitImportBlockValue implements from api.BaseApiParserVisitor
func (*ApiVisitor) VisitImportLit ¶
func (v *ApiVisitor) VisitImportLit(ctx *api.ImportLitContext) any
VisitImportLit implements from api.BaseApiParserVisitor
func (*ApiVisitor) VisitImportSpec ¶
func (v *ApiVisitor) VisitImportSpec(ctx *api.ImportSpecContext) any
VisitImportSpec implements from api.BaseApiParserVisitor
func (*ApiVisitor) VisitImportValue ¶
func (v *ApiVisitor) VisitImportValue(ctx *api.ImportValueContext) any
VisitImportValue implements from api.BaseApiParserVisitor
func (*ApiVisitor) VisitInfoSpec ¶
func (v *ApiVisitor) VisitInfoSpec(ctx *api.InfoSpecContext) any
VisitInfoSpec implements from api.BaseApiParserVisitor
func (*ApiVisitor) VisitKvLit ¶
func (v *ApiVisitor) VisitKvLit(ctx *api.KvLitContext) any
VisitKvLit implements from api.BaseApiParserVisitor
func (*ApiVisitor) VisitMapType ¶
func (v *ApiVisitor) VisitMapType(ctx *api.MapTypeContext) any
VisitMapType implements from api.BaseApiParserVisitor
func (*ApiVisitor) VisitNormalField ¶
func (v *ApiVisitor) VisitNormalField(ctx *api.NormalFieldContext) any
VisitNormalField implements from api.BaseApiParserVisitor
func (*ApiVisitor) VisitPointerType ¶
func (v *ApiVisitor) VisitPointerType(ctx *api.PointerTypeContext) any
VisitPointerType implements from api.BaseApiParserVisitor
func (*ApiVisitor) VisitReplybody ¶
func (v *ApiVisitor) VisitReplybody(ctx *api.ReplybodyContext) any
VisitReplybody implements from api.BaseApiParserVisitor
func (*ApiVisitor) VisitRoute ¶
func (v *ApiVisitor) VisitRoute(ctx *api.RouteContext) any
VisitRoute implements from api.BaseApiParserVisitor
func (*ApiVisitor) VisitServiceApi ¶
func (v *ApiVisitor) VisitServiceApi(ctx *api.ServiceApiContext) any
VisitServiceApi implements from api.BaseApiParserVisitor
func (*ApiVisitor) VisitServiceRoute ¶
func (v *ApiVisitor) VisitServiceRoute(ctx *api.ServiceRouteContext) any
VisitServiceRoute implements from api.BaseApiParserVisitor
func (*ApiVisitor) VisitServiceSpec ¶
func (v *ApiVisitor) VisitServiceSpec(ctx *api.ServiceSpecContext) any
VisitServiceSpec implements from api.BaseApiParserVisitor
func (*ApiVisitor) VisitSpec ¶
func (v *ApiVisitor) VisitSpec(ctx *api.SpecContext) any
VisitSpec implements from api.BaseApiParserVisitor
func (*ApiVisitor) VisitSyntaxLit ¶
func (v *ApiVisitor) VisitSyntaxLit(ctx *api.SyntaxLitContext) any
VisitSyntaxLit implements from api.BaseApiParserVisitor
func (*ApiVisitor) VisitTypeAlias ¶
func (v *ApiVisitor) VisitTypeAlias(ctx *api.TypeAliasContext) any
VisitTypeAlias implements from api.BaseApiParserVisitor
func (*ApiVisitor) VisitTypeBlock ¶
func (v *ApiVisitor) VisitTypeBlock(ctx *api.TypeBlockContext) any
VisitTypeBlock implements from api.BaseApiParserVisitor
func (*ApiVisitor) VisitTypeBlockAlias ¶
func (v *ApiVisitor) VisitTypeBlockAlias(ctx *api.TypeBlockAliasContext) any
VisitTypeBlockAlias implements from api.BaseApiParserVisitor
func (*ApiVisitor) VisitTypeBlockBody ¶
func (v *ApiVisitor) VisitTypeBlockBody(ctx *api.TypeBlockBodyContext) any
VisitTypeBlockBody implements from api.BaseApiParserVisitor
func (*ApiVisitor) VisitTypeBlockStruct ¶
func (v *ApiVisitor) VisitTypeBlockStruct(ctx *api.TypeBlockStructContext) any
VisitTypeBlockStruct implements from api.BaseApiParserVisitor
func (*ApiVisitor) VisitTypeLit ¶
func (v *ApiVisitor) VisitTypeLit(ctx *api.TypeLitContext) any
VisitTypeLit implements from api.BaseApiParserVisitor
func (*ApiVisitor) VisitTypeLitBody ¶
func (v *ApiVisitor) VisitTypeLitBody(ctx *api.TypeLitBodyContext) any
VisitTypeLitBody implements from api.BaseApiParserVisitor
func (*ApiVisitor) VisitTypeSpec ¶
func (v *ApiVisitor) VisitTypeSpec(ctx *api.TypeSpecContext) any
VisitTypeSpec implements from api.BaseApiParserVisitor
func (*ApiVisitor) VisitTypeStruct ¶
func (v *ApiVisitor) VisitTypeStruct(ctx *api.TypeStructContext) any
VisitTypeStruct implements from api.BaseApiParserVisitor
type Array ¶
Array describes the slice ast for api syntax
type AtDoc ¶
AtDoc describes service comments ast for api syntax
type AtHandler ¶
AtHandler describes service handler ast for api syntax
type AtServer ¶
AtServer describes server metadata for api syntax
type Body ¶
Body describes request,response body ast for api syntax
type DataType ¶
DataType describes datatype for api syntax, the default implementation expressions are 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 }
Expr describes ast expression
type ImportExpr ¶
ImportExpr defines import syntax for api
func (*ImportExpr) Comment ¶
func (i *ImportExpr) Comment() Expr
Comment returns the comment of ImportExpr, like // some text
func (*ImportExpr) Doc ¶
func (i *ImportExpr) Doc() []Expr
Doc returns the document of ImportExpr, like // some text
func (*ImportExpr) Equal ¶
func (i *ImportExpr) Equal(v any) bool
Equal compares whether the element literals in two ImportExpr are equal
func (*ImportExpr) Format ¶
func (i *ImportExpr) Format() error
Format provides a formatter for api command, now nothing to do
type InfoExpr ¶
InfoExpr defines info syntax for api
type Interface ¶
type Interface struct {
Literal Expr
}
Interface describes the interface type of golang,Its fixed value is any
type KvExpr ¶
KvExpr describes key-value for api
type Literal ¶
type Literal struct {
Literal Expr
}
Literal describes the basic types of golang, non-reference types, such as int, bool, Foo,...
type Map ¶
Map describes the map ast for api syntax
type Parser ¶
type Parser struct { antlr.DefaultErrorListener // contains filtered or unexported fields }
Parser provides api parsing capabilities
func NewParser ¶
func NewParser(options ...ParserOption) *Parser
NewParser creates an instance for Parser
func (*Parser) Accept ¶
func (p *Parser) Accept(fn func(p *api.ApiParserParser, visitor *ApiVisitor) any, content string) (v any, err error)
Accept can parse any terminalNode of api tree by fn. -- for debug
func (*Parser) ParseContent ¶
ParseContent is used to parse the api from the specified content
func (*Parser) SyntaxError ¶
func (p *Parser) SyntaxError(_ antlr.Recognizer, _ any, line, column int, msg string, _ antlr.RecognitionException)
SyntaxError accepts errors and panic it
type ParserOption ¶
type ParserOption func(p *Parser)
ParserOption defines an function with argument Parser
func WithParserDebug ¶
func WithParserDebug() ParserOption
WithParserDebug returns a debug ParserOption
func WithParserPrefix ¶
func WithParserPrefix(prefix string) ParserOption
WithParserPrefix returns a prefix ParserOption
func WithParserSkipCheckTypeDeclaration ¶
func WithParserSkipCheckTypeDeclaration() ParserOption
type PlaceHolder ¶
type PlaceHolder struct{}
PlaceHolder defines an empty struct
var Holder PlaceHolder
Holder defines a default instance for PlaceHolder
type Pointer ¶
Pointer describes the pointer ast for api syntax
type Route ¶
type Route struct { Method Expr Path Expr Req *Body ReturnToken Expr Reply *Body DocExpr []Expr CommentExpr Expr }
Route describes route ast for api syntax
type Service ¶
type Service struct { AtServer *AtServer ServiceApi *ServiceApi }
Service describes service for api syntax
type ServiceApi ¶
type ServiceApi struct { ServiceToken Expr Name Expr Lbrace Expr Rbrace Expr ServiceRoute []*ServiceRoute }
ServiceApi describes service ast for api syntax
func (*ServiceApi) Equal ¶
func (a *ServiceApi) Equal(v any) bool
Equal compares whether the element literals in two ServiceApi are equal
func (*ServiceApi) Format ¶
func (a *ServiceApi) Format() error
Format provides a formatter for api command, now nothing to do
type ServiceRoute ¶
ServiceRoute describes service route ast for api syntax
func (*ServiceRoute) Equal ¶
func (s *ServiceRoute) Equal(v any) bool
Equal compares whether the element literals in two ServiceRoute are equal
func (*ServiceRoute) Format ¶
func (s *ServiceRoute) Format() error
Format provides a formatter for api command, now nothing to do
func (*ServiceRoute) GetHandler ¶
func (s *ServiceRoute) GetHandler() Expr
GetHandler returns handler name of api route
type SyntaxExpr ¶
SyntaxExpr describes syntax for api
func (*SyntaxExpr) Comment ¶
func (s *SyntaxExpr) Comment() Expr
Comment returns the comment of SyntaxExpr, like // some text
func (*SyntaxExpr) Doc ¶
func (s *SyntaxExpr) Doc() []Expr
Doc returns the document of SyntaxExpr, like // some text
func (*SyntaxExpr) Equal ¶
func (s *SyntaxExpr) Equal(v any) bool
Equal compares whether the element literals in two SyntaxExpr are equal
func (*SyntaxExpr) Format ¶
func (s *SyntaxExpr) Format() error
Format provides a formatter for api command, now nothing to do
type Time ¶
type Time struct {
Literal Expr
}
Time describes the time ast for api syntax
type TokenStream ¶
type TokenStream interface { GetStart() antlr.Token GetStop() antlr.Token GetParser() antlr.Parser }
TokenStream defines a token
type TypeAlias ¶
TypeAlias describes alias ast for api syntax
type TypeField ¶
type TypeField struct { IsAnonymous bool // Name is nil if IsAnonymous Name Expr DataType DataType Tag Expr DocExpr []Expr CommentExpr Expr }
TypeField describes field ast for api syntax
type TypeStruct ¶
type TypeStruct struct { Name Expr Struct Expr LBrace Expr RBrace Expr DocExpr []Expr Fields []*TypeField }
TypeStruct describes structure ast for api syntax
func (*TypeStruct) Doc ¶
func (s *TypeStruct) Doc() []Expr
Doc returns the document of TypeStruct, like // some text
func (*TypeStruct) Equal ¶
func (s *TypeStruct) Equal(dt any) bool
Equal compares whether the element literals in two TypeStruct are equal
func (*TypeStruct) Format ¶
func (s *TypeStruct) Format() error
Format provides a formatter for api command, now nothing to do
func (*TypeStruct) NameExpr ¶
func (s *TypeStruct) NameExpr() Expr
NameExpr returns the expression string of TypeStruct
type VisitorOption ¶
type VisitorOption func(v *ApiVisitor)
VisitorOption defines a function with argument ApiVisitor
func WithVisitorDebug ¶
func WithVisitorDebug() VisitorOption
WithVisitorDebug returns a debug VisitorOption
func WithVisitorPrefix ¶
func WithVisitorPrefix(prefix string) VisitorOption
WithVisitorPrefix returns a VisitorOption wrap with specified prefix