Skip to content

Commit 308f684

Browse files
committed
Update index.ts
1 parent a4ddf63 commit 308f684

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

parse-lisp-expression/index.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ function parseLet(expression: string): Expression {
1111
const content = expression.slice("(let ".length, -1);
1212
const list = parseList("(" + content + ")");
1313
// console.log(list);
14-
if (Array.isArray(list) && list.length <3) {
14+
if (Array.isArray(list) && list.length < 3) {
1515
throw Error("Invalid expression");
1616
}
1717
return buildExpression(["let", ...list]);
@@ -55,7 +55,7 @@ function buildExpression(list: string | number | ListArray): Expression {
5555
};
5656
}
5757
if (typeof list === "string") {
58-
return { type: "Identifier", name: list };
58+
return parseIdentifier(list);
5959
}
6060
if (typeof list === "number") {
6161
return parseNumeric(list);
@@ -89,7 +89,7 @@ function parseList(expression: string): ListArray {
8989
.replaceAll("(", "[")
9090
.replaceAll(")", "]")
9191
.replaceAll(" ", ",")
92-
.replaceAll(/[a-z]([a-z]|\d)*/g, (a) => '"' + a + '"'),
92+
.replaceAll(/[a-z]([a-z]|\d)*/g, (a) => '"' + a + '"')
9393
);
9494
}
9595

@@ -149,7 +149,7 @@ function calculate(expression: Expression, scope: ScopeList): number {
149149
expression.declarations.forEach((declaration) => {
150150
newScope.variables.set(
151151
declaration.id.name,
152-
calculate(declaration.init, newScope),
152+
calculate(declaration.init, newScope)
153153
);
154154
});
155155
return calculate(expression.return.argument, newScope);
@@ -165,7 +165,7 @@ export type Expression =
165165
export class ScopeList {
166166
constructor(
167167
public readonly variables: Map<string, number> = new Map(),
168-
public parent: ScopeList | null | undefined = null,
168+
public parent: ScopeList | null | undefined = null
169169
) {}
170170
}
171171
export interface VariableDeclarator {

0 commit comments

Comments
 (0)