2026-07-19 23:33:02 +05:30
|
|
|
package repl
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"fmt"
|
|
|
|
|
"strings"
|
2026-07-20 00:32:34 +05:30
|
|
|
|
|
|
|
|
. "godb/internals/buffer"
|
|
|
|
|
. "godb/internals/vm"
|
2026-07-19 23:33:02 +05:30
|
|
|
)
|
|
|
|
|
|
|
|
|
|
func PrintConsole() {
|
|
|
|
|
fmt.Print("godb > ")
|
|
|
|
|
}
|
|
|
|
|
|
2026-07-20 00:32:34 +05:30
|
|
|
func Run() {
|
|
|
|
|
|
|
|
|
|
inputBuffer := NewInputBuffer()
|
|
|
|
|
statement := NewStatement()
|
2026-07-21 23:22:15 +05:30
|
|
|
table := NewTable()
|
2026-07-20 00:32:34 +05:30
|
|
|
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
|
|
|
|
|
}
|
|
|
|
|
|
2026-07-22 01:46:52 +05:30
|
|
|
switch statement.ExecuteStatement(table) {
|
|
|
|
|
case ExecuteSuccess:
|
|
|
|
|
fmt.Println("Executed.")
|
|
|
|
|
case ExecuteTableFull:
|
|
|
|
|
fmt.Println("Error: Table is full")
|
|
|
|
|
}
|
2026-07-20 00:32:34 +05:30
|
|
|
|
2026-07-19 23:33:02 +05:30
|
|
|
}
|
|
|
|
|
}
|