syntax.go 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. package ast
  2. import (
  3. "git.i2edu.net/i2/go-zero/tools/goctl/api/parser/g4/gen/api"
  4. )
  5. // SyntaxExpr describes syntax for api
  6. type SyntaxExpr struct {
  7. Syntax Expr
  8. Assign Expr
  9. Version Expr
  10. DocExpr []Expr
  11. CommentExpr Expr
  12. }
  13. // VisitSyntaxLit implements from api.BaseApiParserVisitor
  14. func (v *ApiVisitor) VisitSyntaxLit(ctx *api.SyntaxLitContext) interface{} {
  15. syntax := v.newExprWithToken(ctx.GetSyntaxToken())
  16. assign := v.newExprWithToken(ctx.GetAssign())
  17. version := v.newExprWithToken(ctx.GetVersion())
  18. return &SyntaxExpr{
  19. Syntax: syntax,
  20. Assign: assign,
  21. Version: version,
  22. DocExpr: v.getDoc(ctx),
  23. CommentExpr: v.getComment(ctx),
  24. }
  25. }
  26. // Format provides a formatter for api command, now nothing to do
  27. func (s *SyntaxExpr) Format() error {
  28. // todo
  29. return nil
  30. }
  31. // Equal compares whether the element literals in two SyntaxExpr are equal
  32. func (s *SyntaxExpr) Equal(v interface{}) bool {
  33. if v == nil {
  34. return false
  35. }
  36. syntax, ok := v.(*SyntaxExpr)
  37. if !ok {
  38. return false
  39. }
  40. if !EqualDoc(s, syntax) {
  41. return false
  42. }
  43. return s.Syntax.Equal(syntax.Syntax) &&
  44. s.Assign.Equal(syntax.Assign) &&
  45. s.Version.Equal(syntax.Version)
  46. }
  47. // Doc returns the document of SyntaxExpr, like // some text
  48. func (s *SyntaxExpr) Doc() []Expr {
  49. return s.DocExpr
  50. }
  51. // Comment returns the comment of SyntaxExpr, like // some text
  52. func (s *SyntaxExpr) Comment() Expr {
  53. return s.CommentExpr
  54. }