(95 lines)
1 #!/usr/bin/env nomsu -V7.0.02 ###3 This file defines a Read-Evaluate-Print-Loop (REPL) for Nomsu5 use "consolecolor"6 use "filesystem"7 use "commandline"9 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~11 external:12 (help) means:13 say ("14 This is the Nomsu v\($(NOMSU VERSION), joined with ".") interactive console.15 You can type in Nomsu code here and hit 'enter' twice to run it.16 To exit, type 'exit' or 'quit' and hit enter twice.17 ")19 (tutorial) means:20 (use "tools/tutorial").run_with {.extras = []}21 exit23 command line program with $args:24 say ("26 \(bright)\(underscore)Welcome to the Nomsu v\($(NOMSU VERSION), joined with ".") interactive console!\27 ..\(reset color)28 press 'enter' twice to run a command29 type 'tutorial' to run the tutorial31 ")33 ### Best way I know of to detect the number of return values and only34 print if it's >0:35 (say results of (*extra arguments*)) means:36 $N = (select "#" (*extra arguments*))37 if ($N == 0): return38 for $ in (1 to $N):39 $ret = (select $ (*extra arguments*))40 if ($ret is "Text"):41 $ret = (quote $ret)42 say "\$ret"44 repeat:45 say (bright (yellow ">> ")) inline46 $buff = []47 repeat:48 say (bright) inline49 $line = ($io.read "*L")50 say (reset color) inline51 if (($line == "\n") or (not $line)):52 if (#$buff > 0):53 ### clear the line54 if $(COLOR ENABLED):55 say "\027[1A\027[2K" inline57 go to (run buffer)58 $buff, add ($line, with "\t" -> " ")59 say (dim (yellow ".. ")) inline60 --- (run buffer) ---61 if (#$buff == 0): stop62 $buff = ($buff, joined)63 spoof file $buff64 try:65 $tree = ($buff parsed)66 ..if it fails with $err:67 say $err68 do next70 unless $tree:71 do next73 if ($tree.type == "Comment"):74 say (dim "Comment:\($tree.1)")75 do next77 if ($tree.type != "FileChunks"): $tree = [$tree]78 for $chunk in $tree:79 try:80 $lua = ($chunk as lua)81 ..if it fails with $err: say $err83 unless $lua:84 do next86 ### TODO: this is a bit hacky, it just defaults variables to global87 so that stuff mostly works across multiple lines. It would be88 nicer if local variables actually worked.89 $lua, remove free vars90 if (load "return \($lua, text)"):91 $lua, prepend "return "93 try:94 say results of (run $lua)95 ..if it fails with $err: say $err