2022-05-12 17:38:47 -05:00
|
|
|
package repl
|
|
|
|
|
|
|
|
import (
|
|
|
|
"bufio"
|
|
|
|
"fmt"
|
|
|
|
"io"
|
|
|
|
|
|
|
|
"monkey/lexer"
|
|
|
|
"monkey/token"
|
|
|
|
)
|
|
|
|
|
|
|
|
const PROMPT = ">> "
|
|
|
|
|
|
|
|
func Start(in io.Reader, out io.Writer) {
|
|
|
|
scanner := bufio.NewScanner(in)
|
|
|
|
|
|
|
|
for {
|
|
|
|
fmt.Fprintf(out, 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.Fprintf(out, "%+v\n", tok)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|