24 lines
492 B
Go
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, ", ") + "}"
|
|
}
|