aboutsummaryrefslogtreecommitdiff
path: root/ast
diff options
context:
space:
mode:
authorBobby <[email protected]>2024-01-24 21:26:00 +0000
committerBobby <[email protected]>2024-01-24 21:26:00 +0000
commitbe05c459c07ae9e14f6c09fd3f820d8a459f3254 (patch)
tree19a6be7c75097e72b7633bda859512b1f5943b76 /ast
parentc07b5f8fd0cf8bd1654825dcf7401d670fda4c0a (diff)
downloadmana-be05c459c07ae9e14f6c09fd3f820d8a459f3254.tar.xz
mana-be05c459c07ae9e14f6c09fd3f820d8a459f3254.zip
fn literals
Diffstat (limited to 'ast')
-rw-r--r--ast/ast.go27
1 files changed, 27 insertions, 0 deletions
diff --git a/ast/ast.go b/ast/ast.go
index 31b1be1..424b4ac 100644
--- a/ast/ast.go
+++ b/ast/ast.go
@@ -3,6 +3,7 @@ package ast
import (
"bytes"
"mana/tokens"
+ "strings"
)
type Node interface {
@@ -247,3 +248,29 @@ func (ie *IfExpression) String() string {
return out.String()
}
+
+type FunctionLiteral struct {
+ Token tokens.Token // the 'fn' token
+ Parameters []*Identifier
+ Body *BlockStatement
+}
+
+func (fl *FunctionLiteral) expressionNode() {}
+func (fl *FunctionLiteral) TokenLiteral() string { return fl.Token.Literal }
+func (fl *FunctionLiteral) String() string {
+ var out bytes.Buffer
+
+ params := []string{}
+
+ for _, p := range fl.Parameters {
+ params = append(params, p.String())
+ }
+
+ out.WriteString(fl.TokenLiteral())
+ out.WriteString("(")
+ out.WriteString(strings.Join(params, ", "))
+ out.WriteString(")")
+ out.WriteString(fl.Body.String())
+
+ return out.String()
+}