repl.go 463 B

123456789101112131415161718192021222324252627282930
  1. package repl
  2. import (
  3. "bufio"
  4. "code.osinet.fr/fgm/waiig15/lexer"
  5. "code.osinet.fr/fgm/waiig15/token"
  6. "fmt"
  7. "io"
  8. )
  9. const PROMPT = ">> "
  10. func Start(in io.Reader, out io.Writer) {
  11. scanner := bufio.NewScanner(in)
  12. for {
  13. fmt.Print(PROMPT)
  14. scanned := scanner.Scan()
  15. if !scanned {
  16. return
  17. }
  18. line := scanner.Text()
  19. l := lexer.New(line)
  20. for tok := l.NextToken(); tok.Type != token.EOF; tok = l.NextToken() {
  21. fmt.Printf("%+v\n", tok)
  22. }
  23. }
  24. }