diff options
Diffstat (limited to 'users/fcuny/exp/monkey/pkg/repl')
-rw-r--r-- | users/fcuny/exp/monkey/pkg/repl/repl.go | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/users/fcuny/exp/monkey/pkg/repl/repl.go b/users/fcuny/exp/monkey/pkg/repl/repl.go new file mode 100644 index 0000000..e8b3b1f --- /dev/null +++ b/users/fcuny/exp/monkey/pkg/repl/repl.go @@ -0,0 +1,29 @@ +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) + } + } +} |