27 lines
463 B
Go
27 lines
463 B
Go
|
|
package repl
|
||
|
|
|
||
|
|
import (
|
||
|
|
"bufio"
|
||
|
|
"fmt"
|
||
|
|
"io"
|
||
|
|
|
||
|
|
"code.jmug.me/jmug/interpreter-in-go/pkg/lexer"
|
||
|
|
"code.jmug.me/jmug/interpreter-in-go/pkg/token"
|
||
|
|
)
|
||
|
|
|
||
|
|
const PROMPT = ">> "
|
||
|
|
|
||
|
|
func Start(in io.Reader, out io.Writer) {
|
||
|
|
scanner := bufio.NewScanner(in)
|
||
|
|
for {
|
||
|
|
fmt.Fprint(out, PROMPT)
|
||
|
|
if !scanner.Scan() {
|
||
|
|
return
|
||
|
|
}
|
||
|
|
l := lexer.New(scanner.Text())
|
||
|
|
for tok := l.NextToken(); tok.Type != token.EOF; tok = l.NextToken() {
|
||
|
|
fmt.Fprintf(out, "%+v\n", tok)
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|