aboutsummaryrefslogblamecommitdiff
path: root/users/fcuny/exp/monkey/pkg/repl/repl.go
blob: e8b3b1f9f61f1b6666c957505e49956c2ec030cb (plain) (tree)




























                                                                                      
package repl

import (
	"bufio"
	"fmt"
	"io"
	lexer "monkey/pkg/lexer"
	token "monkey/pkg/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)
		}
	}
}