-
Notifications
You must be signed in to change notification settings - Fork 14
/
syntax.go
64 lines (54 loc) · 1.38 KB
/
syntax.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
package ast
import (
"github.com/suyuan32/goctls/api/parser/g4/gen/api"
)
// SyntaxExpr describes syntax for api
type SyntaxExpr struct {
Syntax Expr
Assign Expr
Version Expr
DocExpr []Expr
CommentExpr Expr
}
// VisitSyntaxLit implements from api.BaseApiParserVisitor
func (v *ApiVisitor) VisitSyntaxLit(ctx *api.SyntaxLitContext) any {
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),
}
}
// Format provides a formatter for api command, now nothing to do
func (s *SyntaxExpr) Format() error {
// todo
return nil
}
// Equal compares whether the element literals in two SyntaxExpr are equal
func (s *SyntaxExpr) Equal(v any) 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)
}
// Doc returns the document of SyntaxExpr, like // some text
func (s *SyntaxExpr) Doc() []Expr {
return s.DocExpr
}
// Comment returns the comment of SyntaxExpr, like // some text
func (s *SyntaxExpr) Comment() Expr {
return s.CommentExpr
}