MCPcopy Index your code
hub / github.com/lutzroeder/netron / _parseSlice

Method _parseSlice

source/python.js:1544–1578  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

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) {

Callers 1

_parseExpressionMethod · 0.80

Calls 6

_parseExpressionMethod · 0.80
expectMethod · 0.45
acceptMethod · 0.45
matchMethod · 0.45
_locationMethod · 0.45
pushMethod · 0.45

Tested by

no test coverage detected