summaryrefslogtreecommitdiff
path: root/repl
diff options
context:
space:
mode:
Diffstat (limited to 'repl')
-rw-r--r--repl/repl.odin30
1 files changed, 30 insertions, 0 deletions
diff --git a/repl/repl.odin b/repl/repl.odin
new file mode 100644
index 0000000..bb4a1b2
--- /dev/null
+++ b/repl/repl.odin
@@ -0,0 +1,30 @@
+package repl
+
+import "../lexer"
+import "../token"
+import "core:bufio"
+import "core:fmt"
+import "core:io"
+
+PROMPT :: ">> "
+
+start :: proc(r: io.Reader, w: io.Writer) {
+ s := bufio.scanner_init(&bufio.Scanner{}, r)
+ defer bufio.scanner_destroy(s)
+
+ for {
+ fmt.wprintf(w, PROMPT)
+ scanned := bufio.scan(s)
+ if !scanned {
+ return
+ }
+
+ line := bufio.scanner_text(s)
+ l := lexer.new(line)
+
+ eof: token.EOF
+ for tok := lexer.next_token(&l); tok != eof; tok = lexer.next_token(&l) {
+ fmt.wprintf(w, "%v\n", tok)
+ }
+ }
+}