go-zero/tools/goctl/api/parser/g4/ast/syntax.go
kingxt ee19fb736b
feature: refactor api parse to g4 (#365)
* feature: refactor api parse to g4

* new g4 parser

* add CHANGE_LOG.MD

* refactor

* fix byte bug

* refactor

* optimized

* optimized

* revert

* update readme.md

* update readme.md

* update readme.md

* update readme.md

* remove no need

* fix java gen

* add upgrade

* resolve confilits

Co-authored-by: anqiansong <anqiansong@xiaoheiban.cn>
2021-01-11 15:10:51 +08:00

59 lines
1.1 KiB
Go

package ast
import (
"github.com/tal-tech/go-zero/tools/goctl/api/parser/g4/gen/api"
)
type SyntaxExpr struct {
Syntax Expr
Assign Expr
Version Expr
DocExpr []Expr
CommentExpr Expr
}
func (v *ApiVisitor) VisitSyntaxLit(ctx *api.SyntaxLitContext) interface{} {
syntax := v.newExprWithToken(ctx.GetSyntaxToken())
assign := v.newExprWithToken(ctx.GetAssign())
version := v.newExprWithToken(ctx.GetVersion())
return &SyntaxExpr{
Syntax: syntax,
Assign: assign,
Version: version,
DocExpr: v.getDoc(ctx),
CommentExpr: v.getComment(ctx),
}
}
func (s *SyntaxExpr) Format() error {
// todo
return nil
}
func (s *SyntaxExpr) Equal(v interface{}) bool {
if v == nil {
return false
}
syntax, ok := v.(*SyntaxExpr)
if !ok {
return false
}
if !EqualDoc(s, syntax) {
return false
}
return s.Syntax.Equal(syntax.Syntax) &&
s.Assign.Equal(syntax.Assign) &&
s.Version.Equal(syntax.Version)
}
func (s *SyntaxExpr) Doc() []Expr {
return s.DocExpr
}
func (s *SyntaxExpr) Comment() Expr {
return s.CommentExpr
}