public void ParseNestedEmbeddingTest() { //Create parser EmbeddingParser embeddingParser = new EmbeddingParser(Init("\"pretext<em \"eerste\">midtext <em \"tweede\">posttexttail\"")); Embedding parsedEmbedding = embeddingParser.ParseEmbedding(); //Test pretext Assert.AreEqual("\"pretext<", parsedEmbedding.GetPreText().ToString()); //Test 1st embed Assert.AreEqual(typeof(ExpressionEmbed), parsedEmbedding.GetEmbed().GetType()); ExpressionEmbed expressionEmbed = (ExpressionEmbed)parsedEmbedding.GetEmbed(); Assert.AreEqual("em", expressionEmbed.GetMarkups().Get(0).ToString()); Assert.AreEqual("\"eerste\"", expressionEmbed.GetExpression().ToString()); //Test TextTail Assert.AreEqual(typeof(MidTextTail), parsedEmbedding.GetTextTail().GetType()); MidTextTail midTextTail = (MidTextTail)parsedEmbedding.GetTextTail(); Assert.AreEqual(">midtext <", midTextTail.GetMidText().ToString()); //Test 2th embed Assert.AreEqual(typeof(ExpressionEmbed), midTextTail.GetEmbed().GetType()); ExpressionEmbed expressionEmbed2 = (ExpressionEmbed)midTextTail.GetEmbed(); Assert.AreEqual("em", expressionEmbed2.GetMarkups().Get(0).ToString()); Assert.AreEqual("\"tweede\"", expressionEmbed2.GetExpression().ToString()); //Test PostTextTail Assert.AreEqual(typeof(PostTextTail), midTextTail.GetTextTail().GetType()); Assert.AreEqual(">posttexttail\"", midTextTail.GetTextTail().ToString()); }
public void ParseEmbeddingTest() { //Create parser EmbeddingParser embeddingParser = new EmbeddingParser(Init("\"left<func1() \"text\">right\"")); Embedding parsedEmbedding = embeddingParser.ParseEmbedding(); //Test PreText Assert.AreEqual("left", parsedEmbedding.GetPreText().GetText()); //Test Embed Assert.AreEqual(typeof(ExpressionEmbed), parsedEmbedding.GetEmbed().GetType()); ExpressionEmbed expressionEmbed = (ExpressionEmbed)parsedEmbedding.GetEmbed(); Assert.AreEqual("\"text\"", expressionEmbed.GetExpression().ToString()); //Test Markup Markup markup = (Markup)expressionEmbed.GetMarkups().Get(0); Assert.AreEqual("func1", markup.GetDesignator().ToString()); Assert.AreEqual(0, markup.GetArguments().Count); //Test TextTail Assert.AreEqual(typeof(PostTextTail), parsedEmbedding.GetTextTail().GetType()); PostTextTail postTextTail = (PostTextTail)parsedEmbedding.GetTextTail(); Assert.AreEqual("right", postTextTail.GetPostText().GetText()); }
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()); }
/// <summary> /// Interpret ExpressionEmbed /// </summary> /// <param name="embed">ExpressionEmbed to interpret</param> public override void Visit(ExpressionEmbed embed) { int depth = this.Depth; //Structure is same as MarkupExpressionStatement, so convert and interpret MarkupExpressionStatement markupExpressionStatement = new MarkupExpressionStatement(); markupExpressionStatement.SetMarkups(embed.GetMarkups()); markupExpressionStatement.SetExpression(embed.GetExpression()); markupExpressionStatement.AcceptVisitor(this); BackToParentXHTMLElement(depth); }
/// <summary> /// Parser for Embed /// </summary> /// <returns>Parsed Embed</returns> public Embed ParseEmbed() { Embed embed = null; NodeList markupList = new NodeList(); //Set up MarkupParser markupParser = new MarkupParser(EmbeddingTokenStream); //Parse Markup* //EmbeddingTokenStream.HasNext(2) && !(EmbeddingTokenStream.Peek(2).GetValue().ToString() == ">" while (NextTokenIsMarkup()) { markupList.Add(markupParser.ParseMarkup()); } //Check if an expression is remaining, otherwise embed is MarkupEmbedding if (IsExpressionRemaining()) { //ExpressionEmbedding ExpressionEmbed expressionEmbed = new ExpressionEmbed(); //Add already parsed markups to expressionEmbed expressionEmbed.SetMarkups(markupList); //Set up expressionparser expressionParser = new ExpressionParser(EmbeddingTokenStream); //Parse expression expressionEmbed.SetExpression(expressionParser.ParseExpression()); embed = expressionEmbed; } else { //MarkupEmbedding //Get last item from markupList and add it as Markup if (markupList.Count != 0) { Markup markup = (Markup)markupList.Get(markupList.Count - 1); markupList.Remove(markupList.Count - 1); MarkupEmbed markupEmbed = new MarkupEmbed(); markupEmbed.SetMarkups(markupList); markupEmbed.SetMarkup(markup); embed = markupEmbed; } else { //Markup* Markup must contain at least one markup element throw new UnexpectedToken("Markup expected, but found:", CurrentToken.GetValue().ToString(), CurrentToken.GetLine()); } } /*//Determine if remaining embed is Markup or Expression * if (NextTokenIsMarkup()) * { //MarkupEmbedding * MarkupEmbed markupEmbed = new MarkupEmbed(); * * //Add already parsed markups to markupEmbed * markupEmbed.SetMarkups(markupList); * * //Parse latest markup * markupEmbed.SetMarkup(markupParser.ParseMarkup()); * * embed = markupEmbed; * } * else * { //ExpressionEmbedding * ExpressionEmbed expressionEmbed = new ExpressionEmbed(); * * //Add already parsed markups to expressionEmbed * expressionEmbed.SetMarkups(markupList); * * //Set up expressionparser * expressionParser = new ExpressionParser(EmbeddingTokenStream); * * //Parse expression * expressionEmbed.SetExpression(expressionParser.ParseExpression()); * * embed = expressionEmbed; * } */ return(embed); }
public virtual void Visit(ExpressionEmbed embed) { VisitSubNodes(embed); }