-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathio.go
60 lines (58 loc) · 1.01 KB
/
io.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
package lisp
import (
"bufio"
"fmt"
"os"
)
func init() {
Add("scan", func(t []Token, p *Lisp) (Token, error) {
if len(t) != 0 {
return None, ErrParaNum
}
buf := bufio.NewReader(os.Stdin)
one := section{}
for {
data, err := buf.ReadBytes('\n')
if err != nil {
return None, err
}
err = one.feed(data)
if err != nil {
return None, err
}
if one.over() {
break
}
}
return p.Eval([]byte(one.total))
})
Add("load", func(t []Token, p *Lisp) (Token, error) {
if len(t) != 1 {
return None, ErrParaNum
}
if t[0].Kind != String {
return None, ErrFitType
}
return p.Load(t[0].Text.(string))
})
Add("print", func(t []Token, p *Lisp) (x Token, y error) {
for _, i := range t {
x, y = p.Exec(i)
if y != nil {
return None, y
}
fmt.Print(x)
}
return x, nil
})
Add("println", func(t []Token, p *Lisp) (x Token, y error) {
for _, i := range t {
x, y = p.Exec(i)
if y != nil {
return None, y
}
fmt.Println(x)
}
return x, nil
})
}