(lhs, tokens, currentIndex, minPrecedence)
| 228 | |
| 229 | |
| 230 | def parseExpression(lhs, tokens, currentIndex, minPrecedence): |
| 231 | if currentIndex >= len(tokens): |
| 232 | return [lhs, currentIndex] |
| 233 | |
| 234 | lookahead = tokens[currentIndex] |
| 235 | while ( |
| 236 | lookahead is not None |
| 237 | and lookahead["type"] == "PYTHON_BINARY_OPERATOR" |
| 238 | and getBinaryPrecedence(lookahead["properties"]["operator"]) >= minPrecedence |
| 239 | ): |
| 240 | operator = lookahead["properties"]["operator"] |
| 241 | operatorPrecedence = getBinaryPrecedence(operator) |
| 242 | currentIndex += 1 |
| 243 | rhs, currentIndex = parseLeaf(tokens, currentIndex) |
| 244 | if currentIndex < len(tokens): |
| 245 | lookahead = tokens[currentIndex] |
| 246 | while ( |
| 247 | lookahead is not None |
| 248 | and lookahead["type"] == "PYTHON_BINARY_OPERATOR" |
| 249 | and getBinaryPrecedence(lookahead["properties"]["operator"]) > operatorPrecedence |
| 250 | ): |
| 251 | lookaheadOp = lookahead["properties"]["operator"] |
| 252 | [rhs, currentIndex] = parseExpression( |
| 253 | rhs, tokens, currentIndex, getBinaryPrecedence(lookaheadOp) |
| 254 | ) |
| 255 | if currentIndex < len(tokens): |
| 256 | lookahead = tokens[currentIndex] |
| 257 | else: |
| 258 | lookahead = None |
| 259 | else: |
| 260 | lookahead = None |
| 261 | if isBoolOp(operator): |
| 262 | lhs = ast.BoolOp(getAstOperator(operator), [lhs, rhs]) |
| 263 | elif isCompareOp(operator): |
| 264 | if isinstance(lhs, ast.Compare): |
| 265 | lhs.ops.append(getAstOperator(operator)) |
| 266 | lhs.comparators.append(rhs) |
| 267 | else: |
| 268 | lhs = ast.Compare(lhs, [getAstOperator(operator)], [rhs]) |
| 269 | else: |
| 270 | lhs = ast.BinOp(lhs, getAstOperator(operator), rhs) |
| 271 | return [lhs, currentIndex] |
| 272 | |
| 273 | |
| 274 | def generateAstExpression(exp_node): |
no test coverage detected