Hashes
This commit is contained in:
26
ast/ast.go
26
ast/ast.go
@@ -325,3 +325,29 @@ func (ie IndexExpression) String() string {
|
||||
}
|
||||
|
||||
func (ie IndexExpression) expressionNode() {}
|
||||
|
||||
type HashLiteral struct {
|
||||
Token token.Token // the '{' token
|
||||
Pairs map[Expression]Expression
|
||||
}
|
||||
|
||||
func (hl HashLiteral) TokenLiteral() string {
|
||||
return hl.Token.Literal
|
||||
}
|
||||
|
||||
func (hl HashLiteral) String() string {
|
||||
var out bytes.Buffer
|
||||
|
||||
pairs := []string{}
|
||||
for key, value := range hl.Pairs {
|
||||
pairs = append(pairs, key.String()+":"+value.String())
|
||||
}
|
||||
|
||||
out.WriteString("{")
|
||||
out.WriteString(strings.Join(pairs, ", "))
|
||||
out.WriteString("}")
|
||||
|
||||
return out.String()
|
||||
}
|
||||
|
||||
func (hl HashLiteral) expressionNode() {}
|
||||
|
||||
Reference in New Issue
Block a user