Пример #1
0
        public object Translate(TranslationContext context, ASTNode node)
        {
            var result = new CREFModel.Choice();

            var comparand = node.Children.FirstOrDefault(n => n.Name == "comparand");

            foreach (var caseItem in ((Node)node).Children.Where(n => n.Name == "caseItem"))
            {
                var whenNode = caseItem.Children[0] as ASTNode;
                var thenNode = caseItem.Children[1] as ASTNode;

                var condition = new CREFModel.Condition();
                if (comparand == null)
                {
                    condition.Items.Add(context.TranslateNode(whenNode));
                }
                else
                {
                    var equal = new CREFModel.BinaryExpression();
                    equal.Operator          = CREFModel.BinaryOperator.opEqual;
                    equal.OperatorSpecified = true;
                    equal.Items.Add(context.TranslateNode(comparand));
                    equal.Items.Add(context.TranslateNode(whenNode));
                    condition.Items.Add(equal);
                }

                condition.Items.Add(context.TranslateNode(thenNode));

                result.Items.Add(condition);
            }

            var elseNode = node.Children.FirstOrDefault(n => n.Name == "else") as ASTNode;

            result.Items.Add(context.TranslateNode(elseNode));

            return(result);
        }
Пример #2
0
        public object Translate(TranslationContext context, ASTNode node)
        {
            var result = new CREFModel.Choice();

            var comparand = node.Children.FirstOrDefault(n => n.Name == "comparand");

            foreach (var caseItem in ((Node)node).Children.Where(n => n.Name == "caseItem"))
            {
                var whenNode = caseItem.Children[0] as ASTNode;
                var thenNode = caseItem.Children[1] as ASTNode;

                var condition = new CREFModel.Condition();
                if (comparand == null)
                {
                    condition.Items.Add(context.TranslateNode(whenNode));
                }
                else
                {
                    var equal = new CREFModel.BinaryExpression();
                    equal.Operator = CREFModel.BinaryOperator.opEqual;
                    equal.OperatorSpecified = true;
                    equal.Items.Add(context.TranslateNode(comparand));
                    equal.Items.Add(context.TranslateNode(whenNode));
                    condition.Items.Add(equal);
                }

                condition.Items.Add(context.TranslateNode(thenNode));

                result.Items.Add(condition);
            }

            var elseNode = node.Children.FirstOrDefault(n => n.Name == "else") as ASTNode;

            result.Items.Add(context.TranslateNode(elseNode));

            return result;
        }