Exemple #1
0
        protected virtual void EmitCaseExpression(CaseExpression expression)
        {
            AppendFormat("{0}", "case");

            if (expression.Expression != null)
            {
                Append(" ");
                EmitExpression(expression.Expression);
            }

            for (int index = 0; index < expression.CaseItems.Count; index++)
            {
                AppendFormat(" {0} ", "when");
                EmitExpression(expression.CaseItems[index].WhenExpression);
                AppendFormat(" {0} ", "then");
                EmitExpression(expression.CaseItems[index].ThenExpression);
            }

            if (expression.ElseExpression != null)
            {
                AppendFormat(" {0} ", "else");
                EmitExpression(((CaseElseExpression)expression.ElseExpression).Expression);
            }

            AppendFormat(" {0}", "end");
        }
        public object Translate(TranslationContext context, ASTNode node)
        {
            var result = new Model.CaseExpression();
            var resultItem = new Model.CaseItemExpression();
            resultItem.WhenExpression = (Model.Expression)context.TranslateNode(node.Children[0]);
            resultItem.ThenExpression = (Model.Expression)context.TranslateNode(node.Children[1]);
            result.CaseItems.Add(resultItem);
            result.ElseExpression = (Model.Expression)context.TranslateNode(node.Children[2]);

            return result;
        }