/// <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); }
/// <summary> /// Parser for MarkupStatement types /// </summary> /// <returns>Parsed Statement</returns> public Statement ParseMarkupStatement() { //Start parsing first markup part Markup firstMarkup = markupParser.ParseMarkup(); if (TokenStream.HasNext() && TokenStream.Peek(1).GetType() == TokenType.SYMBOL && TokenStream.Peek(1).GetValue().ToString() == ";") { //Just a single markup statement MarkupStatement markupStatement = new MarkupStatement(); markupStatement.SetMarkup(firstMarkup); //Skip ; token NextToken(";", "markup;", ';'); return(markupStatement); } else { //Get other markups NodeList markups = new NodeList(); markups.Add(firstMarkup); while (DetectNextIsMarkup()) { markups.Add(markupParser.ParseMarkup()); } //Determine statement type if (TokenStream.HasNext()) { if (TokenStream.Peek(1).GetType() == TokenType.EMBEDDING) { //Markup Embedding Statement MarkupEmbeddingStatement markupEmbedding = new MarkupEmbeddingStatement(); markupEmbedding.SetMarkups(markups); markupEmbedding.SetEmbedding(embeddingParser.ParseEmbedding()); //Skip ; token NextToken(";", "Markup+ Embedding;", ';'); return(markupEmbedding); } else if (TokenStream.Peek(1).GetValue().ToString() == ";") { //MarkupStatement MarkupMarkupStatement markupStatement = new MarkupMarkupStatement(); //Get last parsed markup from list and remove it from list Markup last = (Markup)markups.Get(markups.Count - 1); markups.Remove(markups.Count - 1); markupStatement.SetMarkup(last); markupStatement.SetMarkups(markups); //Skip ; token NextToken(";", "Markup+ Markup;", ';'); return(markupStatement); } else if (IsMarkupStatStatement()) { //MarkupStatStatement MarkupStatStatement markupStatStatement = new MarkupStatStatement(); markupStatStatement.SetMarkups(markups); markupStatStatement.SetStatement(ParseStatement()); return(markupStatStatement); } else if (IsMarkupExpressionStatement()) { //MarkupExpressionStatement MarkupExpressionStatement markupExpressionStatement = new MarkupExpressionStatement(); //Parse MarkupExpressionStatement markupExpressionStatement.SetMarkups(markups); markupExpressionStatement.SetExpression(expressionParser.ParseExpression()); //Skip ; token NextToken(";", "Markup+ Expression;", ';'); return(markupExpressionStatement); } else { //Unexpected token throw new UnexpectedToken("Markup Statement expected, but found:", CurrentToken.GetValue().ToString(), CurrentToken.GetLine()); } } else { throw new UnexpectedToken("Expected MarkupStatement type, but found:", CurrentToken.GetValue().ToString(), CurrentToken.GetLine()); } } }