Пример #1
0
        public void ParserMarkupEmbeddingStatementTest()
        {
            //Create parser
            StatementParser statementParser = new StatementParser(Init("p p \"left<func1() \"text\">right\";"));
            Statement       parsedStatement = statementParser.ParseMarkupStatement();

            //Test statement
            Assert.AreEqual(typeof(MarkupEmbeddingStatement), parsedStatement.GetType());

            //Test MarkupEmbeddingStatement
            MarkupEmbeddingStatement markupEmbeddingStatement = (MarkupEmbeddingStatement)parsedStatement;

            Assert.AreEqual("p", markupEmbeddingStatement.GetMarkups().Get(0).ToString());
            Assert.AreEqual("p", markupEmbeddingStatement.GetMarkups().Get(1).ToString());

            //Test embedding
            Embedding embedding = markupEmbeddingStatement.GetEmbedding();

            Assert.AreEqual("\"left<", embedding.GetPreText().ToString());
            Assert.AreEqual(typeof(ExpressionEmbed), embedding.GetEmbed().GetType());

            ExpressionEmbed embed = (ExpressionEmbed)embedding.GetEmbed();

            Assert.AreEqual(1, embed.GetMarkups().Count);
            Assert.AreEqual("func1", embed.GetMarkups().Get(0).ToString());
            Assert.AreEqual(typeof(TextExpression), embed.GetExpression().GetType());
            Assert.AreEqual("\"text\"", embed.GetExpression().ToString());

            Assert.AreEqual(typeof(PostTextTail), embedding.GetTextTail().GetType());
            PostTextTail postTextTail = (PostTextTail)embedding.GetTextTail();

            Assert.AreEqual(">right\"", postTextTail.GetPostText().ToString());
        }
Пример #2
0
        /// <summary>
        /// Interpret MarkupEmbeddingStatement
        /// </summary>
        /// <param name="statement">MarkupEmbeddingStatement to interpret</param>
        public override void Visit(MarkupEmbeddingStatement 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
                        MarkupEmbeddingStatement markupEmbeddingStatement = new MarkupEmbeddingStatement();
                        markupEmbeddingStatement.SetMarkups(nonInterpretedMarkups);
                        markupEmbeddingStatement.SetEmbedding(statement.GetEmbedding());
                        PushYieldNode(markupEmbeddingStatement);
                    }
                    //Interpret markup
                    ((Markup)MarkupArray[i]).AcceptVisitor(this);
                    return;
                }
                else
                {   //Interpret Tag
                    ((Markup)MarkupArray[i]).AcceptVisitor(this);
                }
            }

            //Interpret Embedding
            statement.GetEmbedding().AcceptVisitor(this);
        }