public UnifiedElement VisitConditionalExpression( ConditionalExpression expr, object data) { var cond = expr.Condition.TryAcceptForExpression(this); var former = expr.TrueExpression.TryAcceptForExpression(this); var latter = expr.FalseExpression.TryAcceptForExpression(this); return(UnifiedTernaryExpression.Create(cond, former, latter)); }
public override bool Visit( UnifiedTernaryExpression element, VisitorArgument arg) { var paren = GetRequiredParen(element); Writer.Write(paren.Item1); element.Condition.TryAccept(this, arg.Set(Paren)); Writer.Write(" ? "); element.TrueExpression.TryAccept(this, arg.Set(Paren)); Writer.Write(" : "); element.FalseExpression.TryAccept(this, arg.Set(Paren)); Writer.Write(paren.Item2); return false; }
public override bool Visit( UnifiedTernaryExpression element, VisitorArgument arg) { var paren = GetRequiredParen(element); Writer.Write(paren.Item1); element.Condition.TryAccept(this, arg.Set(Paren)); Writer.Write(" ? "); element.TrueExpression.TryAccept(this, arg.Set(Paren)); Writer.Write(" : "); element.FalseExpression.TryAccept(this, arg.Set(Paren)); Writer.Write(paren.Item2); return(false); }
public static UnifiedExpression CreateConditionalExpression( XElement node) { Contract.Requires(node != null); Contract.Requires(node.Name() == "conditional_expression"); /* * conditional_expression * : logical_or_expression ('?' expression ':' conditional_expression)? */ if (node.Elements().Count() == 1) { return(CreateLogicalOrExpression(node.FirstElement())); } return(UnifiedTernaryExpression.Create( CreateLogicalOrExpression(node.ElementAt(0)), CreateExpression(node.NthElement(2)).First(), CreateConditionalExpression(node.NthElement(4)))); }