Add REPL boilerplate.

Signed-off-by: jmug <u.g.a.mariano@gmail.com>
This commit is contained in:
Mariano Uvalle 2025-01-02 17:18:00 -08:00
parent dcf5cb336a
commit 04dfd62600
2 changed files with 45 additions and 0 deletions

26
pkg/repl/repl.go Normal file
View file

@ -0,0 +1,26 @@
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)
}
}
}