(tokens: SplootNode[], current: number)
| 22 | export const SPLOOT_EXPRESSION = 'SPLOOT_EXPRESSION' |
| 23 | |
| 24 | function 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 | |
| 41 | function parseExpression( |
| 42 | lhs: ExpressionKind, |
no test coverage detected