Skip to content

Commit 38840e1

Browse files
authored
🚀 implement repl (#17)
1 parent 19fd0fe commit 38840e1

File tree

1 file changed

+46
-0
lines changed

1 file changed

+46
-0
lines changed

cmd/repl/main.go

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
package main
2+
3+
import (
4+
"bufio"
5+
"fmt"
6+
"os"
7+
"os/user"
8+
9+
"github.com/okazaki-kk/miniDB/internal/parser"
10+
"github.com/okazaki-kk/miniDB/internal/parser/lexer"
11+
)
12+
13+
const PROMPT = "miniDB >>"
14+
15+
func main() {
16+
user, err := user.Current()
17+
if err != nil {
18+
panic(err)
19+
}
20+
fmt.Println("Hello " + user.Name + "!")
21+
fmt.Println("This is the miniDB!")
22+
fmt.Println("Feel free to type in commands")
23+
Start()
24+
}
25+
26+
func Start() {
27+
scanner := bufio.NewScanner(os.Stdin)
28+
29+
for {
30+
fmt.Print(PROMPT)
31+
scanned := scanner.Scan()
32+
if !scanned {
33+
return
34+
}
35+
36+
line := scanner.Text()
37+
p := parser.New(lexer.New(line))
38+
stmts, err := p.Parse()
39+
40+
if err != nil {
41+
fmt.Println(err)
42+
continue
43+
}
44+
fmt.Println(stmts)
45+
}
46+
}

0 commit comments

Comments
 (0)