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

Function parseLeaf

packages/language-python/src/nodes/utils.ts:233–252  ·  view source on GitHub ↗
(tokens: SplootNode[], currentIndex: number)

Source from the content-addressed store, hash-verified

231}
232
233function parseLeaf(tokens: SplootNode[], currentIndex: number): [boolean, number] {
234 if (currentIndex >= tokens.length) {
235 // No tokens left when a leaf was expected
236 return [false, currentIndex]
237 }
238 const lookahead = tokens[currentIndex]
239 if (lookahead.type === 'PYTHON_BINARY_OPERATOR') {
240 const op = (lookahead as PythonBinaryOperator).getOperator()
241 if (op in UnaryOperators) {
242 const [valid, leafIndex] = parseLeaf(tokens, currentIndex + 1)
243 if (!valid) {
244 return [false, leafIndex]
245 }
246 return parseExpression(tokens, leafIndex, UnaryOperators[op]['precedence'])
247 }
248 return [false, currentIndex]
249 }
250 // Consume one token - whatever it was it wasn't an operator
251 return [true, currentIndex + 1]
252}
253
254function parseExpression(tokens: SplootNode[], currentIndex: number, minPrecedence: number): [boolean, number] {
255 if (currentIndex >= tokens.length) {

Callers 2

parseExpressionFunction · 0.70
validateExpressionParseFunction · 0.70

Calls 2

parseExpressionFunction · 0.70
getOperatorMethod · 0.45

Tested by

no test coverage detected