46 lines
853 B
Go
46 lines
853 B
Go
package repl
|
|
|
|
import (
|
|
"fmt"
|
|
"strings"
|
|
|
|
. "godb/internals/buffer"
|
|
. "godb/internals/vm"
|
|
)
|
|
|
|
func PrintConsole() {
|
|
fmt.Print("godb > ")
|
|
}
|
|
|
|
func Run() {
|
|
|
|
inputBuffer := NewInputBuffer()
|
|
statement := NewStatement()
|
|
table := NewTable()
|
|
for {
|
|
PrintConsole()
|
|
inputBuffer.ReadConsole()
|
|
if len(inputBuffer.Buffer) > 0 && strings.HasPrefix(inputBuffer.Buffer, ".") {
|
|
switch DoMetaCommands(inputBuffer) {
|
|
case MetaCommandSuccess:
|
|
continue
|
|
case MetaCommandUnrecognised:
|
|
fmt.Printf("unrecognised command %v\n", inputBuffer.Buffer)
|
|
continue
|
|
}
|
|
}
|
|
|
|
switch statement.PrepareStatements(inputBuffer) {
|
|
case PrepareSuccess:
|
|
//todo
|
|
case PrepareUnrecognised:
|
|
fmt.Printf("Unrecognised keyword at the start of '%s'.\n", inputBuffer.Buffer)
|
|
continue
|
|
}
|
|
|
|
statement.ExecuteStatement(table)
|
|
fmt.Println("Executed")
|
|
|
|
}
|
|
}
|