예제 #1
0
        private void AppendLine(List <WordUnit> words, int level)
        {
            WordUnit word;

            if (words.Count == 0)
            {
                words.Add(word = new WordUnit());
            }
            else
            {
                word = new WordUnit('\r')
                {
                    UnitType = TemplateUnitType.Code
                };
                word.Append(-1, '\n');
                if (words[words.Count - 1].ItemFamily != CodeItemFamily.Space)
                {
                    words.Add(word);
                }
                else
                {
                    words[words.Count - 1] = word;
                }
            }
            for (int i = 0; i < level * 4; i++)
            {
                word.Append(-1, ' ');
            }
        }
예제 #2
0
        private void CheckPunctuate(WordUnit word, ref WordUnit pre)
        {
            switch (word.Char)
            {
                #region 其它

            case '#':
                word.IsKeyWord    = true;
                word.PrimaryLevel = 33;
                word.JoinLevel    = 2;
                word.ValueType    = LuaDataTypeItem.NumberValue;
                word.JoinFeature  = JoinFeature.Front;
                word.SetRace(CodeItemRace.Sentence, CodeItemFamily.Operator, CodeItemType.StringLen);
                pre = null;
                break;

            case ';':
                word.IsKeyWord = true;
                word.SetRace(CodeItemRace.Control, CodeItemFamily.Control, CodeItemType.Separator_Semicolon);
                pre = null;
                break;

            default:
                pre = null;
                break;

                #endregion

                #region 扩号区域

            case '{':
                word.IsKeyWord    = true;
                word.PrimaryLevel = 1;
                word.JoinLevel    = 2;
                word.ValueType    = LuaDataTypeItem.TableDefinition;
                word.SetRace(CodeItemRace.Range, CodeItemFamily.Range, CodeItemType.Brackets41);
                pre = null;
                break;

            case '}':
                word.IsKeyWord    = true;
                word.PrimaryLevel = 1;
                word.JoinLevel    = 2;
                word.SetRace(CodeItemRace.Range, CodeItemFamily.Range, CodeItemType.Brackets42);
                pre = null;
                break;

            case '(':
                word.IsKeyWord    = true;
                word.PrimaryLevel = 1;
                word.JoinLevel    = 3;
                word.SetRace(CodeItemRace.Range, CodeItemFamily.Range, CodeItemType.Brackets21);
                pre = null;
                break;

            case ')':
                word.IsKeyWord = true;
                word.JoinLevel = 3;
                word.SetRace(CodeItemRace.Range, CodeItemFamily.Range, CodeItemType.Brackets22);
                pre = null;
                break;

            case '[':
                word.IsKeyWord    = true;
                word.PrimaryLevel = 1;
                word.JoinLevel    = 1;
                word.SetRace(CodeItemRace.Range, CodeItemFamily.Range, CodeItemType.Brackets31);
                pre = null;
                break;

            case ']':
                word.IsKeyWord = true;
                word.JoinLevel = 1;
                word.SetRace(CodeItemRace.Range, CodeItemFamily.Range, CodeItemType.Brackets32);
                pre = null;
                break;

                #endregion

                #region 算术计算

            case '+':
                word.IsKeyWord    = true;
                word.PrimaryLevel = 1;
                word.JoinLevel    = 5;
                word.ValueType    = LuaDataTypeItem.NumberValue;
                word.JoinFeature  = JoinFeature.TowWay;
                word.SetRace(CodeItemRace.Sentence, CodeItemFamily.Compute, CodeItemType.Compute_Add);
                pre = null;
                break;

            case '-':
                word.IsKeyWord   = true;
                word.JoinLevel   = 5;
                word.ValueType   = LuaDataTypeItem.NumberValue;
                word.JoinFeature = JoinFeature.TowWay;
                word.SetRace(CodeItemRace.Sentence, CodeItemFamily.Compute, CodeItemType.Compute_Sub);
                pre = null;
                break;

            case '*':
                word.IsKeyWord    = true;
                word.PrimaryLevel = 1;
                word.JoinLevel    = 4;
                word.ValueType    = LuaDataTypeItem.NumberValue;
                word.JoinFeature  = JoinFeature.TowWay;
                word.SetRace(CodeItemRace.Sentence, CodeItemFamily.Compute, CodeItemType.Compute_Mulit);
                pre = null;
                break;

            case '/':
                word.IsKeyWord    = true;
                word.PrimaryLevel = 1;
                word.JoinLevel    = 4;
                word.ValueType    = LuaDataTypeItem.NumberValue;
                word.JoinFeature  = JoinFeature.TowWay;
                word.SetRace(CodeItemRace.Sentence, CodeItemFamily.Compute, CodeItemType.Compute_Div);
                pre = null;
                break;

            case '%':
                word.IsKeyWord    = true;
                word.PrimaryLevel = 1;
                word.JoinLevel    = 4;
                word.ValueType    = LuaDataTypeItem.NumberValue;
                word.JoinFeature  = JoinFeature.TowWay;
                word.SetRace(CodeItemRace.Sentence, CodeItemFamily.Compute, CodeItemType.Compute_Mod);
                pre = null;
                break;

            case '^':
                word.IsKeyWord    = true;
                word.PrimaryLevel = 1;
                word.JoinLevel    = 3;
                word.ValueType    = LuaDataTypeItem.NumberValue;
                word.JoinFeature  = JoinFeature.TowWay;
                word.SetRace(CodeItemRace.Sentence, CodeItemFamily.Compute, CodeItemType.Compute_Exp);
                pre = null;
                break;

                #endregion

                #region 连接符

            case ',':
                word.IsKeyWord    = true;
                word.PrimaryLevel = 1;
                word.JoinLevel    = 3;
                word.JoinFeature  = JoinFeature.Connect;
                word.SetRace(CodeItemRace.Sentence, CodeItemFamily.Separator, CodeItemType.Separator_Comma);
                pre = null;
                break;

            case ':':
                word.IsKeyWord    = true;
                word.PrimaryLevel = 1;
                word.JoinLevel    = 1;
                word.JoinFeature  = JoinFeature.Connect;
                word.SetRace(CodeItemRace.Sentence, CodeItemFamily.Separator, CodeItemType.Separator_Colon);
                pre = null;
                break;

            case '.':
                if (pre == null || pre.FirstChar != '.')
                {
                    word.IsKeyWord    = true;
                    word.PrimaryLevel = 1;
                    word.JoinLevel    = 1;
                    word.JoinFeature  = JoinFeature.Connect;
                    word.SetRace(CodeItemRace.Sentence, CodeItemFamily.Separator, CodeItemType.Separator_Dot);
                    pre = word;
                }
                else if (pre.Chars.Count == 1)
                {
                    pre.Append(word);
                    word.Clear();
                    pre.JoinLevel = 2;
                    pre.ValueType = LuaDataTypeItem.StringValue;
                    pre.SetRace(CodeItemRace.Sentence, CodeItemFamily.Separator, CodeItemType.Separator_StringJoin);
                }
                else
                {
                    pre.Append(word);
                    word.Clear();
                    word.IsKeyWord  = false;
                    pre.JoinLevel   = -1;
                    pre.ValueType   = LuaDataTypeItem.TableDefinition;
                    pre.JoinFeature = JoinFeature.None;
                    pre.SetRace(CodeItemRace.Variable, CodeItemFamily.Variable, CodeItemType.Variable_Arg);
                    pre = null;
                }
                break;
                #endregion

                #region 逻辑比较

            case '>':
                word.IsKeyWord    = true;
                word.PrimaryLevel = 1;
                word.ValueType    = LuaDataTypeItem.BoolValue;
                word.JoinLevel    = 6;
                word.JoinFeature  = JoinFeature.TowWay;
                word.SetRace(CodeItemRace.Sentence, CodeItemFamily.Compare, CodeItemType.Compare_Greater);
                pre = word;
                break;

            case '<':
                word.IsKeyWord    = true;
                word.PrimaryLevel = 1;
                word.ValueType    = LuaDataTypeItem.BoolValue;
                word.JoinLevel    = 6;
                word.JoinFeature  = JoinFeature.TowWay;
                word.SetRace(CodeItemRace.Sentence, CodeItemFamily.Compare, CodeItemType.Compare_Less);
                pre = word;
                break;

            case '~':
                pre = word;
                break;

            case '=':
                bool canLink = false;
                if (pre != null)
                {
                    switch (pre.Char)
                    {
                    case '>':
                        canLink = true;
                        pre.SetRace(CodeItemRace.Sentence, CodeItemFamily.Compare, CodeItemType.Compare_GreaterEqual);
                        break;

                    case '<':
                        canLink = true;
                        pre.SetRace(CodeItemRace.Sentence, CodeItemFamily.Compare, CodeItemType.Compare_LessEqual);
                        break;

                    case '~':
                        canLink = true;
                        pre.SetRace(CodeItemRace.Sentence, CodeItemFamily.Compare, CodeItemType.Compare_NotEqual);
                        break;

                    case '=':
                        canLink = true;
                        pre.SetRace(CodeItemRace.Sentence, CodeItemFamily.Compare, CodeItemType.Compare_Equal);
                        break;
                    }
                }
                if (canLink)
                {
                    pre.Append(word);
                    word.Clear();
                    pre.PrimaryLevel = 1;
                    pre.ValueType    = LuaDataTypeItem.BoolValue;
                    pre.JoinLevel    = 6;
                    pre.JoinFeature  = JoinFeature.TowWay;
                    pre = null;
                }
                else
                {
                    word.PrimaryLevel = 1;
                    word.IsKeyWord    = true;
                    word.JoinLevel    = 9;
                    word.JoinFeature  = JoinFeature.TowWay;
                    word.SetRace(CodeItemRace.Sentence, CodeItemFamily.SetValue, CodeItemType.Separator_Equal);
                    pre = word;
                }
                break;

                #endregion
            }
        }