MCPcopy Create free account
hub / github.com/SplootCode/splootcode / parseExpression

Function parseExpression

python/executor.py:230–271  ·  view source on GitHub ↗
(lhs, tokens, currentIndex, minPrecedence)

Source from the content-addressed store, hash-verified

228
229
230def 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
274def generateAstExpression(exp_node):

Callers 2

parseLeafFunction · 0.70
generateAstExpressionFunction · 0.70

Calls 5

getBinaryPrecedenceFunction · 0.70
parseLeafFunction · 0.70
isBoolOpFunction · 0.70
getAstOperatorFunction · 0.70
isCompareOpFunction · 0.70

Tested by

no test coverage detected