-
Notifications
You must be signed in to change notification settings - Fork 1
/
pimacs.go
62 lines (52 loc) · 983 Bytes
/
pimacs.go
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
package main
import (
"bufio"
"flag"
"fmt"
"github.com/federicotdn/pimacs/core"
"github.com/federicotdn/pimacs/ui/tui"
"os"
"strings"
)
func repl() {
interpreter, err := core.NewInterpreterDefault()
if err != nil {
panic(err)
}
for {
reader := bufio.NewReader(os.Stdin)
eval := true
fmt.Print("> ")
source, _ := reader.ReadString('\n')
source = strings.TrimRight(source, "\r\n")
if source == "" {
break
} else if source[0] == '|' {
eval = false
source = source[1:]
fmt.Println("[input will not be evaluated]")
}
var printed string
var err error
if eval {
printed, err = interpreter.ReadEvalPrin1(source)
} else {
printed, err = interpreter.ReadPrin1(source)
}
if err != nil {
fmt.Println("repl error:", err)
} else {
fmt.Println(printed)
}
}
}
func main() {
var useTui bool
flag.BoolVar(&useTui, "tui", false, "start Pimacs in TUI mode")
flag.Parse()
if useTui {
tui.Run()
} else {
repl()
}
}