-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
68ebf64
commit 6396872
Showing
6 changed files
with
204 additions
and
2 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
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
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,42 @@ | ||
package evaluator | ||
|
||
import ( | ||
"github.com/grantwforsythe/monkeylang/pkg/ast" | ||
"github.com/grantwforsythe/monkeylang/pkg/object" | ||
) | ||
|
||
func quote(node ast.Node, env *object.Environment) object.Object { | ||
return &object.Quote{Node: evalUnquoteCalls(node, env)} | ||
} | ||
|
||
func evalUnquoteCalls(quote ast.Node, env *object.Environment) ast.Node { | ||
return ast.Modify(quote, func(node ast.Node) ast.Node { | ||
if !isUnquoteCall(node) { | ||
return node | ||
} | ||
|
||
// We make this same assertion in isUnquoteCall so no need to do it again | ||
call, _ := node.(*ast.CallExpression) | ||
|
||
// Can only handle one expression | ||
if len(call.Arguments) != 1 { | ||
return node | ||
} | ||
|
||
eval := Eval(node, env) | ||
if convertible, ok := eval.(object.Convertible); !ok { | ||
return convertible.ToNode() | ||
} | ||
|
||
return node | ||
}) | ||
} | ||
|
||
// Check if a node is call expression for unquote. | ||
func isUnquoteCall(node ast.Node) bool { | ||
fn, ok := node.(*ast.CallExpression) | ||
if !ok { | ||
return false | ||
} | ||
return fn.Arguments[0].Function.TokenLiteral() == "unquote" | ||
Check failure on line 41 in pkg/evaluator/quote_unqote.go
|
||
} |
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