compiler-in-go/pkg/ast/hash.go
jmug 9c32fe1d31 Rename module to "compiler-in-go"
Signed-off-by: jmug <u.g.a.mariano@gmail.com>
2025-01-13 19:56:56 -08:00

24 lines
492 B
Go

package ast
import (
"strings"
"code.jmug.me/jmug/compiler-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, ", ") + "}"
}