Exemple #1
0
        public bool IsSameTypeMain(MathObject other, IDictionary <string, MathObject> parameters, string key)
        {
            if (other is MathToken)
            {
                if (parameters.ContainsKey(key) && !parameters[key].Equals(other))
                {
                    return(false);
                }
                else
                {
                    parameters[key] = other;
                }
            }
            else if (other is MathSequence math)
            {
                if (math.Sup == null && math.Sub == null &&
                    (math.LeftBracket.Value == "(" || math.LeftBracket.Value == "{"))
                {
                    math = new MathSequence(math.List, math.Separator, math.Main.ToOriginalString());
                }

                if (parameters.ContainsKey(key) && !parameters[key].Equals(math))
                {
                    return(false);
                }
                else
                {
                    parameters[key] = math;
                }
            }

            return(true);
        }
Exemple #2
0
 public override bool IsSameType(MathObject other, IDictionary <string, MathObject> parameters)
 {
     return(other switch
     {
         MathSequence seq => IsSameType_Sequence(seq, parameters),
         MathToken token => IsSameType_Token(token, parameters),
         _ => false,
     });
Exemple #3
0
        private MathSequence(MathSequence seq, Token leftBracket, Token rightBracket)
            : this(seq)
        {
            LeftBracket  = leftBracket;
            RightBracket = rightBracket;

            _toTokenString = ConstructorHelperBracket(leftBracket, Main, rightBracket);
            _toString      = _toTokenString.ToString();
            OriginalText   = _toTokenString.ToOriginalString().Trim();
        }
 private MathObject ReturnMathObject()
 {
     if (_sequence.Count == 1)
     {
         return(_sequence[0]);
     }
     else
     {
         var math = new MathSequence(_sequence, "", _original.ToString());
         return(math);
     }
 }
Exemple #5
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;
        }
        private void BracketMode(Token token)
        {
            // _bracketCount > 0
            if (_bracketCount == 0)
            {
                throw new InvalidOperationException("_bracketCount > 0 でないのにBracketModeに来るのはおかしい");
            }

            _original.Append(token.Origin);

            if (token.IsOpenBracket())
            {
                _bracketCount++;
            }
            else if (token.IsCloseBracket())
            {
                _bracketCount--;
            }

            if (_bracketCount == 0) // 全ての括弧が閉じられた場合
            {
                // 括弧の中身でMathObjectを生成
                var left       = _inBracket.First();
                var main       = _inBracket.Skip(1).ToArray().ToTokenString();
                var mathObject = new MathObjectFactory(main).CreateSingle();

                // 添え字でない場合は括弧をMathObjectに含める
                if (_scriptToken.IsEmpty)
                {
                    if (mathObject is MathSequence m)
                    {
                        if (!m.IsSimple)
                        {
                            mathObject = new MathSequence(new MathObject[] { mathObject }, "", main.ToOriginalString());
                        }
                    }
                    mathObject = mathObject.SetBracket(left, token);
                }

                AddSequence(mathObject, left, token);
            }
            else
            {
                _inBracket.Add(token);
            }
        }
Exemple #7
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();
        }
Exemple #8
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();
        }