fixed some weird transpilation output & removed old ast
This commit is contained in:
parent
e0dd8ff9d5
commit
b63741c8d1
4 changed files with 8 additions and 62 deletions
4
Justfile
Normal file
4
Justfile
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
generate:
|
||||
go generate ./...
|
||||
build: generate
|
||||
go build -o lox-go ./cli
|
||||
55
ast/_ast.go
55
ast/_ast.go
|
|
@ -1,55 +0,0 @@
|
|||
package ast
|
||||
|
||||
import "git.red-panda.pet/pandaware/lox-go/lexer"
|
||||
|
||||
// todo: find something better than any here
|
||||
// we can't use generics on either the visitor itself or
|
||||
// each individual method because the adding it to the
|
||||
// visitor itself infects every expr you use with it
|
||||
// and methods cannot have generic parameters
|
||||
|
||||
type ExprVisitor interface {
|
||||
VisitBinaryExpr(b *BinaryExpr) any
|
||||
VisitGroupingExpr(g *GroupingExpr) any
|
||||
VisitLiteralExpr(g *LiteralExpr) any
|
||||
VisitUnaryExpr(g *UnaryExpr) any
|
||||
}
|
||||
|
||||
type Expr interface {
|
||||
Accept(v ExprVisitor) any
|
||||
}
|
||||
|
||||
type BinaryExpr struct {
|
||||
Left Expr
|
||||
Operator *lexer.Token
|
||||
Right Expr
|
||||
}
|
||||
|
||||
func (b *BinaryExpr) Accept(v ExprVisitor) any {
|
||||
return v.VisitBinaryExpr(b)
|
||||
}
|
||||
|
||||
type GroupingExpr struct {
|
||||
Expr Expr
|
||||
}
|
||||
|
||||
func (g *GroupingExpr) Accept(v ExprVisitor) any {
|
||||
return v.VisitGroupingExpr(g)
|
||||
}
|
||||
|
||||
type LiteralExpr struct {
|
||||
Value any
|
||||
}
|
||||
|
||||
func (l *LiteralExpr) Accept(v ExprVisitor) any {
|
||||
return v.VisitLiteralExpr(l)
|
||||
}
|
||||
|
||||
type UnaryExpr struct {
|
||||
Operator *lexer.Token
|
||||
Right Expr
|
||||
}
|
||||
|
||||
func (u *UnaryExpr) Accept(v ExprVisitor) any {
|
||||
return v.VisitUnaryExpr(u)
|
||||
}
|
||||
|
|
@ -16,10 +16,8 @@ type Expr interface {
|
|||
}
|
||||
|
||||
type BinaryExpr struct {
|
||||
Left Expr
|
||||
|
||||
Op *lexer.Token
|
||||
|
||||
Left Expr
|
||||
Op *lexer.Token
|
||||
Right Expr
|
||||
}
|
||||
|
||||
|
|
@ -50,8 +48,7 @@ func (n *LiteralExpr) Accept(v ExprVisitor) any {
|
|||
var _ Expr = new(LiteralExpr)
|
||||
|
||||
type UnaryExpr struct {
|
||||
Op *lexer.Token
|
||||
|
||||
Op *lexer.Token
|
||||
Right Expr
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -111,7 +111,7 @@ func (t *transpiler) visitField(g *fieldNode) (string, error) {
|
|||
return "", err
|
||||
}
|
||||
|
||||
return fmt.Sprintf("\t%s\t%s\n", left, right), nil
|
||||
return fmt.Sprintf("\t%s\t%s", left, right), nil
|
||||
}
|
||||
|
||||
// visitIdentifier implements visitor.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue