Exemplo n.º 1
0
 /// <summary>
 ///     追加字符
 /// </summary>
 /// <param name="word">基本单词</param>
 public void Append(WordUnit word)
 {
     if (!word.IsReplenish)
     {
         if (Line < 0)
         {
             Line = word.Line;
         }
         if (Column < 0)
         {
             Column = word.Column;
         }
         if (Start < 0)
         {
             Start = word.Start;
         }
         End = word.End;
     }
     if (word.IsPunctuate)
     {
         IsPunctuate = true;
         if (word.IsSpace)
         {
             ItemRace   = CodeItemRace.Assist;
             ItemFamily = CodeItemFamily.Space;
             if (word.IsLine)
             {
                 ItemType = CodeItemType.Line;
             }
         }
     }
     CharAppenBuilder.Append(word.Word);
     Words.Add(word);
 }
Exemplo n.º 2
0
        /// <summary>
        /// 调用块的构造终结
        /// </summary>
        private void ReleaseCall()
        {
            SetRace(CodeItemRace.Variable, CodeItemFamily.ValueSentence, CodeItemType.Call);
            var unit    = Elements[0] as WordUnit;
            var isChild = Parent != null && !Parent.IsEmpty && Parent.Elements[0] != this &&
                          Parent.ItemType == CodeItemType.Table_Child;

            if (unit != null && !unit.IsKeyWord && !unit.IsPunctuate)
            {
                _primary = unit;
            }
            if (isChild)
            {
                Name = $"['{Elements[0].Word}']";
            }
            else
            {
                Name = Elements[0].Name ?? Elements[0].Word;
            }
            Primary.Name = Name;
            if (Elements.Count > 1)
            {
                Elements[1].Name = "_call_";
                for (var i = 2; i < Elements.Count; i++)
                {
                    Elements[i].Name = "_call_";
                }
                if (Elements.Count > 2)
                {
                    Name += Elements.Count - 2;
                }
            }
        }
Exemplo n.º 3
0
        /// <summary>
        ///     合并基本单词
        /// </summary>
        /// <returns></returns>
        internal void MergeWords()
        {
            Elements.Clear();
            WordUnit    pre  = null;
            WordElement cur  = null;
            int         line = 0;
            int         col  = 0;

            foreach (var word in Words)
            {
                word.Line   = line;
                word.Column = col;
                if (word.IsLine)
                {
                    line++;
                    col = 0;
                }
                else
                {
                    col += word.Lenght;
                }

                if (cur == null || !word.IsSpace || !pre.IsSpace)
                {
                    Elements.Add(cur = new WordElement(word));
                    pre = word;
                    continue;
                }
                cur.Append(word);
            }
            foreach (var element in Elements)
            {
                element.Release();
            }
        }
Exemplo n.º 4
0
 /// <summary>
 ///     追加字符
 /// </summary>
 /// <param name="unit">字符</param>
 public void Append(WordUnit unit)
 {
     if (unit == null)
     {
         return;
     }
     Chars.AddRange(unit.Chars);
     if (unit.End >= 0)
     {
         End = unit.End;
     }
 }
Exemplo n.º 5
0
        /// <summary>
        /// 函数块的构造终结
        /// </summary>
        private void ReleaseFunction()
        {
            if (Elements.Count > 1 && Elements[1].ItemType == CodeItemType.Call &&
                ((AnalyzeBlock)Elements[1]).Primary != null)
            {
                _primary = ((AnalyzeBlock)Elements[1]).Primary;
                _primary?.SetRace(CodeItemRace.Variable, CodeItemFamily.Variable, CodeItemType.Function);
                ((AnalyzeBlock)Elements[1]).SetRace(CodeItemRace.Variable, CodeItemFamily.Variable,
                                                    CodeItemType.Function);

                Name = Elements[1].Name = _primary?.Name;
            }
        }
Exemplo n.º 6
0
        /// <summary>
        ///     拆分基本单词
        /// </summary>
        /// <returns></returns>
        internal void SplitWords()
        {
            Words = new List <WordUnit>();
            WordUnit word = null;
            int      line = 0;
            int      col  = 0;
            int      idx  = 0;

            for (int index = 0; index < Code.Length; index++)
            {
                char ch = Code[index];
                if (ch == '\r')
                {
                    continue;
                }
                col++;


                if (ch >= 128 ||
                    ch == '_' ||
                    (ch >= '0' && ch <= '9') || //数字
                    (ch >= 'A' && ch <= 'Z') || //字母
                    (ch >= 'a' && ch <= 'z'))
                {
                    if (word != null && word.IsPunctuate)
                    {
                        Words.Add(word = new WordUnit {
                            Line = line, Column = col
                        });
                    }
                    else if (word == null)
                    {
                        Words.Add(word = new WordUnit {
                            Line = line, Column = col
                        });
                    }
                }
                else //标点符号后期独立处理(都是独立的一个字)
                {
                    Words.Add(word = new WordUnit {
                        Line = line, Column = col
                    });
                    if (ch == '\n')
                    {
                        line++;
                        col = 0;
                    }
                }
                word.Append(idx++, ch);
            }
        }
Exemplo n.º 7
0
        /// <summary>
        ///     追加补全字符
        /// </summary>
        /// <param name="str">字符</param>
        public void Append(string str)
        {
            var unit = new WordUnit
            {
                IsReplenish = true,
                Word        = str
            };

            unit.Chars.AddRange(str);
            Elements.Add(new WordElement(unit)
            {
                IsReplenish = true,
                ItemRace    = CodeItemRace.Completion
            });
        }
Exemplo n.º 8
0
        /// <summary>
        ///     接入补全字符
        /// </summary>
        /// <param name="idx"></param>
        /// <param name="str">字符</param>
        public void Insert(int idx, string str)
        {
            var unit = new WordUnit
            {
                IsReplenish = true,
                Word        = str
            };

            unit.Chars.AddRange(str);
            Elements.Insert(idx, new WordElement(unit)
            {
                IsReplenish = true,
                ItemRace    = CodeItemRace.Completion
            });
        }
Exemplo n.º 9
0
 private static void WriteContentWord(WordUnit word, StringBuilder code)
 {
     if (word.IsReplenish)
     {
         code.Append(word.Word);
         return;
     }
     foreach (char ch in word.Chars)
     {
         if (ch > 256 || ch == '[' || ch == ']' || ch == '%')
         {
             code.AppendFormat("/u{0:x4}", (int)ch);
         }
         else
         {
             code.Append(ch);
         }
     }
 }
Exemplo n.º 10
0
 /// <summary>
 ///     合并单元
 /// </summary>
 /// <param name="unit">分析单元</param>
 public void Append(WordUnit unit)
 {
     if (unit == null || Elements.Contains(unit))
     {
         return;
     }
     if ((Start < 0 || Start > unit.Start) && unit.Start >= 0)
     {
         Start = unit.Start;
     }
     if ((End < 0 || End < unit.End) && unit.End >= 0)
     {
         End = unit.End;
     }
     Elements.Add(unit);
     unit.Parent = this;
     OnElementAppend?.Invoke(this, unit);
     //if (Primary == null || unit.PrimaryLevel < Primary.PrimaryLevel)
     //    Primary = unit;
 }
Exemplo n.º 11
0
 /// <summary>
 ///     构造
 /// </summary>
 /// <param name="word">基本单词</param>
 internal WordElement(WordUnit word)
 {
     Append(word);
 }