コード例 #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() }));
        }
コード例 #2
0
ファイル: AnnotationParser.cs プロジェクト: karak/Geovanni
 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() });
 }
コード例 #3
0
ファイル: RubyParser.cs プロジェクト: karak/Geovanni
        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);
            }
        }
コード例 #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));
            }
        }
コード例 #5
0
        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()));
        }
コード例 #6
0
 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());
 }
コード例 #7
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() }
                       ));
        }
コード例 #8
0
 void IExchangableTextVisitor.Letter(UChar letter)
 {
     if (_inRuby)
     {
         _rubyBaseText.Append(letter);
     }
     else
     {
         _builder.Text(letter);
     }
 }
コード例 #9
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())));
        }
コード例 #10
0
 public static String ExtractWord(int n, String s, ACharArray wordDelims)
 {
     using (var sb = new UStringBuilder())
     {
         var i = WordPosition(n, s, wordDelims);
         if (i == -1)
         {
             return(sb.ToString());
         }
         /* find the end of the current word */
         while (i < s.Length && !(wordDelims.Contains(s[i])))
         {
             /* add the I'th character to result */
             sb.Append(s[i]);
             i++;
         }
         return(sb.ToString());
     }
 }
コード例 #11
0
ファイル: ParagraphBuilder.cs プロジェクト: karak/Geovanni
            private void _latinMode_Flush(object sender, LatinMode.FlushEventArgs e)
            {
                var wordBuffer = new UStringBuilder(16);
                var latinText  = e.LatinText;

                foreach (var c in e.LatinText)
                {
                    if (c.CodePoint == (int)' ')
                    {
                        FlushLatinWord(wordBuffer);

                        _buffer.Add(new LatinInterwordSpace(new GlueProperty(0.5F * _currentZwSize, 0.2F * _currentZwSize, 0.25F * _currentZwSize)));
                    }
                    else
                    {
                        wordBuffer.Append(c);
                    }
                    //TODO: Sentence space: after period except after some words "Mr", "Mrs"
                }
                FlushLatinWord(wordBuffer);
            }
コード例 #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)));
        }
コード例 #13
0
ファイル: ParagraphBuilder.cs プロジェクト: karak/Geovanni
            private void _latinMode_Flush(object sender, LatinMode.FlushEventArgs e)
            {
                var wordBuffer = new UStringBuilder(16);
                var latinText = e.LatinText;
                foreach (var c in e.LatinText)
                {
                    if (c.CodePoint == (int)' ')
                    {
                        FlushLatinWord(wordBuffer);

                        _buffer.Add(new LatinInterwordSpace(new GlueProperty(0.5F * _currentZwSize, 0.2F * _currentZwSize, 0.25F * _currentZwSize)));
                    }
                    else
                    {
                        wordBuffer.Append(c);
                    }
                    //TODO: Sentence space: after period except after some words "Mr", "Mrs"
                }
                FlushLatinWord(wordBuffer);
            }
コード例 #14
0
ファイル: AnnotationParser.cs プロジェクト: karak/Geovanni
        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() }
            );
        }
コード例 #15
0
ファイル: RubyParser.cs プロジェクト: karak/Geovanni
 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()));
 }
コード例 #16
0
ファイル: FormattedTextBuffer.cs プロジェクト: karak/Geovanni
 public void Append(UString text)
 {
     _textBuffer.Append(text);
 }
コード例 #17
0
ファイル: RubyParser.cs プロジェクト: karak/Geovanni
 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));
 }