public StatementParser(TokenIterator iterator) : base(iterator) { //Create subparsers predicateParser = new PredicateParser(iterator); expressionParser = new ExpressionParser(iterator); embeddingParser = new EmbeddingParser(iterator); markupParser = new MarkupParser(iterator); }
public void ParseAttrArgumentTest() { //Parse tokens MarkupParser markupParser = new MarkupParser(Init("(i = 1)")); Markup markup = new Markup(); markupParser.ParseArguments(markup); //Test arguments Assert.AreEqual(1, markup.GetArguments().Count); Argument argument = (Argument)markup.GetArguments().Get(0); Assert.AreEqual(typeof(AttrArgument), argument.GetType()); //Test specific argument AttrArgument attrArgument = (AttrArgument)argument; Assert.AreEqual("i", attrArgument.GetIdentifier()); Assert.AreEqual(typeof(NumExpression), attrArgument.GetExpression().GetType()); }
public void ParseAttributeTest() { //Parse tokens MarkupParser markupParser = new MarkupParser(Init("#id1")); Attribute parsedAttribute = markupParser.ParseAttribute(); //Check attribute Assert.AreEqual(typeof(IdAttribute), parsedAttribute.GetType()); //Check id attribute Assert.AreEqual("#id1", parsedAttribute.ToString()); }
public void ParseWidth_HeightAttributeTest() { //Parse tokens MarkupParser markupParser = new MarkupParser(Init("80%20")); Width_HeightAttribute parsedWidth_HeightAttribute = markupParser.ParseWidth_HeightAttribute(); //Check Id Attribute Assert.AreEqual(80, parsedWidth_HeightAttribute.GetWidth()); Assert.AreEqual(20, parsedWidth_HeightAttribute.GetHeight()); }
public void ParseTypeAttributeTest() { //Parse tokens MarkupParser markupParser = new MarkupParser(Init("type1")); TypeAttribute parsedTypeAttribute = markupParser.ParseTypeAttribute(); //Check Id Attribute Assert.AreEqual("type1", parsedTypeAttribute.GetType()); }
public void ParseNoArgumentsTest() { //Parse tokens MarkupParser markupParser = new MarkupParser(Init("()")); Markup markup = new Markup(); markupParser.ParseArguments(markup); //Test arguments Assert.AreEqual(0, markup.GetArguments().Count); }
public void ParseNameAttributeTest() { //Parse tokens MarkupParser markupParser = new MarkupParser(Init("nametest")); NameAttribute parsedNameAttribute = markupParser.ParseNameAttribute(); //Check Id Attribute Assert.AreEqual("nametest", parsedNameAttribute.GetName()); }
public SiteParser(TokenIterator tokenStream) : base(tokenStream) { //Create parsers markupParser = new MarkupParser(tokenStream); }
public void ParseExpressionArgumentTest() { //Parse tokens MarkupParser markupParser = new MarkupParser(Init("([1234,2345,3556,646])")); Markup markup = new Markup(); markupParser.ParseArguments(markup); //Test argument Assert.AreEqual(1, markup.GetArguments().Count); Argument[] arguments = (Argument[]) markup.GetArguments().ToArray(); Assert.AreEqual(typeof(ExpressionArgument), arguments[0].GetType()); //Test expression argument ExpressionArgument exprArgument = (ExpressionArgument)arguments[0]; Assert.AreEqual(typeof(ListExpression), exprArgument.GetExpression().GetType()); //Test list expression ListExpression listExpression = (ListExpression) exprArgument.GetExpression(); Assert.AreEqual(4, listExpression.GetExpressions().Count); }
public void ParseDesignatorWithAttributeTest() { //Parse tokens MarkupParser markupParser = new MarkupParser(Init("img@100%50")); Designator parsedDesignator = markupParser.ParseDesignator(); //Check designator Assert.AreEqual("img", parsedDesignator.GetIdentifier()); Assert.AreEqual(1, parsedDesignator.GetAttributes().Count); //Check attribute Attribute parsedAttribute = (Attribute) parsedDesignator.GetAttributes().Get(0); Assert.AreEqual(typeof(Width_HeightAttribute),parsedAttribute.GetType()); //Check Width_HeightAttribute contents Width_HeightAttribute attribute = (Width_HeightAttribute) parsedAttribute; Assert.AreEqual(100, attribute.GetWidth()); Assert.AreEqual(50, attribute.GetHeight()); }
public void ParseDefaultMarkupTest() { //Parse tokens MarkupParser markupParser = new MarkupParser(Init("(\"test\")")); Markup parsedMarkup = markupParser.ParseMarkup(); //Check attributes Assert.AreEqual(0, parsedMarkup.GetArguments().Count); }
public void ParseClassAttributeTest() { //Parse tokens MarkupParser markupParser = new MarkupParser(Init("classname")); ClassAttribute parsedClassAttribute = markupParser.ParseClassAttribute(); //Check Id Attribute Assert.AreEqual("classname", parsedClassAttribute.GetClass()); }
public void ParseCallNoArgsMarkupTest() { //Parse tokens MarkupParser markupParser = new MarkupParser(Init("home()")); Markup parsedMarkup = markupParser.ParseMarkup(); //Check markup Assert.AreEqual("home", parsedMarkup.GetDesignator().GetIdentifier()); //identifier check Assert.AreEqual(0, parsedMarkup.GetDesignator().GetAttributes().Count); //no attributes Assert.AreEqual(0, parsedMarkup.GetArguments().Count); //no arguments }
/// <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; }
/// <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 void ParseIdAttributeTest() { //Parse tokens MarkupParser markupParser = new MarkupParser(Init("testid")); IdAttribute parsedIdAttribute = markupParser.ParseIdAttribute(); //Check Id Attribute Assert.AreEqual("testid",parsedIdAttribute.GetId()); }