Exemple #1
0
        internal void ChangeValues(IDictionary <string, string> dictionary)
        {
            for (int i = 0; i < _values.Count; ++i)
            {
                CBaseValue old_val = _values[i];
                string     val     = old_val.ToString();
                string     new_val;
                if (dictionary.TryGetValue(val, out new_val))
                {
                    ETokenType tt = Utils.GetTokenType(new_val);
                    var        t  = new CToken(tt, new_val, old_val.Position);

                    CBaseValue be = CBaseValue.CreateBaseValue(this, t); //_values + 1 to end
                    _values[i] = _values[_values.Count - 1];             //insert to need pos

                    old_val.SetParent(null);                             //_values count same
                    _values.RemoveAt(_values.Count - 1);                 //_values - 1
                }
            }

            for (int i = 0; i < _keys.Count; ++i)
            {
                _keys[i].ChangeValues(dictionary);
            }
        }
Exemple #2
0
        void BuildTokens(CSentense sentense, ILogger inLoger)
        {
            CToken[] tokens = CTokenFinder.Instance.GetTokens(sentense);

            if (tokens.Length > 0 && tokens[tokens.Length - 1].TokenType == ETokenType.Comment)
            {
                _tokens = new CToken[tokens.Length - 1];
                Array.Copy(tokens, _tokens, _tokens.Length);
                _comments = tokens[tokens.Length - 1];
            }
            else
            {
                _tokens = tokens;
            }

            _error_count += Check(inLoger);
        }
Exemple #3
0
        Tuple <CToken, int> FindComments(CSentense inSentense)
        {
            if (string.IsNullOrEmpty(inSentense.Text))
            {
                return(new Tuple <CToken, int>(null, 0));
            }

            CToken comment  = null;
            string comm_str = GetTokenString(ETokenType.Comment);
            int    pos      = inSentense.Text.IndexOf(comm_str);

            if (pos == -1)
            {
                return(new Tuple <CToken, int>(null, 0));
            }

            string scomm = inSentense.Text.Substring(pos + comm_str.Length);

            comment = new CToken(ETokenType.Comment, scomm, inSentense.LineNumber, pos + inSentense.Rank * TAB_LENGTH);

            return(new Tuple <CToken, int>(comment, pos));
        }
Exemple #4
0
        internal void AddTokenTail(CTokenLine line, ILogger inLoger)
        {
            if (line.Comments != null)
            {
                AddComments(line.Comments.Text);
            }

            if (line.IsTailEmpty)
            {
                return;
            }

            for (int i = 0; i < line.TailLength; i++)
            {
                CToken t = line.Tail[i];

                CBaseElement be = CBaseValue.CreateBaseValue(this, t);

                if (be == null)
                {
                    inLoger.LogError(EErrorCode.WrongTokenInTail, t);
                }
            }
        }
Exemple #5
0
        void FindHeadAndTail(ILogger inLoger)
        {
            if (_tokens.Length == 0)
            {
                return;
            }

            if (_tokens[0].TokenType == ETokenType.Sharp)
            {
                return;
            }

            if (_tokens[0].TokenType == ETokenType.RecordDivider)
            {
                return;
            }

            int    cur_index = 0;
            CToken toc       = _tokens[cur_index];

            if (toc.TokenType == ETokenType.AddKey)
            {
                _addition_mode = EKeyAddingMode.Add;
                cur_index++;
            }
            else if (toc.TokenType == ETokenType.OverrideKey)
            {
                _addition_mode = EKeyAddingMode.Override;
                cur_index++;
            }
            //if (toc.TokenType == ETokenType.OverrideKey)
            //{
            //    _addition_mode = EKeyAddingMode.Override;
            //    cur_index++;
            //}

            int token_count = _tokens.Length - cur_index;

            if (cur_index == 0 && token_count == 1 && Utils.IsDataType(toc.TokenType))
            {//written only one value
                _tail = new CToken[1] {
                    _tokens[0]
                };
                return;
            }

            if (token_count < 2)
            {
                inLoger.LogError(EErrorCode.CantResolveLine, this);
                return;
            }

            toc = _tokens[cur_index + 1];
            if (toc.TokenType == ETokenType.Colon)
            {
                _head      = _tokens[cur_index];
                cur_index += 2;
                if (!Utils.IsDataType(_head.TokenType))
                {
                    inLoger.LogError(EErrorCode.StrangeHeadType, _head);
                }
            }
            else if (_tokens[0].TokenType == ETokenType.Colon)
            {
                IsNewArrayLine = true;
            }

            List <CToken> lst = new List <CToken>();

            for (int i = cur_index; i < _tokens.Length; ++i)
            {
                if (Utils.IsDataType(_tokens[i].TokenType))
                {
                    lst.Add(_tokens[i]);
                }
            }
            _tail = lst.ToArray();
        }
Exemple #6
0
        public CToken[] GetTokens(CSentense inSentense)
        {
            if (string.IsNullOrEmpty(inSentense.Text))
            {
                return(new CToken[0]);
            }

            string line = inSentense.Text;
            Tuple <CToken, int> comment_pos = FindComments(inSentense);
            CToken comment = comment_pos.Item1;

            if (comment != null)
            {
                line = line.Substring(0, comment_pos.Item2).TrimEnd(' ').TrimEnd('\t');
            }

            List <CToken> lst = new List <CToken>();

            int tab_shift = inSentense.Rank * TAB_LENGTH;
            int lnum      = inSentense.LineNumber;

            int  world_pos = 0;
            int  world_len = 0;
            int  i         = 0;
            bool open_qute = false;

            while (i < line.Length)
            {
                bool quote = line[i] == '"';
                if (quote)
                {
                    open_qute = !open_qute;
                }

                bool           space = false;
                ITokenTemplate tmp   = null;
                if (!open_qute)
                {
                    space = line[i] == ' ';
                    tmp   = _templates.Find(tt => tt.CheckPassed(line, i));
                }

                bool world_break = space || quote || tmp != null;
                if (world_break)
                {
                    world_len = i - world_pos;
                    if (world_len > 0)
                    {
                        AddWorld(i, world_pos, line, lst, lnum, tab_shift);
                    }

                    if (tmp == null)
                    {
                        world_pos = i + 1;
                    }
                    else
                    {
                        world_pos = i + tmp.GetText().Length;
                    }
                }

                if (tmp == null)
                {
                    i++;
                }
                else
                {
                    lst.Add(new CToken(tmp.GetTokenType(), tmp.GetText(), inSentense.LineNumber, i + inSentense.Rank * TAB_LENGTH));
                    i += tmp.GetText().Length;
                }
            }

            world_len = i - world_pos;
            if (world_len > 0)
            {
                AddWorld(i, world_pos, line, lst, lnum, tab_shift);
            }

            if (comment != null)
            {
                lst.Add(comment);
            }

            return(lst.ToArray());
        }