12345678910111213141516171819202122232425262728293031323334 |
- package repl
- import (
- "bufio"
- "fmt"
- "io"
- "code.osinet.fr/fgm/waiig15/lexer"
- "code.osinet.fr/fgm/waiig15/token"
- )
- // PROMPT is the prompt shown to the user of the REPL to invite them to type
- // some code.
- const PROMPT = ">> "
- // Start implements the Read-Eval-Print Loop.
- func Start(in io.Reader, out io.Writer) {
- scanner := bufio.NewScanner(in)
- for {
- fmt.Print(PROMPT)
- scanned := scanner.Scan()
- if !scanned {
- return
- }
- line := scanner.Text()
- l := lexer.New(line)
- for tok := l.NextToken(); tok.Type != token.EOF; tok = l.NextToken() {
- fmt.Printf("%+v\n", tok)
- }
- }
- }
|