|
1 | | -import { BasicEvaluator } from "conductor/dist/conductor/runner"; |
2 | | -import { IRunnerPlugin } from "conductor/dist/conductor/runner/types"; |
3 | | -import { initialise } from "conductor/dist/conductor/runner/util"; |
4 | | -import { Context, runInContext, createContext } from "./index"; |
5 | | -import { Value, Chapter, Variant } from "./types"; |
| 1 | +import { BasicEvaluator } from 'conductor/dist/conductor/runner' |
| 2 | +import { IRunnerPlugin } from 'conductor/dist/conductor/runner/types' |
| 3 | +import { initialise } from 'conductor/dist/conductor/runner/util' |
| 4 | +import { Context, runInContext, createContext } from './index' |
| 5 | +import { Value, Chapter, Variant } from './types' |
6 | 6 |
|
7 | 7 | class JsSlangEvaluator extends BasicEvaluator { |
8 | | - private ctx: Context; |
| 8 | + private ctx: Context |
9 | 9 |
|
10 | | - async evaluateChunk(chunk: string): Promise<void> { |
11 | | - const res = await runInContext(chunk, this.ctx); |
12 | | - if (res.status === "error") { |
13 | | - console.error(res); |
14 | | - } else { |
15 | | - this.ctx = res.context; |
16 | | - if (res.status === "finished") return res.value; |
17 | | - } |
| 10 | + async evaluateChunk(chunk: string): Promise<void> { |
| 11 | + const res = await runInContext(chunk, this.ctx) |
| 12 | + if (res.status === 'error') { |
| 13 | + console.error(res) |
| 14 | + } else { |
| 15 | + this.ctx = res.context |
| 16 | + if (res.status === 'finished') return res.value |
18 | 17 | } |
| 18 | + } |
19 | 19 |
|
20 | | - constructor(conductor: IRunnerPlugin) { |
21 | | - super(conductor); |
| 20 | + constructor(conductor: IRunnerPlugin) { |
| 21 | + super(conductor) |
22 | 22 |
|
23 | | - const rawDisplay = (value: Value, str: string, _externalContext: any) => { |
24 | | - this.conductor.sendOutput((str === undefined ? '' : str + ' ') + String(value)); |
25 | | - return value; |
26 | | - }; |
| 23 | + const rawDisplay = (value: Value, str: string, _externalContext: any) => { |
| 24 | + this.conductor.sendOutput((str === undefined ? '' : str + ' ') + String(value)) |
| 25 | + return value |
| 26 | + } |
27 | 27 |
|
28 | | - this.ctx = createContext(Chapter.SOURCE_4, Variant.DEFAULT, undefined, [], undefined, { |
29 | | - rawDisplay: rawDisplay, |
30 | | - prompt: rawDisplay, |
31 | | - alert: rawDisplay, |
32 | | - visualiseList: (_v: Value) => { |
33 | | - throw new Error('List visualizer is not enabled') |
34 | | - } |
35 | | - }); |
| 28 | + this.ctx = createContext(Chapter.SOURCE_4, Variant.DEFAULT, undefined, [], undefined, { |
| 29 | + rawDisplay: rawDisplay, |
| 30 | + prompt: rawDisplay, |
| 31 | + alert: rawDisplay, |
| 32 | + visualiseList: (_v: Value) => { |
| 33 | + throw new Error('List visualizer is not enabled') |
| 34 | + } |
| 35 | + }) |
36 | 36 |
|
37 | | - console.log("Evaluator initialised!"); |
38 | | - } |
| 37 | + console.log('Evaluator initialised!') |
| 38 | + } |
39 | 39 | } |
40 | 40 |
|
41 | | -initialise(JsSlangEvaluator); |
| 41 | +initialise(JsSlangEvaluator) |
0 commit comments