Skip to content

Commit

Permalink
feat: IndexExpression class to handle index expressions
Browse files Browse the repository at this point in the history
  • Loading branch information
yazaldefilimone committed Feb 25, 2024
1 parent 8620539 commit 1e7f33e
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions src/ast/index-expression.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { Token } from "token";
import { Expression, ExpressionKind } from "./base";
import { Maybe } from "utils";

export class IndexExpression implements Expression {
token: Token;
left: Maybe<Expression>;
index: Maybe<Expression>;
kind: ExpressionKind;
constructor(token: Token, left: Maybe<Expression> = null, index: Maybe<Expression> = null) {
this.token = token;
this.left = left;
this.index = index;
this.kind = ExpressionKind.INDEX;
}

expressionNode() {}
tokenLiteral() {
return this.token.literal;
}
toString() {
return `(${this.left?.toString()}[${this.index?.toString()}])`;
}
}

0 comments on commit 1e7f33e

Please sign in to comment.