Skip to content

Commit 0339ad2

Browse files
committed
export { getVariable, ScopeList };
1 parent 308f684 commit 0339ad2

File tree

2 files changed

+6
-5
lines changed

2 files changed

+6
-5
lines changed

mod.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ import { Array_to_circular_linked_list } from "./4ueAj6/circular-linked-list.ts"
7373
import { cache } from "./sort-integers-by-the-power-value/cache.ts";
7474
import { TreeNodeLeetCodeStringify } from "./utils/TreeNodeLeetCodeStringify.ts";
7575
import { TreeNodeLeetCodeParse } from "./utils/TreeNodeLeetCodeParse.ts";
76+
import { getVariable, ScopeList } from "./parse-lisp-expression/index.ts";
7677
export {
7778
left_rotate,
7879
TrieNode,
@@ -123,3 +124,4 @@ export {
123124
TreeNodeLeetCodeParse,
124125
TreeNodeLeetCodeStringify,
125126
};
127+
export { getVariable, ScopeList };

parse-lisp-expression/index.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -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 {
@@ -202,8 +202,7 @@ export interface Identifier {
202202
name: string;
203203
}
204204
export default evaluate;
205-
206-
function getVariable(scope: ScopeList, name: string): number {
205+
export function getVariable(scope: ScopeList, name: string): number {
207206
if (!scope.parent && !scope.variables.has(name)) {
208207
throw Error("Variable not found:" + name);
209208
}

0 commit comments

Comments
 (0)