compiler-in-go/pkg/ast/hash.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

24 lines
495 B
Go

package ast
import (
"strings"
"code.jmug.me/jmug/interpreter-in-go/pkg/token"
)
type HashLiteral struct {
Token token.Token // The "{" token
Pairs map[Expression]Expression
}
func (hl *HashLiteral) expressionNode() {}
func (hl *HashLiteral) TokenLiteral() string {
return hl.Token.Literal
}
func (hl *HashLiteral) String() string {
pairs := []string{}
for k, v := range hl.Pairs {
pairs = append(pairs, k.String()+":"+v.String())
}
return "{" + strings.Join(pairs, ", ") + "}"
}