aboutsummaryrefslogtreecommitdiff
path: root/repl
diff options
context:
space:
mode:
authorBobby <[email protected]>2023-10-29 16:44:23 -0400
committerBobby <[email protected]>2023-10-29 16:44:23 -0400
commite2049d8b44ac97d3a47f8de8ad89f473214938d1 (patch)
tree9cd66fd87ce50b73c8617f2fc8a53f484f484232 /repl
parentabb94bc7da02ac69ade9a747a8a205741c96d35b (diff)
downloadmana-e2049d8b44ac97d3a47f8de8ad89f473214938d1.tar.xz
mana-e2049d8b44ac97d3a47f8de8ad89f473214938d1.zip
Added REPL and main function
Diffstat (limited to 'repl')
-rw-r--r--repl/repl.go33
1 files changed, 32 insertions, 1 deletions
diff --git a/repl/repl.go b/repl/repl.go
index 9119db8..37acd49 100644
--- a/repl/repl.go
+++ b/repl/repl.go
@@ -1 +1,32 @@
-package repl \ No newline at end of file
+package repl
+
+import (
+ "bufio"
+ "fmt"
+ "io"
+ "mana/lexer"
+ "mana/tokens"
+)
+
+// PROMPT is the prompt for the REPL.
+const PROMPT = "=> "
+
+func Start(in io.Reader, out io.Writer) {
+ scanner := bufio.NewScanner(in)
+
+ for {
+ fmt.Fprint(out, PROMPT)
+ scanned := scanner.Scan()
+
+ if !scanned {
+ return
+ }
+
+ line := scanner.Text()
+ l := lexer.New(line)
+
+ for tok := l.NextToken(); tok.Type != tokens.EOF; tok = l.NextToken() {
+ fmt.Fprintf(out, "%+v\n", tok)
+ }
+ }
+}