after1full.go 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. // AFTER in context
  2. func (parser *Parser) parseArray(depth int) (Sexp, error) {
  3. for { // get the next token, then break
  4. getTok:
  5. for {
  6. tok, err = parser.lexer.peekNextToken()
  7. if err != nil {
  8. return SexpEnd, err
  9. }
  10. if tok.typ == TokenComma {
  11. // pop off the ,
  12. _, _ = parser.lexer.getNextToken()
  13. continue getTok
  14. }
  15. if tok.typ != TokenEnd {
  16. break getTok // got a token
  17. } else {
  18. // we ask for more, and then loop
  19. err = parser.getMoreInput(nil, ErrMoreInputNeeded) // <<<=== key change
  20. switch err {
  21. case ParserHaltRequested:
  22. return SexpNull, err
  23. case ResetRequested:
  24. return SexpEnd, err
  25. }
  26. }
  27. }
  28. if tok.typ == TokenRSquare {
  29. // pop off the ]
  30. _, _ = parser.lexer.getNextToken()
  31. break
  32. }
  33. expr, err := parser.parseExpression(depth + 1)
  34. if err != nil {
  35. return SexpNull, err
  36. }
  37. arr = append(arr, expr)
  38. }
  39. return &SexpArray{Val: arr, Env: parser.env}, nil
  40. }