interpreter-in-go/pkg/ast/hash.go

25 lines
495 B
Go
Raw Normal View History

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, ", ") + "}"
}