orig.parser1.go 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. // (original straight-line code:) parseArray handles `[2, 4, 5, "six"]` arrays of expressions
  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. return nil, io.EOF // <<<<<<<<<<<<< sad, done before finding ']'
  19. }
  20. }
  21. if tok.typ == TokenRSquare {
  22. // pop off the ]
  23. _, _ = parser.lexer.getNextToken()
  24. break
  25. }
  26. expr, err := parser.parseExpression(depth + 1)
  27. if err != nil {
  28. return SexpNull, err
  29. }
  30. arr = append(arr, expr)
  31. }
  32. return &SexpArray{Val: arr, Env: parser.env}, nil
  33. }