Beispiel #1
0
        public void ParseMarkupStatStatementTest()
        {
            //Create parser
            StatementParser statementParser = new StatementParser(Init("p { echo \"test\"; }"));
            Statement       parsedStatement = statementParser.ParseMarkupStatement();

            //Test Statement
            Assert.AreEqual(typeof(MarkupStatStatement), parsedStatement.GetType());

            //Test MarkupStatStatement
            MarkupStatStatement markupStatStatement = (MarkupStatStatement)parsedStatement;

            Assert.AreEqual(1, markupStatStatement.GetMarkups().Count);

            //Test markup
            Markup markup = (Markup)markupStatStatement.GetMarkups().Get(0);

            Assert.AreEqual("p", markup.GetDesignator().GetIdentifier());
            Assert.AreEqual(0, markup.GetArguments().Count);

            //Test statement
            Assert.AreEqual(typeof(BlockStatement), markupStatStatement.GetStatement().GetType());
            BlockStatement statement = (BlockStatement)markupStatStatement.GetStatement();

            Assert.AreEqual(1, statement.GetStatements().Count);

            Statement stmt = (Statement)statement.GetStatements().Get(0);

            Assert.AreEqual(typeof(EchoExpressionStatement), stmt.GetType());
            Assert.AreEqual("echo \"test\";", stmt.ToString());
        }
Beispiel #2
0
        /// <summary>
        /// Interpret MarkupStatStatement
        /// </summary>
        /// <param name="statement">MarkupStatStatement to interpret</param>
        public override void Visit(MarkupStatStatement statement)
        {
            //Iterate through Markup+
            ISyntaxNode[] MarkupArray = statement.GetMarkups().ToArray();
            for (int i = 0; i <= (MarkupArray.Length - 1); i++)
            {
                if (IsMarkupCall((Markup)MarkupArray[i]))
                {
                    //Check if called function contains an yield, if so, add remaining markups/expression to yield stack
                    String functionIdentifier = ((Markup)MarkupArray[i]).GetDesignator().GetIdentifier();
                    if (NodeContainsYield(SymbolTable.GetFunctionDefinition(functionIdentifier)))
                    {
                        //Get remaining markups
                        NodeList nonInterpretedMarkups = new NodeList();
                        for (int j = i + 1; j <= (MarkupArray.Length - 1); j++)
                        {
                            nonInterpretedMarkups.Add(MarkupArray[j]);
                        }
                        //Create new MarkupExpressionStatement and push it to stack
                        MarkupStatStatement markupStatStatement = new MarkupStatStatement();
                        markupStatStatement.SetMarkups(nonInterpretedMarkups);
                        markupStatStatement.SetStatement(statement.GetStatement());
                        PushYieldNode(markupStatStatement);
                    }
                    //Interpret markup
                    ((Markup)MarkupArray[i]).AcceptVisitor(this);
                    return;
                }
                else
                {   //Interpret Tag
                    ((Markup)MarkupArray[i]).AcceptVisitor(this);
                }
            }

            //Interpret statement
            statement.GetStatement().AcceptVisitor(this);
        }