diff options
| author | Ibrahim Muftee <ibrahim@muftee.net> | 2026-07-14 22:18:38 -0500 |
|---|---|---|
| committer | Ibrahim Muftee <ibrahim@muftee.net> | 2026-07-14 22:21:59 -0500 |
| commit | baa37871d9b71d3f94cc8acca8d375ee1232d7f0 (patch) | |
| tree | d74f48479d28380fb2f53cb61c91727d0b6632ec /repl | |
chapter 01
Diffstat (limited to 'repl')
| -rw-r--r-- | repl/repl.odin | 30 |
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) + } + } +} |
