Ejemplo n.º 1
0
 public MathObjectFactory(string text)
 {
     foreach (var item in Config.Instance.IgnoreCommands)
     {
         text = text.Replace(item, "", StringComparison.Ordinal);
     }
     _source = text.ToTokenString();
 }
Ejemplo n.º 2
0
 private MathSequence(MathToken token)
 {
     List           = new ReadOnlyCollection <MathObject>(new[] { token });
     Main           = token.ToTokenString();
     Separator      = "";
     _toTokenString = Main;
     _toString      = _toTokenString.ToString();
     OriginalText   = token.OriginalText;
 }
Ejemplo n.º 3
0
 public MathSequence(MathToken token, Token leftBracket, Token rightBracket)
     : this(token)
 {
     LeftBracket    = leftBracket;
     RightBracket   = rightBracket;
     _toTokenString = ConstructorHelperBracket(leftBracket, Main, rightBracket);
     _toString      = _toTokenString.ToString();
     OriginalText   = _toTokenString.ToOriginalString().Trim();
 }
Ejemplo n.º 4
0
        /// <summary>
        /// 通常のコンストラクタ
        /// </summary>
        /// <param name="list">MathObjectを構成するMathObject列</param>
        public MathSequence(IList <MathObject> list, string separator = "", string originalText = "")
        {
            List      = new ReadOnlyCollection <MathObject>(list);
            Separator = separator;
            Main      = CreateMainTokenString(List, separator);

            _toTokenString = Main;
            _toString      = Main.ToString();
            OriginalText   = originalText.IsNullOrEmpty() ? Main.ToOriginalString().Trim() : originalText.Trim();
        }
Ejemplo n.º 5
0
        private TokenString ConstructorHelperBracket(Token left, TokenString main, Token right)
        {
            var list = new List <Token>();

            list.Add(left);
            list.AddRange(main.Tokens);
            list.Add(right);

            return(list.ToTokenString());
        }
Ejemplo n.º 6
0
 private TokenString CreateMainTokenString(ReadOnlyCollection <MathObject> list, string separator)
 {
     if (List.Count == 0)
     {
         return(TokenString.Empty);
     }
     else
     {
         return(TokenString.Join(separator, list.Select(x => x.ToTokenString())));
     }
 }
Ejemplo n.º 7
0
 public TokenString ToTokenString()
 {
     if (this.IsEmpty)
     {
         return(TokenString.Empty);
     }
     else
     {
         return(TokenString.Create(this));
     }
 }
Ejemplo n.º 8
0
        private MathSequence(MathSequence seq)
        {
            List         = seq.List;
            LeftBracket  = seq.LeftBracket;
            RightBracket = seq.RightBracket;
            Main         = seq.Main;
            Separator    = seq.Separator;
            Sub          = seq.Sub;
            Sup          = seq.Sup;
            _supFirst    = seq._supFirst;

            _toTokenString = seq._toTokenString;
            _toString      = seq._toString;
            OriginalText   = seq.OriginalText;
        }
Ejemplo n.º 9
0
        public MathSequence(MathToken token, Token supOrSub, Token left, MathObject math, Token right)
            : this(token)
        {
            if (supOrSub.Value == "^")
            {
                Sup       = math;
                _supFirst = true;
            }
            else
            {
                Sub = math;
            }

            _toTokenString = ConstructorHelperSupSub(_toTokenString, supOrSub, left, math.ToTokenString(), right);
            _toString      = _toTokenString.ToString();
            OriginalText   = _toTokenString.ToOriginalString().Trim();
        }
Ejemplo n.º 10
0
        private MathSequence(MathSequence seq, Token supOrSub, Token left, MathObject math, Token right)
            : this(seq)
        {
            if (supOrSub.Value == "^")
            {
                Sup = math;
                if (Sub == null)
                {
                    _supFirst = true;
                }
            }
            else
            {
                Sub = math;
            }

            _toTokenString = ConstructorHelperSupSub(_toTokenString, supOrSub, left, math.ToTokenString(), right);
            _toString      = _toTokenString.ToString();
            OriginalText   = _toTokenString.ToOriginalString().Trim();
        }
Ejemplo n.º 11
0
        private MathSequence(MathSequence seq, IList <MathObject> list, MathObject?sup, MathObject?sub)
            : this(seq)
        {
            if (list.Count == 0)
            {
                throw new InvalidOperationException($"{nameof(list)}が空です。");
            }

            List           = new ReadOnlyCollection <MathObject>(list);
            Main           = CreateMainTokenString(List, seq.Separator);
            _toTokenString = ConstructorHelperBracket(seq.LeftBracket, Main, seq.RightBracket);

            Sup = sup;
            Sub = sub;

            if (seq._supFirst)
            {
                if (sup != null)
                {
                    _toTokenString = ConstructorHelperSupSub(_toTokenString, Token.Circumflex, sup.ToTokenString());
                }
                if (sub != null)
                {
                    _toTokenString = ConstructorHelperSupSub(_toTokenString, Token.LowLine, sub.ToTokenString());
                }
            }
            else
            {
                if (sub != null)
                {
                    _toTokenString = ConstructorHelperSupSub(_toTokenString, Token.LowLine, sub.ToTokenString());
                }
                if (sup != null)
                {
                    _toTokenString = ConstructorHelperSupSub(_toTokenString, Token.Circumflex, sup.ToTokenString());
                }
            }

            _toString    = _toTokenString.ToString();
            OriginalText = _toTokenString.ToOriginalString().Trim();
        }
Ejemplo n.º 12
0
        public TokenString Add(TokenString other)
        {
            if (other.Tokens.Count == 0)
            {
                return(this);
            }

            var otherOrigins = other.Tokens.Select(x => x.Origin).ToArray();

            if (this.Tokens.Count > 0)
            {
                otherOrigins[0] = ' ' + otherOrigins[0];
            }

            var tokens = this._values.Concat(other._values).Zip(
                this.Tokens.Select(x => x.Origin).Concat(otherOrigins),
                (x, y) => new Token(x, y)
                ).ToArray();

            return(tokens.ToTokenString());
        }
Ejemplo n.º 13
0
 private TokenString ConstructorHelperSupSub(TokenString main, Token supOrSub, TokenString inBracket)
 {
     return(this.ConstructorHelperSupSub(main, supOrSub, Token.LeftCurlyBracket, inBracket, Token.RightCurlyBracket));
 }
Ejemplo n.º 14
0
 public static TokenString Create(Token token)
 {
     return(TokenString.Create(new[] { token }));
 }
Ejemplo n.º 15
0
 public MathObjectFactory(TokenString text)
 {
     _source = text;
 }
Ejemplo n.º 16
0
 /// <summary>
 /// Tokenのリストをトークン列にします。
 /// </summary>
 /// <param name="list">Tokenのリスト</param>
 /// <returns></returns>
 public static TokenString ToTokenString(this IList <Token> tokens)
 {
     return(TokenString.Create(tokens));
 }
Ejemplo n.º 17
0
 public MathToken(Token token)
 {
     Main         = TokenString.Create(token);
     OriginalText = token.Origin.Trim();
 }