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

Function parseLeaf

packages/language-web/types/js/expression.ts:24–39  ·  view source on GitHub ↗
(tokens: SplootNode[], current: number)

Source from the content-addressed store, hash-verified

22export const SPLOOT_EXPRESSION = 'SPLOOT_EXPRESSION'
23
24function parseLeaf(tokens: SplootNode[], current: number): [ExpressionKind, number] {
25 if (current >= tokens.length) {
26 console.warn('Index out of bounds attempting to parse leaf')
27 }
28 const lookahead = tokens[current]
29 // If we hit an operator here, it might be a unary operator.
30 if (lookahead.type === BINARY_OPERATOR) {
31 const op = lookahead as BinaryOperator
32 if (['+', '-', '++', '--'].indexOf(op.getOperator()) !== -1) {
33 const [argument, newCurrent] = parseLeaf(tokens, current + 1)
34 const expr: UnaryExpressionKind = recast.types.builders.unaryExpression(op.getOperator(), argument)
35 return [expr, newCurrent]
36 }
37 }
38 return [(tokens[current] as JavaScriptSplootNode).generateJsAst() as ExpressionKind, current + 1]
39}
40
41function parseExpression(
42 lhs: ExpressionKind,

Callers 2

parseExpressionFunction · 0.70
generateJsAstMethod · 0.70

Calls 2

getOperatorMethod · 0.45
generateJsAstMethod · 0.45

Tested by

no test coverage detected