Skip to content

Commit a1c5918

Browse files
author
manash
committed
Hooray!! Congratulations. 'Puts' Commit.
1 parent 778735d commit a1c5918

File tree

5 files changed

+39
-5
lines changed

5 files changed

+39
-5
lines changed

index.ts

Whitespace-only changes.

parser/context.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import {HeadFn} from "./exprs/basicFunctions/head";
1515
import {Length} from "./exprs/basicFunctions/len";
1616
import {PushFn} from "./exprs/basicFunctions/push";
17+
import {Puts} from "./exprs/basicFunctions/puts";
1718
import {TailFn} from "./exprs/basicFunctions/tail";
1819
import {FuncLiteral} from "./exprs/functionLiteral";
1920

@@ -88,6 +89,7 @@ class ExecutionContext {
8889
this.basic.set("push", PushFn.create());
8990
this.basic.set("head", HeadFn.create());
9091
this.basic.set("tail", TailFn.create());
92+
this.basic.set('puts', Puts.create());
9193
}
9294
isBuiltin(str: string): boolean {
9395
return this.basic.has(str);
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import {FuncLiteral} from "../functionLiteral";
2+
3+
export class Puts extends FuncLiteral {
4+
execute(evalArgs: any[]) {
5+
for(const v of evalArgs) {
6+
console.log(v);
7+
}
8+
return null;
9+
}
10+
private constructor() {
11+
super();
12+
}
13+
static create() {
14+
return new Puts();
15+
}
16+
}

repl.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,11 @@ function executor(uinput: string) {
3030
try {
3131
return Parser.create(uinput).parse().eval();
3232
} catch (err: any) {
33-
return "Heya! You might have some parsing errors".concat(' ==> ', err.message);
33+
return err.message;
3434
}
3535
}
3636

37-
const evalFun = lexing;
37+
const evalFun = executor;
3838

3939
function evaluator(uinput: string, context, filename, callback) {
4040
callback(null, evalFun(uinput));

tests/eval/evaluator.test.ts

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -179,13 +179,13 @@ describe("Evaluation Queries", () => {
179179
});
180180

181181
describe('7. Objects', () => {
182-
test('1. Evaluation', () => {
182+
test('a. Evaluation', () => {
183183
const inp = `let name = 'hi'; let obj = { name : 'Yo' }; obj['hi'];`
184184
const exp = 'Yo';
185185
testInput(inp, exp);
186186
});
187-
test('2. Complex Evaluation', () => {
188-
const inp = `let two = "two";
187+
test('b. Complex Evaluation', () => {
188+
const inp = `let two = "two";
189189
let o = {
190190
"one": 10 - 9,
191191
two: 1 + 1,
@@ -199,6 +199,22 @@ describe("Evaluation Queries", () => {
199199
const exp = [1, 2, 3, 4, 5, 6];
200200
testInput(inp, exp);
201201
});
202+
203+
test('c. Array inside of Objects', () => {
204+
const inp = `let people = [{"name": "Alice", "age": 24}, {"name": "Anna", "age": 28}];
205+
return people[1]['age'];`;
206+
const exp = 28;
207+
testInput(inp, exp);
208+
})
209+
});
210+
211+
describe('8. Puts', () => {
212+
test('a. Print', () => {
213+
214+
const inp = `puts('Hello')`;
215+
const exp = null;
216+
testInput(inp, exp);
217+
});
202218
});
203219
});
204220

0 commit comments

Comments
 (0)