-
Notifications
You must be signed in to change notification settings - Fork 136
/
expr.go
52 lines (42 loc) · 835 Bytes
/
expr.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
package dsl
type Expr interface {
Accept(ExprVisitor)
}
type ExprVisitor interface {
visitBinary(binary Binary)
visitUnary(unary Unary)
visitGrouping(grouping Grouping)
visitLiteral(literal Literal)
}
// Binary is used for And, Or
type Binary struct {
Left Expr
Operator Token
Right Expr
Output attr
}
func (b Binary) Accept(visitor ExprVisitor) {
visitor.visitBinary(b)
}
// Unary is used for Not
type Unary struct {
Operator Token
Right Expr
}
func (u Unary) Accept(visitor ExprVisitor) {
visitor.visitUnary(u)
}
// Grouping is used for LeftParen, RightParen
type Grouping struct {
Expr Expr
}
func (g Grouping) Accept(visitor ExprVisitor) {
visitor.visitGrouping(g)
}
type Literal struct {
Key attr
Value attrValue
}
func (l Literal) Accept(visitor ExprVisitor) {
visitor.visitLiteral(l)
}