* parse range, "start:end", "start:step:end", ":", "start:", ":end", etc * @return {Node} node * @private
(state)
| 977 | * @private |
| 978 | */ |
| 979 | function parseRange (state) { |
| 980 | let node |
| 981 | const params = [] |
| 982 | |
| 983 | if (state.token === ':') { |
| 984 | if (state.conditionalLevel === state.nestingLevel) { |
| 985 | // we are in the midst of parsing a conditional operator, so not |
| 986 | // a range, but rather an empty true-expr, which is considered a |
| 987 | // syntax error |
| 988 | throw createSyntaxError( |
| 989 | state, |
| 990 | 'The true-expression of a conditional operator may not be empty') |
| 991 | } else { |
| 992 | // implicit start of range = 1 (one-based) |
| 993 | node = new ConstantNode(1) |
| 994 | } |
| 995 | } else { |
| 996 | // explicit start |
| 997 | node = parseAddSubtract(state) |
| 998 | } |
| 999 | |
| 1000 | if (state.token === ':' && (state.conditionalLevel !== state.nestingLevel)) { |
| 1001 | // we ignore the range operator when a conditional operator is being processed on the same level |
| 1002 | params.push(node) |
| 1003 | |
| 1004 | // parse step and end |
| 1005 | while (state.token === ':' && params.length < 3) { // eslint-disable-line no-unmodified-loop-condition |
| 1006 | getTokenSkipNewline(state) |
| 1007 | |
| 1008 | if (state.token === ')' || state.token === ']' || state.token === ',' || state.token === '') { |
| 1009 | // implicit end |
| 1010 | params.push(new SymbolNode('end')) |
| 1011 | } else { |
| 1012 | // explicit end |
| 1013 | params.push(parseAddSubtract(state)) |
| 1014 | } |
| 1015 | } |
| 1016 | |
| 1017 | if (params.length === 3) { |
| 1018 | // params = [start, step, end] |
| 1019 | node = new RangeNode(params[0], params[2], params[1]) // start, end, step |
| 1020 | } else { // length === 2 |
| 1021 | // params = [start, end] |
| 1022 | node = new RangeNode(params[0], params[1]) // start, end |
| 1023 | } |
| 1024 | } |
| 1025 | |
| 1026 | return node |
| 1027 | } |
| 1028 | |
| 1029 | /** |
| 1030 | * add or subtract |
no test coverage detected
searching dependent graphs…