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

Function parseExpression

python/text_generator.py:225–263  ·  view source on GitHub ↗
(lhs, tokens, currentIndex, minPrecedence)

Source from the content-addressed store, hash-verified

223
224
225def 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
266def 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