monkey/repl/repl.go
Tyrel Souza b8d8e30f0f REPL
2021-11-30 16:21:32 -05:00

32 lines
459 B
Go

package repl
import (
"bufio"
"fmt"
"io"
"gitlab.com/Tyrel/monkey/lexer"
"gitlab.com/Tyrel/monkey/token"
)
const PROMPT = ">> "
func Start(in io.Reader, out io.Writer) {
scanner := bufio.NewScanner(in)
for {
fmt.Printf(PROMPT)
scanned := scanner.Scan()
if !scanned {
return
}
line := scanner.Text()
l := lexer.New(line)
for tok := l.NextToken(); tok.Type != token.EOF; tok = l.NextToken() {
fmt.Printf("%+v\n", tok)
}
}
}