about summary refs log tree commit diff
path: root/users/fcuny/exp/monkey/pkg/repl
diff options
context:
space:
mode:
authorFranck Cuny <franck@fcuny.net>2022-05-29 09:57:07 -0700
committerFranck Cuny <franck@fcuny.net>2022-05-29 09:57:07 -0700
commitd284191a8b1ed3aad31583709fddcca1049b30aa (patch)
treee2663f93b1ded9fe949169433ec6d9ea68235665 /users/fcuny/exp/monkey/pkg/repl
parenttools(govanity): add the tool to flake.nix (diff)
parentreadme: convert to org-mode (diff)
downloadworld-d284191a8b1ed3aad31583709fddcca1049b30aa.tar.gz
Merge remote-tracking branch 'monkey/master'
Change-Id: I790690b0877ae309d1d5feb5150f136085e78206
Diffstat (limited to '')
-rw-r--r--users/fcuny/exp/monkey/pkg/repl/repl.go30
1 files changed, 30 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..5e7b1d1
--- /dev/null
+++ b/users/fcuny/exp/monkey/pkg/repl/repl.go
@@ -0,0 +1,30 @@
+// Package repl provides a REPL to the monkey language.
+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.Print(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)
+		}
+	}
+}