infparse.go 836 B

12345678910111213141516171819202122232425262728293031
  1. func (p *Parser) infiniteParsingLoop() {
  2. defer close(p.Done)
  3. expressions := make([]Sexp, 0, SliceDefaultCap)
  4. for {
  5. expr, err := p.parseExpression(0)
  6. if err != nil || expr == SexpEnd {
  7. if err == ParserHaltRequested {
  8. return
  9. }
  10. // expr == SexpEnd means that parserExpression
  11. // couldn't read another token, so a call to
  12. // getMoreInput() is required.
  13. // provide accumulated expressions
  14. // back to the client here
  15. err = p.getMoreInput(expressions, err)
  16. if err == ParserHaltRequested {
  17. return
  18. }
  19. // getMoreInput() will have delivered
  20. // expressions to the client. Reset expressions since we
  21. // don't own that memory any more.
  22. expressions = make([]Sexp, 0, SliceDefaultCap)
  23. } else {
  24. // INVAR: err == nil && expr is not SexpEnd
  25. expressions = append(expressions, expr)
  26. }
  27. }
  28. }