diff options
| author | Bobby <[email protected]> | 2024-02-07 21:54:42 +0000 |
|---|---|---|
| committer | Bobby <[email protected]> | 2024-02-07 21:54:42 +0000 |
| commit | b3d5ef5c6c3dcb6d1bf707b82e5350168d66d6c5 (patch) | |
| tree | c7152d84e510c822f24b61610fa8c4c7f3c37bce /repl | |
| parent | ee1a97c282989a4c84a217991886a915abee5d3b (diff) | |
| download | mana-b3d5ef5c6c3dcb6d1bf707b82e5350168d66d6c5.tar.xz mana-b3d5ef5c6c3dcb6d1bf707b82e5350168d66d6c5.zip | |
Mana RPPL
Diffstat (limited to 'repl')
| -rw-r--r-- | repl/repl.go | 31 |
1 files changed, 27 insertions, 4 deletions
diff --git a/repl/repl.go b/repl/repl.go index 04bff57..9db9683 100644 --- a/repl/repl.go +++ b/repl/repl.go @@ -5,14 +5,23 @@ import ( "fmt" "io" "mana/lexer" - "mana/tokens" + "mana/parser" ) // PROMPT is the prompt for the REPL. -const PROMPT = "=> " +const PROMPT = ">>> " +const MANA_ICON = ` +███╗░░░███╗░█████╗░███╗░░██╗░█████╗░ +████╗░████║██╔══██╗████╗░██║██╔══██╗ +██╔████╔██║███████║██╔██╗██║███████║ +██║╚██╔╝██║██╔══██║██║╚████║██╔══██║ +██║░╚═╝░██║██║░░██║██║░╚███║██║░░██║ +╚═╝░░░░░╚═╝╚═╝░░╚═╝╚═╝░░╚══╝╚═╝░░╚═╝ +` func Start(in io.Reader, out io.Writer) { var scanner *bufio.Scanner = bufio.NewScanner(in) + io.WriteString(out, MANA_ICON + "\n") for { fmt.Fprint(out, PROMPT) @@ -24,9 +33,23 @@ func Start(in io.Reader, out io.Writer) { var line string = scanner.Text() var l *lexer.Lexer = lexer.New(line) + var p *parser.Parser = parser.New(l) - for tok := l.NextToken(); tok.Type != tokens.EOF; tok = l.NextToken() { - fmt.Fprintf(out, "%+v\n", tok) + var program = p.ParseProgram() + + if len(p.Errors()) != 0 { + printParserErrors(out, p.Errors()) + continue } + + io.WriteString(out, program.String()) + io.WriteString(out, "\n") + } +} + +func printParserErrors(out io.Writer, errors []string) { + io.WriteString(out, "Mana Encountered Parser Errors:\n") + for _, msg := range errors { + io.WriteString(out, "\t" + msg + "\n") } } |
