(tokens, currentIndex)
| 137 | |
| 138 | |
| 139 | def parseLeaf(tokens, currentIndex): |
| 140 | if currentIndex >= len(tokens): |
| 141 | print("Index out of bounds, attempting to parse leaf") |
| 142 | return currentIndex |
| 143 | |
| 144 | lookahead = tokens[currentIndex] |
| 145 | if lookahead["type"] == "PYTHON_BINARY_OPERATOR": |
| 146 | op = lookahead["properties"]["operator"] |
| 147 | if op in UNARY_OPERATORS: |
| 148 | # treat RHS as it's own expression, depending on precedence. |
| 149 | lhs, index = parseLeaf(tokens, currentIndex + 1) |
| 150 | top_expr, index = parseExpression( |
| 151 | lhs, tokens, index, getUnaryPrecedence(op) |
| 152 | ) |
| 153 | # Create Unary expression |
| 154 | return [ast.UnaryOp(getAstUnaryOperator(op), top_expr), index] |
| 155 | return [generateAstExpressionToken(tokens[currentIndex]), currentIndex + 1] |
| 156 | |
| 157 | |
| 158 | UNARY_OPERATORS = { |
no test coverage detected