arrays + builtins
This commit is contained in:
48
ast/ast.go
48
ast/ast.go
@@ -277,3 +277,51 @@ func (sl StringLiteral) String() string {
|
||||
return sl.Token.Literal
|
||||
}
|
||||
func (sl StringLiteral) expressionNode() {}
|
||||
|
||||
type ArrayLiteral struct {
|
||||
Token token.Token // the '[' token
|
||||
Elements []Expression
|
||||
}
|
||||
|
||||
func (al ArrayLiteral) TokenLiteral() string {
|
||||
return al.Token.Literal
|
||||
}
|
||||
func (al ArrayLiteral) String() string {
|
||||
var out bytes.Buffer
|
||||
|
||||
elements := []string{}
|
||||
for _, el := range al.Elements {
|
||||
elements = append(elements, el.String())
|
||||
}
|
||||
|
||||
out.WriteString("[")
|
||||
out.WriteString(strings.Join(elements, ", "))
|
||||
out.WriteString("]")
|
||||
|
||||
return out.String()
|
||||
}
|
||||
func (al ArrayLiteral) expressionNode() {}
|
||||
|
||||
type IndexExpression struct {
|
||||
Token token.Token // The [ token
|
||||
Left Expression
|
||||
Index Expression
|
||||
}
|
||||
|
||||
func (ie IndexExpression) TokenLiteral() string {
|
||||
return ie.Token.Literal
|
||||
}
|
||||
|
||||
func (ie IndexExpression) String() string {
|
||||
var out bytes.Buffer
|
||||
|
||||
out.WriteString("(")
|
||||
out.WriteString(ie.Left.String())
|
||||
out.WriteString("[")
|
||||
out.WriteString(ie.Index.String())
|
||||
out.WriteString("])")
|
||||
|
||||
return out.String()
|
||||
}
|
||||
|
||||
func (ie IndexExpression) expressionNode() {}
|
||||
|
||||
Reference in New Issue
Block a user