Done with the book! Added hash maps and the puts builtin.
Signed-off-by: jmug <u.g.a.mariano@gmail.com>
This commit is contained in:
parent
fa9f450278
commit
fb25a86b91
11 changed files with 373 additions and 0 deletions
24
pkg/ast/hash.go
Normal file
24
pkg/ast/hash.go
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
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, ", ") + "}"
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue