Пример #1
0
 public virtual void Visit(MarkupStatStatement statement)
 {
     VisitSubNodes(statement);
 }
Пример #2
0
        /// <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());
                }
            }
        }