Example #1
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);
        }
            public void AllEmpty()
            {
                //arrange
                string inputPath = @"HasEmpties\Inputs\AllEmpty.xml";
                string expected  = string.Format(LiteralsPython.Import, LiteralsPython.PackageName) + '\n';
                string name      = "None";

                expected += '\n';
                expected += LiteralsPython.Event + "\n" + BlocklyTransformer.AddSpaces(1) + LiteralsPython.EventStart;
                expected += LiteralsPython.EmptyEvent;
                expected += "\n\n";
                expected += LiteralsPython.Body + "\n";
                expected += BlocklyTransformer.AddSpaces(1) + LiteralsPython.EmptyBody;
                expected += '\n';
                expected += string.Format(LiteralsPython.AddScript, name);

                //act
                var actual = TestOne(ReadXmlInput(inputPath));

                //assert
                Assert.AreEqual(expected, actual);
            }
Example #3
0
        /// <summary>
        /// Interpret context as <see cref="Script"/>
        /// </summary>
        /// <param name="context">Context to interpret</param>
        /// <returns>Python code</returns>
        public override string Interpret(ref XmlToPythonContext context)
        {
            base.Interpret(ref context);
            var node = context.currentNode;
            //add imports
            string result = string.Format(LiteralsPython.Import, LiteralsPython.PackageName) + '\n';
            string ev     = string.Empty;
            string body   = string.Empty;
            string name   = "None";

            foreach (XmlNode item in node.ChildNodes)
            {
                context.currentNode = item;
                switch (item.Attributes["name"].Value)
                {
                //name of script
                case "NAME":
                    name = (new Values.Name()).Interpret(ref context);
                    break;

                //event of script
                case "EVENT":
                    ev = (new Values.Event()).Interpret(ref context);
                    break;

                //body of script
                case "BODY":
                    body = (new Statements.Body()).Interpret(ref context);
                    break;
                }
            }
            //declare event of script
            result += '\n';
            result += LiteralsPython.Event + "\n" + BlocklyTransformer.AddSpaces(1) + LiteralsPython.EventStart;
            if (string.IsNullOrEmpty(ev))
            {
                result += LiteralsPython.EmptyEvent;
            }
            else
            {
                result += ev;
            }

            //declare body of script
            result += "\n\n";
            result += LiteralsPython.Body + "\n";
            if (string.IsNullOrEmpty(body))
            {
                result += BlocklyTransformer.AddSpaces(1) + LiteralsPython.EmptyBody;
            }
            else
            {
                result += body;
            }

            //declare script with name, event and body
            result += '\n';
            result += string.Format(LiteralsPython.AddScript, name);

            return(result);
        }