Ejemplo n.º 1
0
        public static Functor Create(string name, string functor)
        {
            var nameObj    = new MathObjectFactory(name).CreateSingle();
            var functorObj = new MathObjectFactory(functor).CreateSingle();

            return(new Functor(nameObj, functorObj));
        }
Ejemplo n.º 2
0
        public static Functor?Create(string text)
        {
            var m = _construct.Match(text);

            if (m.Success)
            {
                var math = new MathObjectFactory(m.Groups[1].Value).Create().ToArray();
                if (math.Length == 2)
                {
                    return(new Functor(math[0], math[1]));
                }
            }
            return(null);
        }
Ejemplo n.º 3
0
        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);
            }
        }