You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

60 lines
1.1 KiB
Go

package parser
import "golox/token"
type ExprVisitor[T any] interface {
VisitErrorExpr(error *ErrorExpr) T
VisitBinaryExpr(binary *BinaryExpr) T
VisitGroupingExpr(grouping *GroupingExpr) T
VisitLiteralExpr(literal *LiteralExpr) T
VisitUnaryExpr(unary *UnaryExpr) T
}
type Expr interface {
Accept(visitor ExprVisitor[any]) any
}
type ErrorExpr struct {
Value string
}
func (t *ErrorExpr) Accept(visitor ExprVisitor[any]) any {
return visitor.VisitErrorExpr(t)
}
type BinaryExpr struct {
Left Expr
Operator token.Token
Right Expr
}
func (t *BinaryExpr) Accept(visitor ExprVisitor[any]) any {
return visitor.VisitBinaryExpr(t)
}
type GroupingExpr struct {
Expression Expr
}
func (t *GroupingExpr) Accept(visitor ExprVisitor[any]) any {
return visitor.VisitGroupingExpr(t)
}
type LiteralExpr struct {
Value any
}
func (t *LiteralExpr) Accept(visitor ExprVisitor[any]) any {
return visitor.VisitLiteralExpr(t)
}
type UnaryExpr struct {
Operator token.Token
Right Expr
}
func (t *UnaryExpr) Accept(visitor ExprVisitor[any]) any {
return visitor.VisitUnaryExpr(t)
}