-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Clean up packages and error handling
- Loading branch information
1 parent
2f850fe
commit 37333ee
Showing
13 changed files
with
821 additions
and
1,034 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
package ast | ||
|
||
import ( | ||
"fmt" | ||
) | ||
|
||
type astPrinter struct{} | ||
|
||
func (a astPrinter) VisitSuperExpr(expr SuperExpr) interface{} { | ||
// TODO implement me | ||
panic("implement me") | ||
} | ||
|
||
func (a astPrinter) VisitThisExpr(expr ThisExpr) interface{} { | ||
return expr.Keyword.Lexeme | ||
} | ||
|
||
func (a astPrinter) VisitGetExpr(expr GetExpr) interface{} { | ||
// TODO implement me | ||
panic("implement me") | ||
} | ||
|
||
func (a astPrinter) VisitSetExpr(expr SetExpr) interface{} { | ||
// TODO implement me | ||
panic("implement me") | ||
} | ||
|
||
func (a astPrinter) VisitFunctionExpr(expr FunctionExpr) interface{} { | ||
// TODO implement me | ||
panic("implement me") | ||
} | ||
|
||
func (a astPrinter) VisitCallExpr(expr CallExpr) interface{} { | ||
// TODO implement me | ||
panic("implement me") | ||
} | ||
|
||
// print returns a string representation of an Expr node | ||
func (a astPrinter) print(expr Expr) string { | ||
return expr.Accept(a).(string) | ||
} | ||
|
||
func (a astPrinter) VisitAssignExpr(expr AssignExpr) interface{} { | ||
return a.parenthesize("= "+expr.Name.Lexeme, expr.Value) | ||
} | ||
|
||
func (a astPrinter) VisitVariableExpr(expr VariableExpr) interface{} { | ||
return expr.Name.Lexeme | ||
} | ||
|
||
func (a astPrinter) VisitTernaryExpr(expr TernaryExpr) interface{} { | ||
return a.parenthesize("?:", expr.Cond, expr.Left, expr.Right) | ||
} | ||
|
||
func (a astPrinter) VisitBinaryExpr(expr BinaryExpr) interface{} { | ||
return a.parenthesize(expr.Operator.Lexeme, expr.Left, expr.Right) | ||
} | ||
|
||
func (a astPrinter) VisitGroupingExpr(expr GroupingExpr) interface{} { | ||
return a.parenthesize("group", expr.Expression) | ||
} | ||
|
||
func (a astPrinter) VisitLiteralExpr(expr LiteralExpr) interface{} { | ||
if expr.Value == nil { | ||
return "nil" | ||
} | ||
|
||
return fmt.Sprint(expr.Value) | ||
} | ||
|
||
func (a astPrinter) VisitUnaryExpr(expr UnaryExpr) interface{} { | ||
return a.parenthesize(expr.Operator.Lexeme, expr.Right) | ||
} | ||
|
||
func (a astPrinter) VisitLogicalExpr(expr LogicalExpr) interface{} { | ||
return a.parenthesize(expr.Operator.Lexeme, expr.Left, expr.Right) | ||
} | ||
|
||
func (a astPrinter) parenthesize(name string, exprs ...Expr) string { | ||
var str string | ||
|
||
str += "(" + name | ||
for _, expr := range exprs { | ||
str += " " + a.print(expr) | ||
} | ||
str += ")" | ||
|
||
return str | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package main | ||
package interpret | ||
|
||
import ( | ||
"fmt" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,8 @@ | ||
package main | ||
package interpret | ||
|
||
import "time" | ||
import ( | ||
"time" | ||
) | ||
|
||
type clock struct{} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package main | ||
package interpret | ||
|
||
import ( | ||
"fmt" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.