* parse the matrix * @return {Node} node * @private
(state)
| 1594 | * @private |
| 1595 | */ |
| 1596 | function parseMatrix (state) { |
| 1597 | let array, params, rows, cols |
| 1598 | |
| 1599 | if (state.token === '[') { |
| 1600 | // matrix [...] |
| 1601 | openParams(state) |
| 1602 | getToken(state) |
| 1603 | |
| 1604 | if (state.token !== ']') { |
| 1605 | // this is a non-empty matrix |
| 1606 | const row = parseRow(state) |
| 1607 | |
| 1608 | if (state.token === ';') { |
| 1609 | // 2 dimensional array |
| 1610 | rows = 1 |
| 1611 | params = [row] |
| 1612 | |
| 1613 | // the rows of the matrix are separated by dot-comma's |
| 1614 | while (state.token === ';') { // eslint-disable-line no-unmodified-loop-condition |
| 1615 | getToken(state) |
| 1616 | |
| 1617 | if (state.token !== ']') { |
| 1618 | params[rows] = parseRow(state) |
| 1619 | rows++ |
| 1620 | } |
| 1621 | } |
| 1622 | |
| 1623 | if (state.token !== ']') { |
| 1624 | throw createSyntaxError(state, 'End of matrix ] expected') |
| 1625 | } |
| 1626 | closeParams(state) |
| 1627 | getToken(state) |
| 1628 | |
| 1629 | // check if the number of columns matches in all rows |
| 1630 | cols = params[0].items.length |
| 1631 | for (let r = 1; r < rows; r++) { |
| 1632 | if (params[r].items.length !== cols) { |
| 1633 | throw createError(state, 'Column dimensions mismatch ' + |
| 1634 | '(' + params[r].items.length + ' !== ' + cols + ')') |
| 1635 | } |
| 1636 | } |
| 1637 | |
| 1638 | array = new ArrayNode(params) |
| 1639 | } else { |
| 1640 | // 1 dimensional vector |
| 1641 | if (state.token !== ']') { |
| 1642 | throw createSyntaxError(state, 'End of matrix ] expected') |
| 1643 | } |
| 1644 | closeParams(state) |
| 1645 | getToken(state) |
| 1646 | |
| 1647 | array = row |
| 1648 | } |
| 1649 | } else { |
| 1650 | // this is an empty matrix "[ ]" |
| 1651 | closeParams(state) |
| 1652 | getToken(state) |
| 1653 | array = new ArrayNode([]) |
no test coverage detected
searching dependent graphs…