Skip to content

Commit

Permalink
Improve error messages in typechecker
Browse files Browse the repository at this point in the history
  • Loading branch information
chidiwilliams committed Jul 10, 2022
1 parent aedc0f9 commit 33b5d0d
Show file tree
Hide file tree
Showing 10 changed files with 285 additions and 122 deletions.
138 changes: 137 additions & 1 deletion ast/expr.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,25 @@ package ast

type Expr interface {
Accept(visitor ExprVisitor) interface{}
StartLine() int
EndLine() int
}

type AssignExpr struct {
Name Token
Value Expr
}

func (b AssignExpr) StartLine() int {
// TODO implement me
panic("implement me")
}

func (b AssignExpr) EndLine() int {
// TODO implement me
panic("implement me")
}

func (b AssignExpr) Accept(visitor ExprVisitor) interface{} {
return visitor.VisitAssignExpr(b)
}
Expand All @@ -19,6 +31,14 @@ type BinaryExpr struct {
Right Expr
}

func (b BinaryExpr) StartLine() int {
return b.Left.StartLine()
}

func (b BinaryExpr) EndLine() int {
return b.Right.EndLine()
}

func (b BinaryExpr) Accept(visitor ExprVisitor) interface{} {
return visitor.VisitBinaryExpr(b)
}
Expand All @@ -29,6 +49,16 @@ type CallExpr struct {
Arguments []Expr
}

func (b CallExpr) StartLine() int {
// TODO implement me
panic("implement me")
}

func (b CallExpr) EndLine() int {
// TODO implement me
panic("implement me")
}

func (b CallExpr) Accept(visitor ExprVisitor) interface{} {
return visitor.VisitCallExpr(b)
}
Expand All @@ -40,6 +70,16 @@ type FunctionExpr struct {
ReturnType Type
}

func (b FunctionExpr) StartLine() int {
// TODO implement me
panic("implement me")
}

func (b FunctionExpr) EndLine() int {
// TODO implement me
panic("implement me")
}

func (b FunctionExpr) Accept(visitor ExprVisitor) interface{} {
return visitor.VisitFunctionExpr(b)
}
Expand All @@ -49,6 +89,16 @@ type GetExpr struct {
Name Token
}

func (b GetExpr) StartLine() int {
// TODO implement me
panic("implement me")
}

func (b GetExpr) EndLine() int {
// TODO implement me
panic("implement me")
}

func (b GetExpr) Accept(visitor ExprVisitor) interface{} {
return visitor.VisitGetExpr(b)
}
Expand All @@ -57,12 +107,30 @@ type GroupingExpr struct {
Expression Expr
}

func (b GroupingExpr) StartLine() int {
return b.Expression.StartLine()
}

func (b GroupingExpr) EndLine() int {
return b.Expression.EndLine()
}

func (b GroupingExpr) Accept(visitor ExprVisitor) interface{} {
return visitor.VisitGroupingExpr(b)
}

type LiteralExpr struct {
Value interface{}
Value interface{}
LineStart int
LineEnd int
}

func (b LiteralExpr) StartLine() int {
return b.LineStart
}

func (b LiteralExpr) EndLine() int {
return b.LineEnd
}

func (b LiteralExpr) Accept(visitor ExprVisitor) interface{} {
Expand All @@ -75,6 +143,16 @@ type LogicalExpr struct {
Right Expr
}

func (b LogicalExpr) StartLine() int {
// TODO implement me
panic("implement me")
}

func (b LogicalExpr) EndLine() int {
// TODO implement me
panic("implement me")
}

func (b LogicalExpr) Accept(visitor ExprVisitor) interface{} {
return visitor.VisitLogicalExpr(b)
}
Expand All @@ -85,6 +163,16 @@ type SetExpr struct {
Value Expr
}

func (b SetExpr) StartLine() int {
// TODO implement me
panic("implement me")
}

func (b SetExpr) EndLine() int {
// TODO implement me
panic("implement me")
}

func (b SetExpr) Accept(visitor ExprVisitor) interface{} {
return visitor.VisitSetExpr(b)
}
Expand All @@ -94,6 +182,16 @@ type SuperExpr struct {
Method Token
}

func (b SuperExpr) StartLine() int {
// TODO implement me
panic("implement me")
}

func (b SuperExpr) EndLine() int {
// TODO implement me
panic("implement me")
}

func (b SuperExpr) Accept(visitor ExprVisitor) interface{} {
return visitor.VisitSuperExpr(b)
}
Expand All @@ -102,6 +200,16 @@ type ThisExpr struct {
Keyword Token
}

func (b ThisExpr) StartLine() int {
// TODO implement me
panic("implement me")
}

func (b ThisExpr) EndLine() int {
// TODO implement me
panic("implement me")
}

func (b ThisExpr) Accept(visitor ExprVisitor) interface{} {
return visitor.VisitThisExpr(b)
}
Expand All @@ -112,6 +220,16 @@ type TernaryExpr struct {
Alternate Expr
}

func (b TernaryExpr) StartLine() int {
// TODO implement me
panic("implement me")
}

func (b TernaryExpr) EndLine() int {
// TODO implement me
panic("implement me")
}

func (b TernaryExpr) Accept(visitor ExprVisitor) interface{} {
return visitor.VisitTernaryExpr(b)
}
Expand All @@ -121,6 +239,16 @@ type UnaryExpr struct {
Right Expr
}

func (b UnaryExpr) StartLine() int {
// TODO implement me
panic("implement me")
}

func (b UnaryExpr) EndLine() int {
// TODO implement me
panic("implement me")
}

func (b UnaryExpr) Accept(visitor ExprVisitor) interface{} {
return visitor.VisitUnaryExpr(b)
}
Expand All @@ -129,6 +257,14 @@ type VariableExpr struct {
Name Token
}

func (b VariableExpr) StartLine() int {
return b.Name.Line
}

func (b VariableExpr) EndLine() int {
return b.Name.Line
}

func (b VariableExpr) Accept(visitor ExprVisitor) interface{} {
return visitor.VisitVariableExpr(b)
}
Expand Down
Loading

0 comments on commit 33b5d0d

Please sign in to comment.