( lhs: ExpressionKind, tokens: SplootNode[], current: number, minPrecedence: number )
| 39 | } |
| 40 | |
| 41 | function parseExpression( |
| 42 | lhs: ExpressionKind, |
| 43 | tokens: SplootNode[], |
| 44 | current: number, |
| 45 | minPrecedence: number |
| 46 | ): [ExpressionKind, number] { |
| 47 | if (current >= tokens.length) { |
| 48 | return [lhs, current] |
| 49 | } |
| 50 | |
| 51 | let lookahead = tokens[current] |
| 52 | while ( |
| 53 | lookahead && |
| 54 | lookahead.type === BINARY_OPERATOR && |
| 55 | (lookahead as BinaryOperator).getPrecedence() >= minPrecedence |
| 56 | ) { |
| 57 | const operator = lookahead as BinaryOperator |
| 58 | current += 1 |
| 59 | let rhs: ExpressionKind |
| 60 | ;[rhs, current] = parseLeaf(tokens, current) |
| 61 | if (current < tokens.length) { |
| 62 | lookahead = tokens[current] |
| 63 | while ( |
| 64 | lookahead && |
| 65 | lookahead.type === BINARY_OPERATOR && |
| 66 | (lookahead as BinaryOperator).getPrecedence() > operator.getPrecedence() |
| 67 | ) { |
| 68 | ;[rhs, current] = parseExpression(rhs, tokens, current, (lookahead as BinaryOperator).getPrecedence()) |
| 69 | if (current < tokens.length) { |
| 70 | lookahead = tokens[current] |
| 71 | } else { |
| 72 | lookahead = null |
| 73 | } |
| 74 | } |
| 75 | } else { |
| 76 | lookahead = null |
| 77 | } |
| 78 | lhs = recast.types.builders.binaryExpression(operator.getOperator(), lhs, rhs) |
| 79 | } |
| 80 | return [lhs, current] |
| 81 | } |
| 82 | |
| 83 | export class SplootExpression extends JavaScriptSplootNode { |
| 84 | constructor(parentReference: ParentReference) { |
no test coverage detected