summaryrefslogtreecommitdiff
path: root/repl/repl.odin
blob: bb4a1b2fb5a4bae232f92fa7c3fe11201ac7f662 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
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)
		}
	}
}