getmore2.go 952 B

12345678910111213141516171819202122232425
  1. // getMoreInput does I/O: it is called by the Parser routines mid-parse to get the user's next line
  2. func (p *Parser) getMoreInput(deliverThese []Sexp, errorToReport error) error {
  3. if len(deliverThese) == 0 && errorToReport == nil {
  4. p.FlagSendNeedInput = true
  5. } else {
  6. p.sendMe = append(p.sendMe,ParserReply{Expr: deliverThese,Err: errorToReport})
  7. }
  8. for {
  9. select {
  10. case <-p.reqStop:
  11. return ParserHaltRequested
  12. case input := <-p.AddInput:
  13. p.lexer.AddNextStream(input)
  14. p.FlagSendNeedInput = false
  15. return nil
  16. case input := <-p.ReqReset:
  17. p.lexer.Reset()
  18. p.lexer.AddNextStream(input)
  19. p.FlagSendNeedInput = false
  20. return ResetRequested
  21. case p.HaveStuffToSend() <- p.sendMe: // a conditional send!
  22. p.sendMe = make([]ParserReply, 0, 1)
  23. p.FlagSendNeedInput = false
  24. }}}