Precedence-climbing binary expression parser.
( P: ParseState, stop: string, minPrec: number, mode: ArithMode, )
| 4230 | |
| 4231 | /** Precedence-climbing binary expression parser. */ |
| 4232 | function parseArithBinary( |
| 4233 | P: ParseState, |
| 4234 | stop: string, |
| 4235 | minPrec: number, |
| 4236 | mode: ArithMode, |
| 4237 | ): TsNode | null { |
| 4238 | let left = parseArithUnary(P, stop, mode) |
| 4239 | if (!left) return null |
| 4240 | while (true) { |
| 4241 | skipBlanks(P.L) |
| 4242 | if (isArithStop(P, stop)) break |
| 4243 | if (peek(P.L) === ',') break |
| 4244 | const opInfo = scanArithOp(P) |
| 4245 | if (!opInfo) break |
| 4246 | const [opText, opLen] = opInfo |
| 4247 | const prec = ARITH_PREC[opText] |
| 4248 | if (prec === undefined || prec < minPrec) break |
| 4249 | const os = P.L.b |
| 4250 | for (let k = 0; k < opLen; k++) advance(P.L) |
| 4251 | const op = mk(P, opText, os, P.L.b, []) |
| 4252 | const nextMin = ARITH_RIGHT_ASSOC.has(opText) ? prec : prec + 1 |
| 4253 | const right = parseArithBinary(P, stop, nextMin, mode) |
| 4254 | if (!right) break |
| 4255 | left = mk(P, 'binary_expression', left.startIndex, right.endIndex, [ |
| 4256 | left, |
| 4257 | op, |
| 4258 | right, |
| 4259 | ]) |
| 4260 | } |
| 4261 | return left |
| 4262 | } |
| 4263 | |
| 4264 | function parseArithUnary( |
| 4265 | P: ParseState, |
no test coverage detected