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) interface{}
- func (v *ApiVisitor) VisitApi(ctx *api.ApiContext) interface{}
- func (v *ApiVisitor) VisitArrayType(ctx *api.ArrayTypeContext) interface{}
- func (v *ApiVisitor) VisitAtDoc(ctx *api.AtDocContext) interface{}
- func (v *ApiVisitor) VisitAtHandler(ctx *api.AtHandlerContext) interface{}
- func (v *ApiVisitor) VisitAtServer(ctx *api.AtServerContext) interface{}
- func (v *ApiVisitor) VisitBody(ctx *api.BodyContext) interface{}
- func (v *ApiVisitor) VisitDataType(ctx *api.DataTypeContext) interface{}
- func (v *ApiVisitor) VisitField(ctx *api.FieldContext) interface{}
- func (v *ApiVisitor) VisitImportBlock(ctx *api.ImportBlockContext) interface{}
- func (v *ApiVisitor) VisitImportBlockValue(ctx *api.ImportBlockValueContext) interface{}
- func (v *ApiVisitor) VisitImportLit(ctx *api.ImportLitContext) interface{}
- func (v *ApiVisitor) VisitImportSpec(ctx *api.ImportSpecContext) interface{}
- func (v *ApiVisitor) VisitImportValue(ctx *api.ImportValueContext) interface{}
- func (v *ApiVisitor) VisitInfoSpec(ctx *api.InfoSpecContext) interface{}
- func (v *ApiVisitor) VisitKvLit(ctx *api.KvLitContext) interface{}
- func (v *ApiVisitor) VisitMapType(ctx *api.MapTypeContext) interface{}
- func (v *ApiVisitor) VisitNormalField(ctx *api.NormalFieldContext) interface{}
- func (v *ApiVisitor) VisitPointerType(ctx *api.PointerTypeContext) interface{}
- func (v *ApiVisitor) VisitReplybody(ctx *api.ReplybodyContext) interface{}
- func (v *ApiVisitor) VisitRoute(ctx *api.RouteContext) interface{}
- func (v *ApiVisitor) VisitServiceApi(ctx *api.ServiceApiContext) interface{}
- func (v *ApiVisitor) VisitServiceRoute(ctx *api.ServiceRouteContext) interface{}
- func (v *ApiVisitor) VisitServiceSpec(ctx *api.ServiceSpecContext) interface{}
- func (v *ApiVisitor) VisitSpec(ctx *api.SpecContext) interface{}
- func (v *ApiVisitor) VisitSyntaxLit(ctx *api.SyntaxLitContext) interface{}
- func (v *ApiVisitor) VisitTypeAlias(ctx *api.TypeAliasContext) interface{}
- func (v *ApiVisitor) VisitTypeBlock(ctx *api.TypeBlockContext) interface{}
- func (v *ApiVisitor) VisitTypeBlockAlias(ctx *api.TypeBlockAliasContext) interface{}
- func (v *ApiVisitor) VisitTypeBlockBody(ctx *api.TypeBlockBodyContext) interface{}
- func (v *ApiVisitor) VisitTypeBlockStruct(ctx *api.TypeBlockStructContext) interface{}
- func (v *ApiVisitor) VisitTypeLit(ctx *api.TypeLitContext) interface{}
- func (v *ApiVisitor) VisitTypeLitBody(ctx *api.TypeLitBodyContext) interface{}
- func (v *ApiVisitor) VisitTypeSpec(ctx *api.TypeSpecContext) interface{}
- func (v *ApiVisitor) VisitTypeStruct(ctx *api.TypeStructContext) interface{}
- 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) interface{}, ...) (v interface{}, 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, _ interface{}, 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) interface{}
VisitAnonymousFiled implements from api.BaseApiParserVisitor
func (*ApiVisitor) VisitApi ¶
func (v *ApiVisitor) VisitApi(ctx *api.ApiContext) interface{}
VisitApi implements from api.BaseApiParserVisitor
func (*ApiVisitor) VisitArrayType ¶
func (v *ApiVisitor) VisitArrayType(ctx *api.ArrayTypeContext) interface{}
VisitArrayType implements from api.BaseApiParserVisitor
func (*ApiVisitor) VisitAtDoc ¶
func (v *ApiVisitor) VisitAtDoc(ctx *api.AtDocContext) interface{}
VisitAtDoc implements from api.BaseApiParserVisitor
func (*ApiVisitor) VisitAtHandler ¶
func (v *ApiVisitor) VisitAtHandler(ctx *api.AtHandlerContext) interface{}
VisitAtHandler implements from api.BaseApiParserVisitor
func (*ApiVisitor) VisitAtServer ¶
func (v *ApiVisitor) VisitAtServer(ctx *api.AtServerContext) interface{}
VisitAtServer implements from api.BaseApiParserVisitor
func (*ApiVisitor) VisitBody ¶
func (v *ApiVisitor) VisitBody(ctx *api.BodyContext) interface{}
VisitBody implements from api.BaseApiParserVisitor
func (*ApiVisitor) VisitDataType ¶
func (v *ApiVisitor) VisitDataType(ctx *api.DataTypeContext) interface{}
VisitDataType implements from api.BaseApiParserVisitor
func (*ApiVisitor) VisitField ¶
func (v *ApiVisitor) VisitField(ctx *api.FieldContext) interface{}
VisitField implements from api.BaseApiParserVisitor
func (*ApiVisitor) VisitImportBlock ¶
func (v *ApiVisitor) VisitImportBlock(ctx *api.ImportBlockContext) interface{}
VisitImportBlock implements from api.BaseApiParserVisitor
func (*ApiVisitor) VisitImportBlockValue ¶
func (v *ApiVisitor) VisitImportBlockValue(ctx *api.ImportBlockValueContext) interface{}
VisitImportBlockValue implements from api.BaseApiParserVisitor
func (*ApiVisitor) VisitImportLit ¶
func (v *ApiVisitor) VisitImportLit(ctx *api.ImportLitContext) interface{}
VisitImportLit implements from api.BaseApiParserVisitor
func (*ApiVisitor) VisitImportSpec ¶
func (v *ApiVisitor) VisitImportSpec(ctx *api.ImportSpecContext) interface{}
VisitImportSpec implements from api.BaseApiParserVisitor
func (*ApiVisitor) VisitImportValue ¶
func (v *ApiVisitor) VisitImportValue(ctx *api.ImportValueContext) interface{}
VisitImportValue implements from api.BaseApiParserVisitor
func (*ApiVisitor) VisitInfoSpec ¶
func (v *ApiVisitor) VisitInfoSpec(ctx *api.InfoSpecContext) interface{}
VisitInfoSpec implements from api.BaseApiParserVisitor
func (*ApiVisitor) VisitKvLit ¶
func (v *ApiVisitor) VisitKvLit(ctx *api.KvLitContext) interface{}
VisitKvLit implements from api.BaseApiParserVisitor
func (*ApiVisitor) VisitMapType ¶
func (v *ApiVisitor) VisitMapType(ctx *api.MapTypeContext) interface{}
VisitMapType implements from api.BaseApiParserVisitor
func (*ApiVisitor) VisitNormalField ¶
func (v *ApiVisitor) VisitNormalField(ctx *api.NormalFieldContext) interface{}
VisitNormalField implements from api.BaseApiParserVisitor
func (*ApiVisitor) VisitPointerType ¶
func (v *ApiVisitor) VisitPointerType(ctx *api.PointerTypeContext) interface{}
VisitPointerType implements from api.BaseApiParserVisitor
func (*ApiVisitor) VisitReplybody ¶
func (v *ApiVisitor) VisitReplybody(ctx *api.ReplybodyContext) interface{}
VisitReplybody implements from api.BaseApiParserVisitor
func (*ApiVisitor) VisitRoute ¶
func (v *ApiVisitor) VisitRoute(ctx *api.RouteContext) interface{}
serVisitRoute implements from api.BaseApiParserVisitor
func (*ApiVisitor) VisitServiceApi ¶
func (v *ApiVisitor) VisitServiceApi(ctx *api.ServiceApiContext) interface{}
VisitServiceApi implements from api.BaseApiParserVisitor
func (*ApiVisitor) VisitServiceRoute ¶
func (v *ApiVisitor) VisitServiceRoute(ctx *api.ServiceRouteContext) interface{}
VisitServiceRoute implements from api.BaseApiParserVisitor
func (*ApiVisitor) VisitServiceSpec ¶
func (v *ApiVisitor) VisitServiceSpec(ctx *api.ServiceSpecContext) interface{}
VisitServiceSpec implements from api.BaseApiParserVisitor
func (*ApiVisitor) VisitSpec ¶
func (v *ApiVisitor) VisitSpec(ctx *api.SpecContext) interface{}
VisitSpec implements from api.BaseApiParserVisitor
func (*ApiVisitor) VisitSyntaxLit ¶
func (v *ApiVisitor) VisitSyntaxLit(ctx *api.SyntaxLitContext) interface{}
VisitSyntaxLit implements from api.BaseApiParserVisitor
func (*ApiVisitor) VisitTypeAlias ¶
func (v *ApiVisitor) VisitTypeAlias(ctx *api.TypeAliasContext) interface{}
VisitTypeAlias implements from api.BaseApiParserVisitor
func (*ApiVisitor) VisitTypeBlock ¶
func (v *ApiVisitor) VisitTypeBlock(ctx *api.TypeBlockContext) interface{}
VisitTypeBlock implements from api.BaseApiParserVisitor
func (*ApiVisitor) VisitTypeBlockAlias ¶
func (v *ApiVisitor) VisitTypeBlockAlias(ctx *api.TypeBlockAliasContext) interface{}
VisitTypeBlockAlias implements from api.BaseApiParserVisitor
func (*ApiVisitor) VisitTypeBlockBody ¶
func (v *ApiVisitor) VisitTypeBlockBody(ctx *api.TypeBlockBodyContext) interface{}
VisitTypeBlockBody implements from api.BaseApiParserVisitor
func (*ApiVisitor) VisitTypeBlockStruct ¶
func (v *ApiVisitor) VisitTypeBlockStruct(ctx *api.TypeBlockStructContext) interface{}
VisitTypeBlockStruct implements from api.BaseApiParserVisitor
func (*ApiVisitor) VisitTypeLit ¶
func (v *ApiVisitor) VisitTypeLit(ctx *api.TypeLitContext) interface{}
VisitTypeLit implements from api.BaseApiParserVisitor
func (*ApiVisitor) VisitTypeLitBody ¶
func (v *ApiVisitor) VisitTypeLitBody(ctx *api.TypeLitBodyContext) interface{}
VisitTypeLitBody implements from api.BaseApiParserVisitor
func (*ApiVisitor) VisitTypeSpec ¶
func (v *ApiVisitor) VisitTypeSpec(ctx *api.TypeSpecContext) interface{}
VisitTypeSpec implements from api.BaseApiParserVisitor
func (*ApiVisitor) VisitTypeStruct ¶
func (v *ApiVisitor) VisitTypeStruct(ctx *api.TypeStructContext) interface{}
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 interface{}) 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 interface{}
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) interface{}, content string) (v interface{}, 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, _ interface{}, 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 interface{}) 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 interface{}) 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 interface{}) 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 interface{}) 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