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

Function parseLeaf

python/text_generator.py:134–150  ·  view source on GitHub ↗
(tokens, currentIndex)

Source from the content-addressed store, hash-verified

132
133
134def parseLeaf(tokens, currentIndex):
135 if currentIndex >= len(tokens):
136 print("Index out of bounds, attempting to parse leaf")
137 return currentIndex
138
139 lookahead = tokens[currentIndex]
140 if lookahead["type"] == "PYTHON_BINARY_OPERATOR":
141 op = lookahead["properties"]["operator"]
142 if op in UNARY_OPERATORS:
143 # treat RHS as it's own expression, depending on precedence.
144 lhs, index = parseLeaf(tokens, currentIndex + 1)
145 top_expr, index = parseExpression(
146 lhs, tokens, index, getUnaryPrecedence(op)
147 )
148 # Create Unary expression
149 return [ast.UnaryOp(getAstUnaryOperator(op), top_expr), index]
150 return [generateAstExpressionToken(tokens[currentIndex]), currentIndex + 1]
151
152
153UNARY_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