(tokens: SplootNode[], currentIndex: number)
| 231 | } |
| 232 | |
| 233 | function parseLeaf(tokens: SplootNode[], currentIndex: number): [boolean, number] { |
| 234 | if (currentIndex >= tokens.length) { |
| 235 | // No tokens left when a leaf was expected |
| 236 | return [false, currentIndex] |
| 237 | } |
| 238 | const lookahead = tokens[currentIndex] |
| 239 | if (lookahead.type === 'PYTHON_BINARY_OPERATOR') { |
| 240 | const op = (lookahead as PythonBinaryOperator).getOperator() |
| 241 | if (op in UnaryOperators) { |
| 242 | const [valid, leafIndex] = parseLeaf(tokens, currentIndex + 1) |
| 243 | if (!valid) { |
| 244 | return [false, leafIndex] |
| 245 | } |
| 246 | return parseExpression(tokens, leafIndex, UnaryOperators[op]['precedence']) |
| 247 | } |
| 248 | return [false, currentIndex] |
| 249 | } |
| 250 | // Consume one token - whatever it was it wasn't an operator |
| 251 | return [true, currentIndex + 1] |
| 252 | } |
| 253 | |
| 254 | function parseExpression(tokens: SplootNode[], currentIndex: number, minPrecedence: number): [boolean, number] { |
| 255 | if (currentIndex >= tokens.length) { |
no test coverage detected