monna/repl/repl.go
tijani ee8ab63809 Rename new -> New and next_token -> NextToken, because of go's weird requirement that first letter
of public methods in a package that would be used in another package must be capitalized.

git-svn-id: https://svn.tlawal.org/svn/monkey@4 f6afcba9-9ef1-4bdd-9b72-7484f5705bac
2022-05-12 22:38:47 +00:00

32 lines
437 B
Go

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)
}
}
}