( parseMapper: ParseMapper, tokens: SplootNode[], currentIndex: number )
| 79 | } |
| 80 | |
| 81 | function parseLeafToPyright( |
| 82 | parseMapper: ParseMapper, |
| 83 | tokens: SplootNode[], |
| 84 | currentIndex: number |
| 85 | ): [boolean, number, ExpressionNode] { |
| 86 | if (currentIndex >= tokens.length) { |
| 87 | // No tokens left when a leaf was expected |
| 88 | const errorExpr: ErrorNode = { |
| 89 | nodeType: ParseNodeType.Error, |
| 90 | category: ErrorExpressionCategory.MissingExpression, |
| 91 | id: parseMapper.getNextId(), |
| 92 | start: 0, |
| 93 | length: 0, |
| 94 | } |
| 95 | return [false, currentIndex, errorExpr] |
| 96 | } |
| 97 | const lookahead = tokens[currentIndex] |
| 98 | if (lookahead.type === 'PYTHON_BINARY_OPERATOR') { |
| 99 | const op = (lookahead as PythonBinaryOperator).getOperator() |
| 100 | if (op in UnaryOperators) { |
| 101 | // Don't care if it's invalid, it'll return an error node if needed |
| 102 | const [, leafIndex, operandNode] = parseLeafToPyright(parseMapper, tokens, currentIndex + 1) |
| 103 | const lhs: UnaryOperationNode = { |
| 104 | nodeType: ParseNodeType.UnaryOperation, |
| 105 | expression: operandNode, |
| 106 | id: parseMapper.getNextId(), |
| 107 | length: 0, |
| 108 | start: 0, |
| 109 | operator: UnaryOperators[op].type, |
| 110 | operatorToken: { start: 0, length: 0, type: UnaryOperators[op].tokenType }, |
| 111 | } |
| 112 | operandNode.parent = lhs |
| 113 | return parseExpressionToPyright(parseMapper, tokens, lhs, leafIndex, UnaryOperators[op]['precedence']) |
| 114 | } |
| 115 | const errorExpr: ErrorNode = { |
| 116 | nodeType: ParseNodeType.Error, |
| 117 | category: ErrorExpressionCategory.MissingExpression, |
| 118 | id: parseMapper.getNextId(), |
| 119 | start: 0, |
| 120 | length: 0, |
| 121 | } |
| 122 | return [false, currentIndex, errorExpr] |
| 123 | } |
| 124 | // Consume one token - whatever it was it wasn't an operator |
| 125 | const leafNode = parseTokenToPyright(parseMapper, lookahead) |
| 126 | return [true, currentIndex + 1, leafNode] |
| 127 | } |
| 128 | |
| 129 | function parseExpressionToPyright( |
| 130 | parseMapper: ParseMapper, |
no test coverage detected