Exemplo n.º 1
0
        public override void Parse(bool useDefaultAnalyzers = false)
        {
            NextToken();
            Root = NodeFactory.CreateRootNode();

            while (CurrentToken.Keyword != KeywordToken.EOF)
            {
                NextToken();
                // only container elements can be processed here
                switch (CurrentToken.Keyword)
                {
                case KeywordToken.Paragraph:
                    var a = new ParagraphStatementParser(parser);
                    Root.SetRootNode(a.Parse(CurrentToken));
                    break;

                case KeywordToken.Body:
                    var b        = new GenericElementNode(this, KeywordToken.Body);
                    var bodyNode = b.Parse(CurrentToken);
                    Root.SetRootNode(bodyNode);
                    break;
                }
            }

            if (useDefaultAnalyzers)
            {
                if (_analyzers == null)
                {
                    _analyzers = new ChildrenAnalyzer();
                    _analyzers.Use(new ElementToAttributeAnalyzer())
                    .Use(new AttributeCopierAnalyzer())
                    .Use(new SiblingsAnalyzer())
                    ;
                }
                else
                {
                    var elementAnalyzer = new ChildrenAnalyzer();
                    elementAnalyzer.Use(new ElementToAttributeAnalyzer())
                    .Use(new AttributeCopierAnalyzer())
                    .Use(new SiblingsAnalyzer())
                    .Use(_analyzers);
                    _analyzers = elementAnalyzer;
                }
            }
            if (_analyzers == null)
            {
                return;
            }
            Root.SetRootNode(_analyzers.Analyze(Root.Root));
        }
        public void ParseShouldLeaveCursorOneTokenPastTheParagraphBoundary()
        {
            var parserNode = new OoxmlNodeTd(new OoxmlScanner(
                                                 new Source(@"<w:body>
                                <w:p>
                                    <w:t>Testing this string</w:t>
                                </w:p>
                            </w:body>")
                                                 ));

            parserNode.NextToken();
            while (parserNode.CurrentToken.Keyword != KeywordToken.Paragraph)
            {
                parserNode.NextToken();
            }
            var sut = new ParagraphStatementParser(parserNode);

            sut.Parse(parserNode.CurrentToken);

            var currentToken = parserNode.CurrentToken;

            Assert.AreEqual(KeywordToken.Close, currentToken.Keyword);
            Assert.AreEqual("w:body", currentToken.Text);
        }