diff options
| author | Bruce Hill <bruce@bruce-hill.com> | 2018-11-08 15:23:22 -0800 |
|---|---|---|
| committer | Bruce Hill <bruce@bruce-hill.com> | 2018-11-08 15:24:15 -0800 |
| commit | 652c29bdef1f0991cc13bef59d6dc78b657ae9a4 (patch) | |
| tree | 8e335399e77b1893657b9fa985db0738034daac3 /tools/repl.nom | |
| parent | 1f3660f393c1a17988a15b89f18686b28e51a9e7 (diff) | |
Major overhaul, splitting nomsu_compiler into nomsu_environment,
nomsu_compiler, and nomsu_decompiler. Also added comprehensions.
Diffstat (limited to 'tools/repl.nom')
| -rw-r--r-- | tools/repl.nom | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/tools/repl.nom b/tools/repl.nom new file mode 100644 index 0000000..00efd77 --- /dev/null +++ b/tools/repl.nom @@ -0,0 +1,61 @@ +#!/usr/bin/env nomsu -V4 +use "lib/consolecolor.nom" +use "lib/os.nom" + +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +[quit, exit] all mean: lua> "os.exit(0)" + +(help) means: + say "\ + ..This is the Nomsu v\(Nomsu version) interactive console. + You can type in Nomsu code here and hit 'enter' twice to run it. + To exit, type 'exit' or 'quit' and hit enter twice." + +say "\ + .. + \(bright)\(underscore)Welcome to the Nomsu v\(Nomsu version) interactive console!\(reset color) + press 'enter' twice to run a command + " + +%repl_line = 0 +repeat: + %repl_line += 1 + %io.write (bright (yellow ">> ")) + %buff = [] + repeat: + %io.write (bright) + %line = (%io.read "*L") + %io.write (reset color) + if ((%line == "\n") or (not %line)): + if ((size of %buff) > 0): + %io.write "\027[1A\027[2K" + go to (run buffer) + %buff::add (%line::with "\t" -> " ") + %io.write (dim (yellow ".. ")) + + === (run buffer) === + if ((size of %buff) == 0): + stop + + %buff = (%buff::joined) + + # TODO: support local variables + spoof file %buff + try: + %ret = (run %buff) + ..and if it barfs %err: + say %err + ..or if it succeeds: + if (type of %ret) is: + "nil": + do nothing + "boolean": + say "= \("yes" if %ret else "no")" + "table": + if %ret.as_nomsu: + say "= \(%ret::as nomsu)" + ..else: + say "= \%ret" + else: + say "= \%ret" |
