public void ThrowsUnExpectedTokenExceptionWhenProgramTokenIsNotFound()
        {
            tokensParser.SetupSequence(x => x.NextToken)
            .Returns(new IdentifierToken("Test"))
            .Returns(new EndOfFileToken());

            Action action = () => parser.Parse();

            action.Should().Throw <UnExpectedTokenException> ();
        }
Пример #2
0
 public Node Parse()
 {
     return(new Node("Pascal")
            .Add(_headingParser.Parse())
            .Add(_constantsDeclarationParser.Parse())
            .Add(_variablesDeclarationParser.Parse()));
 }
        public void Parse()
        {
            DomDocument         document           = new DomDocument();
            IBlockElementParser blockElementParser = new HeadingParser();

            blockElementParser.Parse(null, document,
                                     "h1(class#id){style}=(())). Heading 1\r\n\r\nh2.One more\r\n\r\nh3(class2). And one more\r\n\r\n");

            Assert.AreEqual(2, document.ChildElements.Count);

            Heading heading = document.ChildElements[0] as Heading;

            Assert.IsNotNull(heading);
            Assert.AreEqual(1, heading.Level);
            Assert.AreEqual("class", heading.Attributes.CssClass);
            Assert.AreEqual("id", heading.Attributes.ID);
            Assert.AreEqual("style", heading.Attributes.Style);
            Assert.AreEqual(BlockElementAlignment.Center, heading.Attributes.Alignment);
            Assert.AreEqual(2, heading.Attributes.LeftIndent);
            Assert.AreEqual(3, heading.Attributes.RightIndent);

            heading = document.ChildElements[1] as Heading;

            Assert.IsNotNull(heading);
            Assert.AreEqual(3, heading.Level);
            Assert.AreEqual("class2", heading.Attributes.CssClass);
        }
Пример #4
0
        private static RubyParser.TokenVisitor CreateTokenVisitor(FormattedTextBuffer buffer)
        {
            var visitor = new RubyParser.TokenVisitor
            {
                OnNormal = text =>
                {
                    var tokens2 = AnnotationParser.Parse(text);
                    foreach (var token2 in tokens2)
                    {
                        token2.Accept(new AnnotationParser.TokenVisitor
                        {
                            OnBody        = bodyText => buffer.Append(bodyText),
                            OnPlaceholder = () => buffer.Append(AozoraBunko.SpecialCharacters.ExternalCharacterPlaceholder),
                            OnAnnotation  = annotationText =>
                            {
                                //見出し
                                var headingText = HeadingParser.Parse(annotationText);
                                if (headingText != null)
                                {
                                    //TODO: 見出しレベル
                                    buffer.HeadingTitle = headingText;
                                    return;
                                }

                                //圏点
                                var emphasysDottedText = EmphasysDotsParser.Parse(annotationText);
                                if (emphasysDottedText != null)
                                {
                                    buffer.EmphasysDot(buffer.Length - emphasysDottedText.Length, buffer.Length);
                                    return;
                                }

                                //TODO: その他の注記
                            }
                        });
                    }
                    ;
                },
                OnRuby = (baseText, rubyText) =>
                {
                    buffer.Append(baseText);
                    buffer.Ruby(buffer.Length - baseText.Length, buffer.Length, rubyText);
                }
            };

            return(visitor);
        }