(lhs, tokens, currentIndex, minPrecedence)
| 223 | |
| 224 | |
| 225 | def parseExpression(lhs, tokens, currentIndex, minPrecedence): |
| 226 | if currentIndex >= len(tokens): |
| 227 | return [lhs, currentIndex] |
| 228 | |
| 229 | lookahead = tokens[currentIndex] |
| 230 | while ( |
| 231 | lookahead is not None |
| 232 | and lookahead["type"] == "PYTHON_BINARY_OPERATOR" |
| 233 | and getBinaryPrecedence(lookahead["properties"]["operator"]) >= minPrecedence |
| 234 | ): |
| 235 | operator = lookahead["properties"]["operator"] |
| 236 | operatorPrecedence = getBinaryPrecedence(operator) |
| 237 | currentIndex += 1 |
| 238 | rhs, currentIndex = parseLeaf(tokens, currentIndex) |
| 239 | if currentIndex < len(tokens): |
| 240 | lookahead = tokens[currentIndex] |
| 241 | while ( |
| 242 | lookahead is not None |
| 243 | and lookahead["type"] == "PYTHON_BINARY_OPERATOR" |
| 244 | and getBinaryPrecedence(lookahead["properties"]["operator"]) > operatorPrecedence |
| 245 | ): |
| 246 | lookaheadOp = lookahead["properties"]["operator"] |
| 247 | [rhs, currentIndex] = parseExpression( |
| 248 | rhs, tokens, currentIndex, getBinaryPrecedence(lookaheadOp) |
| 249 | ) |
| 250 | if currentIndex < len(tokens): |
| 251 | lookahead = tokens[currentIndex] |
| 252 | else: |
| 253 | lookahead = None |
| 254 | else: |
| 255 | lookahead = None |
| 256 | if isBoolOp(operator): |
| 257 | lhs = ast.BoolOp(getAstOperator(operator), [lhs, rhs]) |
| 258 | elif isCompareOp(operator): |
| 259 | # TODO: Support mutiple comparators, e.g. a < b < c |
| 260 | lhs = ast.Compare(lhs, [getAstOperator(operator)], [rhs]) |
| 261 | else: |
| 262 | lhs = ast.BinOp(lhs, getAstOperator(operator), rhs) |
| 263 | return [lhs, currentIndex] |
| 264 | |
| 265 | |
| 266 | def generateAstExpression(exp_node): |
no test coverage detected