Esempio n. 1
0
        private static bool CompareVariable(Dsl.StatementData data, Dsl.StatementData var)
        {
            bool ret = data.GetFunctionNum() == var.GetFunctionNum();

            if (ret)
            {
                int ct = data.GetFunctionNum();
                for (int i = 0; i < ct; ++i)
                {
                    var fl = data.GetFunction(i);
                    var fr = var.GetFunction(i);
                    ret = CompareVariable(fl, fr);
                    if (!ret)
                    {
                        break;
                    }
                }
            }
            return(ret);
        }
 public void Load(Dsl.StatementData messageHandlerData, string storyId)
 {
     m_StoryId = storyId;
     Dsl.CallData msgCallData = messageHandlerData.First.Call;
     if (null != msgCallData && msgCallData.HaveParam())
     {
         int      paramNum = msgCallData.GetParamNum();
         string[] args     = new string[paramNum];
         for (int i = 0; i < paramNum; ++i)
         {
             args[i] = msgCallData.GetParamId(i);
         }
         m_MessageId = string.Join(":", args);
     }
     for (int ix = 1; ix < messageHandlerData.GetFunctionNum(); ++ix)
     {
         var funcData = messageHandlerData.Functions[ix];
         var id       = funcData.GetId();
         if (id == "args")
         {
             var callData = funcData.Call;
             if (null != callData && callData.HaveParam())
             {
                 int paramNum = callData.GetParamNum();
                 if (paramNum > 0)
                 {
                     m_ArgumentNames = new string[paramNum];
                     for (int i = 0; i < paramNum; ++i)
                     {
                         m_ArgumentNames[i] = callData.GetParamId(i);
                     }
                 }
             }
         }
         else if (id == "comment" || id == "comments")
         {
             m_Comments = funcData;
         }
         else if (id == "body")
         {
         }
         else
         {
             LogSystem.Error("Story {0} MessageHandler {1}, part '{2}' error !", storyId, m_MessageId, id);
         }
     }
     Dsl.FunctionData bodyFunc = null;
     for (int ix = 0; ix < messageHandlerData.GetFunctionNum(); ++ix)
     {
         var funcData = messageHandlerData.Functions[ix];
         var id       = funcData.GetId();
         if (funcData.HaveStatement() && id != "comment" && id != "comments")
         {
             bodyFunc = funcData;
         }
     }
     if (null != bodyFunc)
     {
         RefreshCommands(bodyFunc);
     }
     else
     {
         LogSystem.Error("Story {0} MessageHandler {1}, no body !", storyId, m_MessageId);
     }
 }
Esempio n. 3
0
 public bool Init(Dsl.ISyntaxComponent config)
 {
     m_LoadSuccess = true;
     m_Config      = config;
     Dsl.FunctionData funcData = config as Dsl.FunctionData;
     if (null != funcData)
     {
         Load(funcData);
     }
     else
     {
         Dsl.StatementData statementData = config as Dsl.StatementData;
         if (null != statementData)
         {
             var first = statementData.First;
             if (first.HaveId() && !first.HaveParamOrStatement())
             {
                 //命令行样式转换为函数样式
                 var func = new Dsl.FunctionData();
                 func.CopyFrom(first);
                 func.SetParamClass((int)Dsl.FunctionData.ParamClassEnum.PARAM_CLASS_PARENTHESIS);
                 for (int i = 1; i < statementData.GetFunctionNum(); ++i)
                 {
                     var fd = statementData.GetFunction(i);
                     if (fd.HaveId() && !fd.HaveParamOrStatement())
                     {
                         func.AddParam(fd.Name);
                     }
                     else
                     {
                         func.AddParam(fd);
                     }
                 }
                 Load(func);
             }
             else
             {
                 int funcNum  = statementData.GetFunctionNum();
                 var lastFunc = statementData.Last;
                 var id       = lastFunc.GetId();
                 if (funcNum >= 2 && id == "comment" || id == "comments")
                 {
                     m_Comments = lastFunc;
                     statementData.Functions.RemoveAt(funcNum - 1);
                     if (statementData.GetFunctionNum() == 1)
                     {
                         funcData = statementData.GetFunction(0);
                         Load(funcData);
                     }
                     else
                     {
                         Load(statementData);
                     }
                 }
                 else
                 {
                     Load(statementData);
                 }
             }
         }
         else
         {
             //keyword
         }
     }
     return(m_LoadSuccess);
 }