diff options
| author | Bobby <[email protected]> | 2023-10-29 16:44:23 -0400 |
|---|---|---|
| committer | Bobby <[email protected]> | 2023-10-29 16:44:23 -0400 |
| commit | e2049d8b44ac97d3a47f8de8ad89f473214938d1 (patch) | |
| tree | 9cd66fd87ce50b73c8617f2fc8a53f484f484232 /repl/repl.go | |
| parent | abb94bc7da02ac69ade9a747a8a205741c96d35b (diff) | |
| download | mana-e2049d8b44ac97d3a47f8de8ad89f473214938d1.tar.xz mana-e2049d8b44ac97d3a47f8de8ad89f473214938d1.zip | |
Added REPL and main function
Diffstat (limited to 'repl/repl.go')
| -rw-r--r-- | repl/repl.go | 33 |
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) + } + } +} |
