Esempio n. 1
0
        public virtual bool RemoveChild(Int32 Index, IList <S4JToken> NewChilds = null)
        {
            if (Index < 0)
            {
                return(false);
            }

            S4JToken prevChild = Index > 0 ? Children[Index - 1] : null;
            S4JToken nextChild = Index + 1 < Children.Count ? Children[Index + 1] : null;

            this.Children.RemoveAt(Index);

            if (prevChild != null)
            {
                prevChild.NextToken = nextChild;
            }

            if (nextChild != null)
            {
                nextChild.PrevToken = prevChild;
            }

            if (NewChilds != null)
            {
                foreach (S4JToken newChild in NewChilds)
                {
                    InsertChildToToken(Index, newChild);
                    Index++;
                }
            }

            return(true);
        }
Esempio n. 2
0
        public virtual void OnPop()
        {
            // CalculateIsSingleKey(this.Parent, this);

            S4JToken lastChild = this.Children.LastOrDefault();

            if (lastChild is S4JTokenTextValue txtVal)
            {
                txtVal.Commit();
            }
        }
Esempio n. 3
0
        public virtual void MarkLastChildAsObjectKey()
        {
            S4JToken lastChild = this.Children.LastOrDefault();

            if (lastChild == null)
            {
                return;
            }

            lastChild.MarkAsObjectKey();
        }
Esempio n. 4
0
        public virtual void AppendCharsToToken(IList <Char> Chars)
        {
            S4JToken lastChild = this.Children.LastOrDefault();

            if (!(lastChild is S4JTokenTextValue) || lastChild.IsCommited)
            {
                lastChild = new S4JTokenTextValue();
                AddChildToToken(lastChild);
            }
            lastChild.AppendCharsToToken(Chars);
        }
Esempio n. 5
0
        public virtual void AddChildToToken(S4JToken Child)
        {
            S4JToken lastChild = Children.LastOrDefault();

            if (lastChild != null)
            {
                lastChild.NextToken = Child;
            }
            Child.PrevToken = lastChild;
            Children.Add(Child);
        }
Esempio n. 6
0
        public virtual S4JToken Clone()
        {
            S4JToken newToken = (S4JToken)this.MemberwiseClone();

            newToken.State     = newToken.State?.Clone();
            newToken.Tags      = new Dictionary <string, object>(this.Tags);
            newToken.Parent    = null;
            newToken.PrevToken = null;
            newToken.NextToken = null;
            newToken.Children  = newToken.Children.Select(i => { S4JToken token = i.Clone(); token.Parent = newToken; return(token); }).ToList();
            // newToken.Parent = newToken.Parent?.Clone();
            return(newToken);
        }
Esempio n. 7
0
        public virtual void InsertChildToToken(Int32 Index, S4JToken Child)
        {
            S4JToken prevChild = Index > 0 ? Children[Index - 1] : null;
            S4JToken nextChild = Index + 1 < Children.Count  ? Children[Index + 1] : null;

            Children.Insert(Index, Child);

            if (prevChild != null)
            {
                prevChild.NextToken = Child;
            }

            Child.PrevToken = prevChild;
            Child.NextToken = nextChild;

            if (nextChild != null)
            {
                nextChild.PrevToken = Child;
            }
        }
Esempio n. 8
0
        public virtual void Commit()
        {
            // IsCommited = true;

            S4JToken lastChild = this.Children.LastOrDefault();

            if (lastChild is S4JTokenTextValue txtVal)
            {
                txtVal.Commit();
            }

            CalculateIsSingleKey(this, lastChild);

            for (var i = 0; i < this.Children.Count; i++)
            {
                S4JToken token = this.Children[i];
                if (token?.State?.StateType != EStateType.S4J_TAG)
                {
                    continue;
                }

                if (token.NextToken != null)
                {
                    foreach (var tagKV in token.Tags)
                    {
                        token.NextToken.Tags[tagKV.Key] = tagKV.Value;
                    }
                }

                RemoveChild(i);
                i--;
            }


            //CalculateIsSingleKey(this, lastChild);
            // CalculateIsSingleKey(this.Parent, this);
        }
Esempio n. 9
0
        private void CalculateIsSingleKey(S4JToken Token, S4JToken Item)
        {
            if (Item == null)
            {
                return;
            }

            // ustalenie IsSingleKey = true
            // próba określenia czy token jest w obiekcie
            // oraz czy jest 'kluczem bez wartosci'
            if (Token is S4JTokenObject ||
                Token is S4JTokenParameters ||
                Token is S4JTokenTag)
            {
                S4JToken prevChild = null;
                foreach (S4JToken child in Token.Children)
                {
                    if (!child.IsObjectKey)
                    {
                        if (prevChild == null ||
                            prevChild.IsObjectKey == false)
                        {
                            child.MarkAsSingleObjectKey();
                        }

                        else if (prevChild != null &&
                                 prevChild.IsObjectKey == true)
                        {
                            child.MarkAsObjectValue();
                        }
                    }

                    prevChild = child;
                }
            }
        }
Esempio n. 10
0
        public virtual bool RemoveChild(S4JToken OldChild, IList <S4JToken> NewChilds)
        {
            Int32 childIndex = IndexOfChild(OldChild);

            return(RemoveChild(childIndex, NewChilds));
        }
Esempio n. 11
0
        public virtual Int32 IndexOfChild(S4JToken OldChild)
        {
            Int32 childIndex = this.Children.IndexOf(OldChild);

            return(childIndex);
        }
Esempio n. 12
0
        public S4JToken To_token(S4JState State)
        {
            S4JToken result = null;

            if (State != null)
            {
                if (State.StateType == EStateType.S4J)
                {
                    result = new S4JTokenRoot();
                }

                if (State.StateType == EStateType.S4J_ARRAY)
                {
                    result = new S4JTokenArray();
                }

                if (State.StateType == EStateType.S4J_COMMENT)
                {
                    result = new S4JTokenComment();
                }

                if (State.StateType == EStateType.S4J_OBJECT)
                {
                    result = new S4JTokenObject();
                }

                if (State.StateType == EStateType.S4J_TAG)
                {
                    result = new S4JTokenTag();
                }

                if (State.StateType == EStateType.S4J_PARAMETERS)
                {
                    result = new S4JTokenParameters();
                }

                if (State.StateType == EStateType.S4J_QUOTATION)
                {
                    result = new S4JTokenQuotation();
                }

                if (State.StateType == EStateType.S4J_TEXT_VALUE)
                {
                    result = new S4JTokenTextValue();
                }

                //if (State.StateType == EStateType.S4J_SEPARATOR)
                //    result = new JsArray();

                //if (State.StateType == EStateType.S4J_SIMPLE_VALUE)
                //    result = new S4JTokenSimpleValue();

                if (State.StateType == EStateType.S4J_OBJECT_CONTENT)
                {
                    result = new S4JTokenObjectContent();
                }

                //if (State.StateType == EStateType.S4J_VALUE_DELIMITER)
                //    result = new JsArray();

                if (State.StateType == EStateType.FUNCTION)
                {
                    result = new S4JTokenFunction()
                    {
                        Evaluator = (State as S4JStateFunction)?.Evaluator
                    }
                }
                ;

                if (State.StateType == EStateType.FUNCTION_COMMENT)
                {
                    result = new S4JTokenFunctionComment();
                }

                if (State.StateType == EStateType.FUNCTION_BRACKETS)
                {
                    result = new S4JTokenFunctionBracket();
                }

                if (State.StateType == EStateType.FUNCTION_QUOTATION)
                {
                    result = new S4JTokenFunctionQuotation();
                }
            }

            if (result != null)
            {
                result.State = State;
            }

            return(result);
        }
    }
Esempio n. 13
0
 public override void AddChildToToken(S4JToken Child)
 {
     base.AddChildToToken(Child);
 }
Esempio n. 14
0
 public override void AddChildToToken(S4JToken Child)
 {
 }
Esempio n. 15
0
 public override void AddChildToToken(S4JToken Child)
 {
     // Value = Child;
 }