()
| 1542 | return new ast.List(elts); |
| 1543 | } |
| 1544 | _parseSlice() { |
| 1545 | const elts = []; |
| 1546 | let slice = [null, null, null]; |
| 1547 | let index = 0; |
| 1548 | let valid = false; |
| 1549 | this._tokenizer.expect('['); |
| 1550 | while (true) { |
| 1551 | if (this._tokenizer.accept(':')) { |
| 1552 | index++; |
| 1553 | valid = true; |
| 1554 | } else if (index > 2 || this._tokenizer.match(',') || this._tokenizer.match(']')) { |
| 1555 | if (!valid || index > 2) { |
| 1556 | throw new python.Error(`Invalid slice at ${this._location()}`); |
| 1557 | } |
| 1558 | elts.push(index === 0 ? slice[0] : new ast.Slice(slice[0], slice[1], slice[2])); |
| 1559 | slice = [null, null, null]; |
| 1560 | index = 0; |
| 1561 | if (this._tokenizer.accept(']')) { |
| 1562 | break; |
| 1563 | } |
| 1564 | this._tokenizer.expect(','); |
| 1565 | } else { |
| 1566 | const expression = this._parseExpression(); |
| 1567 | if (expression === null) { |
| 1568 | throw new python.Error(`Expected expression ${this._location()}`); |
| 1569 | } |
| 1570 | slice[index] = expression; |
| 1571 | valid = true; |
| 1572 | } |
| 1573 | } |
| 1574 | if (elts.length > 1) { |
| 1575 | return new ast.Tuple(elts); |
| 1576 | } |
| 1577 | return elts[0]; |
| 1578 | } |
| 1579 | _parseName(required) { |
| 1580 | const token = this._tokenizer.peek(); |
| 1581 | if (token.type === 'id' && !token.keyword) { |
no test coverage detected