From 77d0ea46b3f1de99357c7706c4c05eb44c237412 Mon Sep 17 00:00:00 2001 From: Bobby Date: Thu, 4 Apr 2024 16:25:56 +0000 Subject: arrays and array indexes --- ast/ast.go | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'ast') diff --git a/ast/ast.go b/ast/ast.go index 9473f1a..cc30808 100644 --- a/ast/ast.go +++ b/ast/ast.go @@ -329,3 +329,23 @@ func (al *ArrayLiteral) String() string { return out.String() } + +type IndexExpression struct { + Token tokens.Token // the '[' token + Left Expression + Index Expression +} + +func (ie *IndexExpression) expressionNode() {} +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() +} -- cgit v1.2.3