aboutsummaryrefslogtreecommitdiff
path: root/repl/repl.go
blob: 0002a8930104570c1c46636b7c27f08dfb5175f0 (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
31
32
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) {
	var scanner *bufio.Scanner = bufio.NewScanner(in)

	for {
		fmt.Fprint(out, PROMPT)
		var scanned bool = scanner.Scan()
		
		if !scanned {
			return
		}

		var line string = scanner.Text()
		var l *lexer.Lexer = lexer.New(line)

		for tok := l.NextToken(); tok.Type != tokens.EOF; tok = l.NextToken() {
			fmt.Fprintf(out, "%+v\n", tok)
		}
	}
}