Skip to content

Commit

Permalink
test: ArrayLiteral class to src/ast/array.ts
Browse files Browse the repository at this point in the history
  • Loading branch information
yazaldefilimone committed Feb 25, 2024
1 parent 75543f9 commit 5699ae5
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions src/ast/array.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { Token } from "token/token";
import { Expression, ExpressionKind } from "./base";
import { Maybe } from "utils";

export class ArrayLiteral implements Expression {
token: Token;
kind: ExpressionKind;
public elements: Maybe<Expression[]>;
constructor(token: Token, elements: Maybe<Expression[]> = null) {
this.token = token;
this.kind = ExpressionKind.ARRAY;
this.elements = elements || null;
}
expressionNode(): void {
throw new Error("Method not implemented.");
}
tokenLiteral(): string {
return this.token.literal;
}
toString(): string {
if (this.elements === null) {
return "";
}
return `[${this.elements.map((e) => e.toString()).join(", ")}]`;
}
}

0 comments on commit 5699ae5

Please sign in to comment.