aboutsummaryrefslogtreecommitdiff
path: root/tools/repl.nom
blob: 6197074679096671f5ad1ed84ee84aae4d3fbe21 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#!/usr/bin/env nomsu -V4.10.12.7
#
    This file defines a Read-Evaluate-Print-Loop (REPL) for Nomsu

use "lib/consolecolor.nom"
use "lib/os.nom"

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

externally [quit, exit] all mean: lua> "os.exit(0)"
externally (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"