11.12 Conditional Operator
770152
function parseConditionalExpression() {
        var expr, previousAllowIn, consequent, alternate, startToken;

        startToken = lookahead;

        expr = parseBinaryExpression();
        if (match('?')) {
            lex();
            previousAllowIn = state.allowIn;
            state.allowIn = true;
            consequent = parseAssignmentExpression();
            state.allowIn = previousAllowIn;
            expect(':');
            alternate = parseAssignmentExpression();

            expr = new WrappingNode(startToken).finishConditionalExpression(expr, consequent, alternate);
        }

        return expr;
    }
1313959
private function add_conditional_operators() {
		$this->engine->addHelper(
			'if_cond',
			function ( $template, $context, $args ) {
					$that = $context->get( 'this' );

					$handlebars_arguments = new Arguments( $args );
					$arguments            = $handlebars_arguments->getPositionalArguments();

					$value_a  = $arguments[0];
					$operator = $arguments[1];
					$value_b  = $arguments[2];

					$value_a = $this->get_real_value( $value_a, $that );
					$value_b = $this->get_real_value( $value_b, $that );

				if ( $this->is_conditional_true( $value_a, $value_b, $operator ) ) {
					$template->setStopToken( 'else' );
					$buffer = $this->render( $template, $context, array(), true );
					$template->setStopToken( false );
					$template->discard( $context );
				} else {
					$template->setStopToken( 'else' );
					$template->discard( $context );
					$template->setStopToken( false );
					$buffer = $this->render( $template, $context, array(), true );
				}

					return $buffer;
			}
		);
	}
949827
def conditional_symbols(node):
    '''
    
    
    '''

    gen = ConditionalSymbolVisitor()
    gen.visit(node)
    lhs = gen.cond_lhs, gen.stable_lhs
    rhs = gen.cond_rhs, gen.stable_rhs
    undefined = gen.undefined
    return lhs, rhs, undefined
192048
function (item, expression) {
            var ret = 1,
                operator = expression.operator;

            if (expression instanceof Query.Where) {
                if (operator === "or") {
                    ret = 0;
                }
                var tmp;
                for (var i = 0; i < expression.expressions.length; i++) {
                    tmp = this._filterItem(item, expression.expressions[i]);
                    if (operator === "and") {
                        ret = ret * tmp;
                    } else if (operator === "or" && tmp) {
                        return 1;
                    } else if (operator === "not") {
                        return tmp ? 0 : 1;
                    }
                }
            } else if (expression instanceof Query.Comparator) {
                // TODO: add type check
                var value = expression.value,
                    field = expression.field,
                    itemValue = this._getValueForItemField(item, field);

                if (typeof(itemValue) === "undefined") {
                    return 0;
                }

                switch (operator) {
                    case "eql":
                        return itemValue == value;
                    case "gt":
                        return itemValue > value;
                    case "lt":
                        return itemValue < value;
                    case "gte":
                        return itemValue >= value;
                    case "lte":
                        return itemValue <= value;
                    case "in":
                        if (!(itemValue instanceof Array)) {
                            itemValue = [itemValue];
                        }
                        for (var j = 0; j < itemValue.length; j++) {
                            for (var k in value) {
                                if (value.hasOwnProperty(k)) {
                                    if (itemValue[j] == value[k]) {
                                        return 1;
                                    }
                                }
                            }
                        }
                        return 0;
                    case "between":
                        return itemValue >= value[0] && itemValue <= value[1];
                    case "like":
                        return new RegExp(value, "i").test(itemValue);
                    case "ne":
                        return itemValue != value;
                    default :
                        return 1;
                }

            }

            return ret;
        }
950646
function parseConditionalExpression() {
        var expr, previousAllowIn, consequent;

        expr = parseLogicalORExpression();

        if (match('?')) {
            lex();
            previousAllowIn = state.allowIn;
            state.allowIn = true;
            consequent = parseAssignmentExpression();
            state.allowIn = previousAllowIn;
            expect(':');

            expr = {
                type: Syntax.ConditionalExpression,
                test: expr,
                consequent: consequent,
                alternate: parseAssignmentExpression()
            };
        }

        return expr;
    }
200943
function checkConditional(runner, conditional) {
  try {
    return conditional[1].call(runner, runner.target, runner.context);
  } catch (e) {}
}
118548
public final void conditionalAndExpression() throws RecognitionException {
		int conditionalAndExpression_StartIndex = input.index();

		try {
			if ( state.backtracking>0 && alreadyParsedRule(input, 112) ) { return; }

			// src/main/resources/org/drools/compiler/semantics/java/parser/Java.g:1146:5: ( inclusiveOrExpression ( '&&' inclusiveOrExpression )* )
			// src/main/resources/org/drools/compiler/semantics/java/parser/Java.g:1146:9: inclusiveOrExpression ( '&&' inclusiveOrExpression )*
			{
			pushFollow(FOLLOW_inclusiveOrExpression_in_conditionalAndExpression5102);
			inclusiveOrExpression();
			state._fsp--;
			if (state.failed) return;
			// src/main/resources/org/drools/compiler/semantics/java/parser/Java.g:1146:31: ( '&&' inclusiveOrExpression )*
			loop144:
			while (true) {
				int alt144=2;
				int LA144_0 = input.LA(1);
				if ( (LA144_0==33) ) {
					alt144=1;
				}

				switch (alt144) {
				case 1 :
					// src/main/resources/org/drools/compiler/semantics/java/parser/Java.g:1146:33: '&&' inclusiveOrExpression
					{
					match(input,33,FOLLOW_33_in_conditionalAndExpression5106); if (state.failed) return;
					pushFollow(FOLLOW_inclusiveOrExpression_in_conditionalAndExpression5108);
					inclusiveOrExpression();
					state._fsp--;
					if (state.failed) return;
					}
					break;

				default :
					break loop144;
				}
			}

			}

		}
		catch (RecognitionException re) {
			reportError(re);
			recover(input,re);
		}
		finally {
			// do for sure before leaving
			if ( state.backtracking>0 ) { memoize(input, 112, conditionalAndExpression_StartIndex); }

		}
	}
1001151
public String conditionalExpression() throws RecognitionException {
        int first = input.index();
        exprParser.conditionalExpression();
        if ( state.failed ) return null;

        if ( state.backtracking == 0 && input.index() > first ) {
            // expression consumed something
            String expr = input.toString( first,
                                          input.LT( -1 ).getTokenIndex() );
            return expr;
        }
        return null;
    }
795734
private void checkConditionalForwardsExpressions(ClassDeclaration jclass)
            throws FatalCompileTimeException
    {
        // Get simple actions in the Controller annotation.
        List simpleActions =
                CompilerUtils.getAnnotationArrayValue(jclass, CONTROLLER_TAG_NAME, SIMPLE_ACTIONS_ATTR, true);

        if (simpleActions != null) {
            HashSet expressionsFound = new HashSet();
            for (Iterator j = simpleActions.iterator(); j.hasNext();) {
                AnnotationInstance sa = (AnnotationInstance) j.next();
                List conditionalForwards = CompilerUtils.getAnnotationArray(sa, CONDITIONAL_FORWARDS_ATTR, true);

                if (conditionalForwards != null) {
                    for (Iterator k = conditionalForwards.iterator(); k.hasNext();) {
                        AnnotationInstance cf = (AnnotationInstance) k.next();
                        String expression = CompilerUtils.getString(cf, CONDITION_ATTR, true);
                        assert expression != null;

                        if (expressionsFound.contains(expression)) {
                            String name = CompilerUtils.getString(sa, NAME_ATTR, true);
                            getDiagnostics().addWarning(cf, "warning.duplicate-conditional-forward-expression",expression, name);
                        }
                        else {
                            expressionsFound.add(expression);
                        }
                    }
                }
                expressionsFound.clear();
            }
        }
    }
541974
function isForkingByTrueOrFalse(node) {
    const parent = node.parent;

    switch (parent.type) {
        case "ConditionalExpression":
        case "IfStatement":
        case "WhileStatement":
        case "DoWhileStatement":
        case "ForStatement":
            return parent.test === node;

        case "LogicalExpression":
            return isHandledLogicalOperator(parent.operator);

        default:
            return false;
    }
}
1324225
private boolean validConditionalExpression(Node expr) {
    // The expression must have four children:
    // - The cond keyword
    // - A boolean expression
    // - A type transformation expression with the 'if' branch
    // - A type transformation expression with the 'else' branch
    if (!checkParameterCount(expr, Keywords.COND)) {
      return false;
    }
    // Check for the validity of the boolean and the expressions
    if (!validBooleanExpression(getCallArgument(expr, 0))) {
      warnInvalidInside("conditional", expr);
      return false;
    }
    if (!validTypeTransformationExpression(getCallArgument(expr, 1))) {
      warnInvalidInside("conditional", expr);
      return false;
    }
    if (!validTypeTransformationExpression(getCallArgument(expr, 2))) {
      warnInvalidInside("conditional", expr);
      return false;
    }
    return true;
  }
563574
function checkConditional(node) {
            const nonSpacedConsequesntNode = getFirstNonSpacedToken(node.test, node.consequent, "?");
            const nonSpacedAlternateNode = getFirstNonSpacedToken(node.consequent, node.alternate, ":");

            if (nonSpacedConsequesntNode) {
                report(node, nonSpacedConsequesntNode);
            } else if (nonSpacedAlternateNode) {
                report(node, nonSpacedAlternateNode);
            }
        }
431413
function boolStringOption(value){
    if(value === 'true' || value === true) return true;
    if(value === 'false' || value === false) return false;
    return value;
}
837424
protected static function evalTemplateConditionals($template, array $data, array $conditionals = null)
    {
        // find all conditionals
        if(!isset($conditionals))
            $conditionals = self::getTemplateConditionals($template);

        if(empty($conditionals))
            return $template;

        // check them all
        foreach($conditionals['set'] as $conditional)
        {
            if(isset($data[$conditional]))
                $template = str_replace(['{{ifdef '. $conditional . '}}', '{{endif ' . $conditional . '}}'], '', $template);
            else
                $template = preg_replace('#\{\{ifdef ' . $conditional . '\}\}[\s\S]*\{\{endif ' . $conditional . '\}\}#', '', $template);
        }

        foreach($conditionals['not_set'] as $conditional)
        {
            if(!isset($data[$conditional]))
                $template = str_replace(['{{ifndef '. $conditional . '}}', '{{endif ' . $conditional . '}}'], '', $template);
            else
                $template = preg_replace('#\{\{ifndef ' . $conditional . '\}\}[\s\S]*\{\{endif ' . $conditional . '\}\}#', '', $template);
        }

        return $template;
    }
1119985
def rewrite_binary_composition_inside_ternary_conditional(ir_blocks):
    """"""
    def visitor_fn(expression):
        """Expression visitor function."""
        # MATCH queries do not allow BinaryComposition inside a TernaryConditional's true/false
        # value blocks, since OrientDB cannot produce boolean values for comparisons inside them.
        # We transform any structures that resemble the following:
        #    TernaryConditional(predicate, X, Y), with X or Y of type BinaryComposition
        # into the following:
        # - if X is of type BinaryComposition, and Y is not,
        #    BinaryComposition(
        #        u'=',
        #        TernaryConditional(
        #            predicate,
        #            TernaryConditional(X, true, false),
        #            Y
        #        ),
        #        true
        #    )
        # - if Y is of type BinaryComposition, and X is not,
        #    BinaryComposition(
        #        u'=',
        #        TernaryConditional(
        #            predicate,
        #            X,
        #            TernaryConditional(Y, true, false),
        #        ),
        #        true
        #    )
        # - if both X and Y are of type BinaryComposition,
        #    BinaryComposition(
        #        u'=',
        #        TernaryConditional(
        #            predicate,
        #            TernaryConditional(X, true, false),
        #            TernaryConditional(Y, true, false)
        #        ),
        #        true
        #    )
        if not isinstance(expression, TernaryConditional):
            return expression

        if_true = expression.if_true
        if_false = expression.if_false

        true_branch_rewriting_necessary = isinstance(if_true, BinaryComposition)
        false_branch_rewriting_necessary = isinstance(if_false, BinaryComposition)

        if not (true_branch_rewriting_necessary or false_branch_rewriting_necessary):
            # No rewriting is necessary.
            return expression

        if true_branch_rewriting_necessary:
            if_true = TernaryConditional(if_true, TrueLiteral, FalseLiteral)

        if false_branch_rewriting_necessary:
            if_false = TernaryConditional(if_false, TrueLiteral, FalseLiteral)

        ternary = TernaryConditional(expression.predicate, if_true, if_false)
        return BinaryComposition(u'=', ternary, TrueLiteral)

    new_ir_blocks = [
        block.visit_and_update_expressions(visitor_fn)
        for block in ir_blocks
    ]

    return new_ir_blocks
744836
def call_condition_proc(condition, object)
        case condition
        when Proc   then condition.call(object)
        when Symbol then condition.to_proc.call(object)
        else             condition
        end
      end
166522
function checkCondition(i) {
  const start = i;
  let l;
  let _i;
  let s;

  if (i >= tokensLength) return 0;

  if (l = checkAtkeyword(i)) i += l;
  else return 0;

  if (['if', 'else'].indexOf(tokens[start + 1].value) < 0) return 0;

  while (i < tokensLength) {
    if (l = checkBlock(i)) break;

    s = checkSC(i);
    _i = i + s;

    if (l = _checkCondition(_i)) i += l + s;
    else break;
  }

  return i - start;
}