compiler-in-go/pkg/ast/return.go
jmug 0acd1d41e8 Add all the files from the interpreter repo
Signed-off-by: jmug <u.g.a.mariano@gmail.com>
2025-01-13 19:51:49 -08:00

26 lines
590 B
Go

package ast
import (
"bytes"
"code.jmug.me/jmug/interpreter-in-go/pkg/token"
)
type ReturnStatement struct {
Token token.Token // TODO: This is a little redundant, figure out if I can get rid of it.
ReturnValue Expression
}
func (rs *ReturnStatement) statementNode() {}
func (rs *ReturnStatement) TokenLiteral() string {
return rs.Token.Literal
}
func (rs *ReturnStatement) String() string {
var out bytes.Buffer
out.WriteString(rs.TokenLiteral())
if rs.ReturnValue != nil {
out.WriteString(" " + rs.ReturnValue.String())
}
out.WriteString(";")
return out.String()
}