Skip to content

Instantly share code, notes, and snippets.

@tizoc
Created April 10, 2020 15:12
Show Gist options
  • Save tizoc/7c4e7fdf1ae062d511c5bc5198c13de5 to your computer and use it in GitHub Desktop.
Save tizoc/7c4e7fdf1ae062d511c5bc5198c13de5 to your computer and use it in GitHub Desktop.
diff --git a/console.js b/console.js
index 9f026d9..7d5b530 100644
--- a/console.js
+++ b/console.js
@@ -22,7 +22,9 @@ $(async function () {
//console.log(shen.valueOf("shen.*tc*"))
await shen.assign("*history*", 0)
await shen.exec("(define runsh Parsed -> (trap-error (shen.toplevel (read-from-string Parsed)) (/. E (shen.toplevel-display-exception E))))")
+ await shen.exec("(define input-parses? Str -> (let Chars (map (function string->n) (explode Str)) Parsed (compile (/. X (shen.<st_input> X)) Chars (/. E $$$input-incomplete)) (shen-script.boolean.shen->js (not (= Parsed $$$input-incomplete)))))")
let evalShen = await shen.caller("runsh")
+ let inputParses = await shen.caller("input-parses?")
jqconsole.Write("Welcome to the ShenScript REPL!\nThe <div> on the right is available under the id workspace.\n\n", 'jqconsole-output')
await shen.exec('(do (shen.initialise_environment) (shen.credits))')
@@ -35,7 +37,16 @@ $(async function () {
evalShen(input)
await shen.exec("(set *history* (+ (value *history*) 1))")
startPrompt();
- });
+ }, async (input, next) => {
+ if (input.trim() === "") { return next(0) }
+ const result = await inputParses(input)
+ if (result) {
+ return next(false)
+ } else {
+ return next(0)
+ }
+ },
+ true);
};
startPrompt();
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment