Пример #1
0
        public override string Interpret(ref XmlToPythonContext context)
        {
            base.Interpret(ref context);
            var    nodes = context.currentNode.ChildNodes;
            string OP    = string.Empty;
            string A     = string.Empty;
            string B     = string.Empty;

            foreach (XmlNode n in nodes)
            {
                context.currentNode = n;
                switch (n.Attributes["name"].Value)
                {
                case "OP":
                    OP = new Field().Interpret(ref context);
                    break;

                //TODO: add attribute for comparables
                case "A":
                    context.NextNode();
                    if (OP == "EQ" || OP == "NEQ")
                    {
                        A = EqBlocks[context.currentNode.Attributes["type"].Value]
                            .Interpret(ref context);
                    }
                    else
                    {
                        A = ComBlocks[context.currentNode.Attributes["type"].Value]
                            .Interpret(ref context);
                    }
                    break;

                case "B":
                    context.NextNode();
                    if (OP == "EQ" || OP == "NEQ")
                    {
                        B = EqBlocks[context.currentNode.Attributes["type"].Value]
                            .Interpret(ref context);
                    }
                    else
                    {
                        B = ComBlocks[context.currentNode.Attributes["type"].Value]
                            .Interpret(ref context);
                    }
                    break;

                default:
                    throw new System.Exception();
                }
            }
            //TODO: error handling
            var result = "(" + A + Operations[OP] + B + ")";

            context.ParentNode();
            return(result);
        }
Пример #2
0
        /// <summary>
        /// Interpret context as <see cref="Lamp"/>
        /// </summary>
        /// <param name="context">Context to interpret</param>
        /// <returns>Python code</returns>
        public override string Interpret(ref XmlToPythonContext context)
        {
            base.Interpret(ref context);
            context.NextNode();
            var result = (new Blocks.Lamp()).Interpret(ref context);

            context.ParentNode();
            return(result);
        }
        /// <summary>
        /// Interpret context as <see cref="Number"/>
        /// </summary>
        /// <param name="context">Context to interpret</param>
        /// <returns>Python code</returns>
        public override string Interpret(ref XmlToPythonContext context)
        {
            base.Interpret(ref context);
            context.NextNode();
            var result = new Field().Interpret(ref context);

            context.ParentNode();
            return(result);
        }
Пример #4
0
        /// <summary>
        /// Interpret context as <see cref="Event"/>
        /// </summary>
        /// <param name="context">Context to interpret</param>
        /// <returns>Python code</returns>
        public override string Interpret(ref XmlToPythonContext context)
        {
            base.Interpret(ref context);
            context.NextNode();
            var result = EventStarters[context.currentNode.Attributes["type"].Value].Interpret(ref context);

            context.ParentNode();
            return(result);
        }
        /// <summary>
        /// Interpret context as <see cref="FunctionCallBlock{InputValueType}"/>
        /// </summary>
        /// <param name="context">Context to interpret</param>
        /// <returns>Python code</returns>
        public override string Interpret(ref XmlToPythonContext context)
        {
            base.Interpret(ref context);
            context.NextNode();
            var result = string.Format(LiteralsPython.FunctionCall, FunctionLiteral, (new InputValueType()).Interpret(ref context));

            context.ParentNode();
            return(result);
        }
Пример #6
0
        public override string Interpret(ref XmlToPythonContext context)
        {
            base.Interpret(ref context);
            //TODO: create finder attribute for numbers, that are not just math_number
            context.NextNode();
            var result = (new Blocks.Math.Number()).Interpret(ref context);

            context.ParentNode();
            return(result);
        }
Пример #7
0
        /// <summary>
        /// Interpret context as <see cref="MethodCallBlock{InputValueType}"/>
        /// </summary>
        /// <param name="context">Context to interpret</param>
        /// <returns>Python code</returns>
        public override string Interpret(ref XmlToPythonContext context)
        {
            base.Interpret(ref context);
            context.NextNode();
            var result = string.Format(LiteralsPython.MethodCall, (new InputValueType()).Interpret(ref context), FunctionLiteral);

            context.ParentNode();
            if (NeedNextCheck)
            {
                context.NextCheck();
            }
            return(result);
        }
Пример #8
0
        /// <summary>
        /// Interpret context as <see cref="Body"/>
        /// </summary>
        /// <param name="context">Context to interpret</param>
        /// <returns>Python code</returns>
        public override string Interpret(ref XmlToPythonContext context)
        {
            base.Interpret(ref context);
            context.tabCount = 1;
            var result = string.Empty;

            context.NextNode();
            XmlNode prev;

            do
            {
                prev    = context.currentNode;
                result += BlocklyTransformer.AddSpaces(context.tabCount)
                          + (Blocks[context.currentNode.Attributes["type"].Value]).Interpret(ref context) + '\n';
            } while (prev != context.currentNode);

            return(result);
        }