Init commit

This commit is contained in:
Raphaël Forment
2023-07-28 01:23:38 +02:00
committed by GitHub
parent c34ee20306
commit aff5e643ac
20 changed files with 3848 additions and 0 deletions

31
src/Evaluator.ts Normal file
View File

@ -0,0 +1,31 @@
import type { Editor } from './main';
import type { File } from './AppSettings';
/* This mode of evaluation can only work if the whole buffer is evaluated at once */
export const tryEvaluate = (application: Editor, code: File): void => {
let isValidCode: boolean;
try {
Function(`with (this) {try{${code.candidate}} catch (e) {console.log(e)}};`).call(application.api)
code.evaluations++;
isValidCode = true;
} catch (error) {
Function(`with (this) {try{${code.committed}} catch (e) {console.log(e)}};`).call(application.api)
code.evaluations++;
isValidCode = false;
}
if (isValidCode) {
code.committed = code.candidate;
} else {
evaluate(application, code);
}
}
export const evaluate = (application: Editor, code: File): void => {
Function(`with (this) {try{${code.committed}} catch (e) {console.log(e)}};`).call(application.api)
code.evaluations++;
}
export const evaluateCommand = (application: Editor, command: string): void => {
Function(`with (this) {try{${command}} catch (e) {console.log(e)}};`).call(application.api)
}