MCPcopy Index your code
hub / github.com/dchester/jsonpath / parseBinaryExpression

Function parseBinaryExpression

jsonpath.js:2488–2542  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

2486 // 11.11 Binary Logical Operators
2487
2488 function parseBinaryExpression() {
2489 var marker, markers, expr, token, prec, stack, right, operator, left, i;
2490
2491 marker = lookahead;
2492 left = parseUnaryExpression();
2493
2494 token = lookahead;
2495 prec = binaryPrecedence(token, state.allowIn);
2496 if (prec === 0) {
2497 return left;
2498 }
2499 token.prec = prec;
2500 lex();
2501
2502 markers = [marker, lookahead];
2503 right = parseUnaryExpression();
2504
2505 stack = [left, token, right];
2506
2507 while ((prec = binaryPrecedence(lookahead, state.allowIn)) > 0) {
2508
2509 // Reduce: make a binary expression from the three topmost entries.
2510 while ((stack.length > 2) && (prec <= stack[stack.length - 2].prec)) {
2511 right = stack.pop();
2512 operator = stack.pop().value;
2513 left = stack.pop();
2514 expr = delegate.createBinaryExpression(operator, left, right);
2515 markers.pop();
2516 marker = markers[markers.length - 1];
2517 delegate.markEnd(expr, marker);
2518 stack.push(expr);
2519 }
2520
2521 // Shift.
2522 token = lex();
2523 token.prec = prec;
2524 stack.push(token);
2525 markers.push(lookahead);
2526 expr = parseUnaryExpression();
2527 stack.push(expr);
2528 }
2529
2530 // Final reduce to clean-up the stack.
2531 i = stack.length - 1;
2532 expr = stack[i];
2533 markers.pop();
2534 while (i > 1) {
2535 expr = delegate.createBinaryExpression(stack[i - 1].value, stack[i - 2], expr);
2536 i -= 2;
2537 marker = markers.pop();
2538 delegate.markEnd(expr, marker);
2539 }
2540
2541 return expr;
2542 }
2543
2544
2545 // 11.12 Conditional Operator

Callers 1

Calls 3

parseUnaryExpressionFunction · 0.85
binaryPrecedenceFunction · 0.85
lexFunction · 0.70

Tested by

no test coverage detected