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

Function parseLeaf

python/executor.py:139–155  ·  view source on GitHub ↗
(tokens, currentIndex)

Source from the content-addressed store, hash-verified

137
138
139def 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
158UNARY_OPERATORS = {

Callers 2

parseExpressionFunction · 0.70
generateAstExpressionFunction · 0.70

Calls 4

parseExpressionFunction · 0.70
getUnaryPrecedenceFunction · 0.70
getAstUnaryOperatorFunction · 0.70

Tested by

no test coverage detected