Beispiel #1
0
        private static LazyList <IToken> ParseAnnotation(IEnumerator <UChar> inputStream)
        {
            int depth  = 0; //入れ子を無視する
            var buffer = new UStringBuilder(128);

            while (inputStream.MoveNext())
            {
                if (inputStream.Current == SpecialCharacters.AnnotationCloseBracket)
                {
                    if (depth > 0)
                    {
                        --depth;
                        buffer.Append(inputStream.Current);
                    }
                    else
                    {
                        return(LazyList <IToken> .New(
                                   new AnnotationToken { Text = buffer.ToUString() },
                                   () => ParseRoot(inputStream)
                                   ));
                    }
                }
                else
                {
                    if (inputStream.Current == SpecialCharacters.AnnotationOpenBracket)
                    {
                        ++depth;
                    }
                    buffer.Append(inputStream.Current);
                }
            }
            //syntax-error
            return(LazyList <IToken> .New(new AnnotationToken { Text = buffer.ToUString() }));
        }
Beispiel #2
0
 private static LazyList<IToken> ParseAnnotation(IEnumerator<UChar> inputStream)
 {
     int depth = 0; //入れ子を無視する
     var buffer = new UStringBuilder(128);
     while (inputStream.MoveNext())
     {
         if (inputStream.Current == SpecialCharacters.AnnotationCloseBracket)
         {
             if (depth > 0)
             {
                 --depth;
                 buffer.Append(inputStream.Current);
             }
             else
             {
                 return LazyList<IToken>.New(
                     new AnnotationToken { Text = buffer.ToUString() },
                     () => ParseRoot(inputStream)
                 );
             }
         }
         else
         {
             if (inputStream.Current == SpecialCharacters.AnnotationOpenBracket)
             {
                 ++depth;
             }
             buffer.Append(inputStream.Current);
         }
     }
     //syntax-error
     return LazyList<IToken>.New(new AnnotationToken { Text = buffer.ToUString() });
 }
Beispiel #3
0
        private static LazyList <Token> ParseNormal(IEnumerator <UChar> inputStream)
        {
            UStringBuilder _textFragment    = new UStringBuilder(1024);
            UStringBuilder _tentativeParent = new UStringBuilder(16);
            ParentType     type             = _none;

            while (inputStream.MoveNext())
            {
                var c = inputStream.Current;

                if (c == SpecialCharacters.BeforeRubyInitiater)
                {
                    _textFragment.Append(_tentativeParent.ToUString());
                    _tentativeParent.Clear();
                    var token = new NormalToken(_textFragment.ToUString());
                    _textFragment.Clear();
                    _textFragment    = null;
                    _tentativeParent = null;
                    return(LazyList <Token> .New(token, () => ParseRubyParent(inputStream)));
                }
                else if (c == SpecialCharacters.RubyOpen)
                {
                    var token = new NormalToken(_textFragment.ToUString());
                    _textFragment.Clear();
                    _textFragment = null;
                    UString parent = _tentativeParent.ToUString();
                    _tentativeParent.Clear();
                    _tentativeParent = null;
                    return(LazyList <Token> .New(token, () => ParseRubyText(inputStream, parent)));
                }
                else
                {
                    //暫定親字の継続検証
                    if (type.IsContinuous(c))
                    {
                        _tentativeParent.Append(c);
                    }
                    else
                    {
                        _textFragment.Append(_tentativeParent.ToUString());
                        _tentativeParent.Clear();
                        _tentativeParent.Append(c);
                        type = RubyParser.ClassifyParentType(c);
                    }
                }
            }

            {
                _textFragment.Append(_tentativeParent.ToUString());
                _tentativeParent.Clear();
                var token = new NormalToken(_textFragment.ToUString());
                return(LazyList <Token> .New(token));
            }
        }
Beispiel #4
0
        private static LazyList<Token> ParseNormal(IEnumerator<UChar> inputStream)
        {
            UStringBuilder _textFragment = new UStringBuilder(1024);
            UStringBuilder _tentativeParent = new UStringBuilder(16);
            ParentType type = _none;

            while (inputStream.MoveNext())
            {
                var c = inputStream.Current;

                if (c == SpecialCharacters.BeforeRubyInitiater)
                {
                    _textFragment.Append(_tentativeParent.ToUString());
                    _tentativeParent.Clear();
                    var token = new NormalToken(_textFragment.ToUString());
                    _textFragment.Clear();
                    _textFragment = null;
                    _tentativeParent = null;
                    return LazyList<Token>.New(token, () => ParseRubyParent(inputStream));
                }
                else if (c == SpecialCharacters.RubyOpen)
                {
                    var token = new NormalToken(_textFragment.ToUString());
                    _textFragment.Clear();
                    _textFragment = null;
                    UString parent = _tentativeParent.ToUString();
                    _tentativeParent.Clear();
                    _tentativeParent = null;
                    return LazyList<Token>.New(token, () => ParseRubyText(inputStream, parent));
                }
                else
                {
                    //暫定親字の継続検証
                    if (type.IsContinuous(c))
                    {
                        _tentativeParent.Append(c);
                    }
                    else
                    {
                        _textFragment.Append(_tentativeParent.ToUString());
                        _tentativeParent.Clear();
                        _tentativeParent.Append(c);
                        type = RubyParser.ClassifyParentType(c);
                    }
                }
            }

            {
                _textFragment.Append(_tentativeParent.ToUString());
                _tentativeParent.Clear();
                var token = new NormalToken(_textFragment.ToUString());
                return LazyList<Token>.New(token);
            }
        }
        private static LazyList <UChar> ParseAnnotation(IEnumerator <UChar> inputStream)
        {
            var content = new UStringBuilder(64);

            while (inputStream.MoveNext())
            {
                var c = inputStream.Current;
                if (c == SpecialCharacters.AnnotationCloseBracket)
                {
                    string replaced;
                    if (ExternalCharacterDictionary.DoesMatch(content.ToString(), out replaced))
                    {
                        content.Clear();
                        return(Seq(new UString(replaced).ToArray(), () => ParseNormal(inputStream)));
                    }
                    else
                    {
                        content.Clear();
                        return(Seq(new UChar[] { UnreplacedPlaceholder }, () => ParseNormal(inputStream)));
                    }
                }
                else
                {
                    content.Append(c);
                }
            }
            content.Clear();
            return(Seq(content.ToUString().ToArray()));
        }
Beispiel #6
0
        private static LazyList <IToken> ParseRoot(IEnumerator <UChar> inputStream)
        {
            var buffer = new UStringBuilder(512);

            while (inputStream.MoveNext())
            {
                UChar c1 = inputStream.Current;
                if (c1 == SpecialCharacters.AnnotationOpenBracket)
                {
                    if (inputStream.MoveNext())
                    {
                        UChar c2 = inputStream.Current;
                        if (c2 == SpecialCharacters.AnnotationInitiatorChar)
                        {
                            return(LazyList <IToken> .New(
                                       new BodyToken { Text = buffer.ToUString() },
                                       () => ParseAnnotation(inputStream)
                                       ));
                        }
                        else
                        {
                            buffer.Append(c1);
                            buffer.Append(c2);
                        }
                    }
                    else
                    {
                        buffer.Append(c1);
                    }
                }
                else if (c1 == AnnotationParser._externalCharacterPlaceholder)
                {
                    return(LazyList <IToken> .New(
                               new PlaceholderToken(),
                               () => ParseRoot(inputStream)
                               ));
                }
                else
                {
                    buffer.Append(c1);
                }
            }

            return(LazyList <IToken> .New(
                       new BodyToken { Text = buffer.ToUString() }
                       ));
        }
Beispiel #7
0
        private static LazyList <Token> ParseRubyParent(IEnumerator <UChar> inputStream)
        {
            var parent = new UStringBuilder(16);

            while (inputStream.MoveNext())
            {
                var c = inputStream.Current;
                if (c == SpecialCharacters.RubyOpen)
                {
                    return(ParseRubyText(inputStream, parent.ToUString()));
                }
                else
                {
                    parent.Append(c);
                }
            }
            //WARNING: syntax-error
            return(LazyList <Token> .New(new NormalToken(parent.ToUString())));
        }
Beispiel #8
0
 private void FlushLatinWord(UStringBuilder wordBuffer)
 {
     if (wordBuffer.Length > 0)
     {
         var word   = wordBuffer.ToUString();
         var length = _latinMetric.MeasureText(word.String);
         this.AppendObject(new LatinWord(word, length));
         wordBuffer.Clear();
     }
 }
Beispiel #9
0
            void IExchangableTextVisitor.RubyEnd()
            {
                if (!_inRuby)
                {
                    throw new Exception("Not in ruby text yet");
                }

                _builder.TextWithGroupRuby(_rubyBaseText.ToUString(), _rubyText);

                _rubyBaseText.Clear();
                _rubyText = null;
                _inRuby   = false;
            }
Beispiel #10
0
        void IExchangableText.Accept(IExchangableTextVisitor visitor)
        {
            if (_headingTitle != null)
            {
                visitor.Heading(1, _headingTitle);
            }

            int index = 0;

            foreach (var letter in _textBuffer.ToUString())
            {
                VisitAt(index, visitor);
                visitor.Letter(letter);
                ++index;
            }
            VisitAt(index, visitor);
        }
Beispiel #11
0
        private static LazyList<IToken> ParseRoot(IEnumerator<UChar> inputStream)
        {
            var buffer = new UStringBuilder(512);
            while (inputStream.MoveNext())
            {
                UChar c1 = inputStream.Current;
                if (c1 == SpecialCharacters.AnnotationOpenBracket)
                {
                    if (inputStream.MoveNext())
                    {
                        UChar c2 = inputStream.Current;
                        if (c2 == SpecialCharacters.AnnotationInitiatorChar)
                        {
                            return LazyList<IToken>.New(
                                new BodyToken { Text = buffer.ToUString() },
                                () => ParseAnnotation(inputStream)
                            );
                        }
                        else
                        {
                            buffer.Append(c1);
                            buffer.Append(c2);
                        }
                    }
                    else
                    {
                        buffer.Append(c1);
                    }
                }
                else if (c1 == AnnotationParser._externalCharacterPlaceholder)
                {
                    return LazyList<IToken>.New(
                        new PlaceholderToken(),
                        () => ParseRoot(inputStream)
                    );
                } else{
                    buffer.Append(c1);
                }
            }

            return LazyList<IToken>.New(
                new BodyToken { Text = buffer.ToUString() }
            );
        }
Beispiel #12
0
        private static LazyList <Token> ParseRubyText(IEnumerator <UChar> inputStream, UString rubyParent)
        {
            var text = new UStringBuilder(32);

            while (inputStream.MoveNext())
            {
                var c = inputStream.Current;
                if (c == SpecialCharacters.RubyClose)
                {
                    var token = new RubyToken(rubyParent, text.ToUString());
                    return(LazyList <Token> .New(token, () => ParseNormal(inputStream)));
                }
                else
                {
                    text.Append(c);
                }
            }
            //WARNING: syntax-error
            //         dispose incomplete ruby
            return(LazyList <Token> .New(new NormalToken(rubyParent)));
        }
 private static LazyList<UChar> ParseAnnotation(IEnumerator<UChar> inputStream)
 {
     var content = new UStringBuilder(64);
     while (inputStream.MoveNext())
     {
         var c = inputStream.Current;
         if (c == SpecialCharacters.AnnotationCloseBracket)
         {
            string replaced;
             if (ExternalCharacterDictionary.DoesMatch(content.ToString(), out replaced))
             {
                 content.Clear();
                 return Seq(new UString(replaced).ToArray(), () => ParseNormal(inputStream));
             }
             else
             {
                 content.Clear();
                 return Seq(new UChar[] { UnreplacedPlaceholder }, () => ParseNormal(inputStream));
             }
         }
         else
         {
             content.Append(c);
         }
     }
     content.Clear();
     return Seq(content.ToUString().ToArray());
 }
Beispiel #14
0
 private static LazyList<Token> ParseRubyParent(IEnumerator<UChar> inputStream)
 {
     var parent = new UStringBuilder(16);
     while (inputStream.MoveNext())
     {
         var c = inputStream.Current;
         if (c == SpecialCharacters.RubyOpen)
         {
             return ParseRubyText(inputStream, parent.ToUString());
         }
         else
         {
             parent.Append(c);
         }
     }
     //WARNING: syntax-error
     return LazyList<Token>.New(new NormalToken(parent.ToUString()));
 }
Beispiel #15
0
 private static LazyList<Token> ParseRubyText(IEnumerator<UChar> inputStream, UString rubyParent)
 {
     var text = new UStringBuilder(32);
     while (inputStream.MoveNext())
     {
         var c = inputStream.Current;
         if (c == SpecialCharacters.RubyClose)
         {
             var token = new RubyToken(rubyParent, text.ToUString());
             return LazyList<Token>.New(token, () => ParseNormal(inputStream));
         }
         else
         {
             text.Append(c);
         }
     }
     //WARNING: syntax-error
     //         dispose incomplete ruby
     return LazyList<Token>.New(new NormalToken(rubyParent));
 }
Beispiel #16
0
 private void FlushLatinWord(UStringBuilder wordBuffer)
 {
     if (wordBuffer.Length > 0)
     {
         var word = wordBuffer.ToUString();
         var length = _latinMetric.MeasureText(word.String);
         this.AppendObject(new LatinWord(word, length));
         wordBuffer.Clear();
     }
 }