예제 #1
0
 protected override bool Load(Dsl.FunctionData funcData)
 {
     if (funcData.IsHighOrder)
     {
         Dsl.ISyntaxComponent cond = funcData.LowerOrderFunction.GetParam(0);
         m_Condition = Interpreter.Load(cond);
         for (int ix = 0; ix < funcData.GetParamNum(); ++ix)
         {
             IExpression subExp = Interpreter.Load(funcData.GetParam(ix));
             m_Expressions.Add(subExp);
         }
     }
     else
     {
         //error
         Interpreter.Log("Interpreter error, {0} line {1}", funcData.ToScriptString(false), funcData.GetLine());
     }
     return(true);
 }
예제 #2
0
        private static void ParseEnum(string dslFile, FunctionData funcData, string defGroupName, SortedDictionary<string, EnumTypeDef> enumTypes, ref bool haveError)
        {
            if (null != funcData) {
            CallData callData = funcData.Call;
            if (null != callData && callData.GetParamNum() >= 1) {
              string enumName, groupName;
              enumName = callData.GetParamId(0);
              if (callData.GetParamNum() > 1) {
            groupName = callData.GetParamId(1);
              } else {
            groupName = defGroupName;
              }

              EnumTypeDef enumTypeDef = new EnumTypeDef();
              enumTypeDef.m_EnumName = enumName;
              enumTypeDef.m_GroupName = groupName;
              if (enumTypes.ContainsKey(enumName)) {
            enumTypes[enumName] = enumTypeDef;
              } else {
            enumTypes.Add(enumName, enumTypeDef);
              }

              int nextValue = 0;
              foreach (ISyntaxComponent comp in funcData.Statements) {
            ValueData val = comp as ValueData;
            if (null != val) {
              if (val.HaveId()) {
                enumTypeDef.m_EnumMembers.Add(val.GetId(), nextValue);
                ++nextValue;
              } else {
                LogSystem.Error("enum member {0} must have name ! line {1} file {2}", comp.ToScriptString(), comp.GetLine(), dslFile);
                haveError = true;
              }
            } else {
              CallData field = comp as CallData;
              if (null != field) {
                if (field.HaveId()) {
                  if (field.GetParamNum() >= 1) {
                    ISyntaxComponent param = field.GetParam(0);
                    string id = param.GetId();
                    int idType = param.GetIdType();
                    if (idType == ValueData.NUM_TOKEN) {
                      nextValue = int.Parse(id);
                    } else {
                      LogSystem.Error("enum member {0} value must be number ! line {1} file {2}", comp.ToScriptString(), comp.GetLine(), dslFile);
                      haveError = true;
                    }
                    enumTypeDef.m_EnumMembers.Add(field.GetId(), nextValue);
                  } else {
                    enumTypeDef.m_EnumMembers.Add(field.GetId(), nextValue);
                  }
                  ++nextValue;
                } else {
                  LogSystem.Error("enum member {0} must have name ! line {1} file {2}", comp.ToScriptString(), comp.GetLine(), dslFile);
                  haveError = true;
                }
              } else {
                LogSystem.Error("enum member {0} must end with ';' ! line {1} file {2}", comp.ToScriptString(), comp.GetLine(), dslFile);
                haveError = true;
              }
            }
              }
            } else {
              LogSystem.Error("enum {0} must have 1 or 2 params (name and group) ! line {1} file {2}", funcData.ToScriptString(), funcData.GetLine(), dslFile);
              haveError = true;
            }
              }
        }
예제 #3
0
        private static string ParseMessage(string dslFile, FunctionData funcData, string defGroupName, bool isInnerMessage, SortedDictionary<string, MessageDef> messages, ref bool haveError)
        {
            string typeName = null;
              if (null != funcData) {
            CallData callData = funcData.Call;
            if (null != callData && callData.GetParamNum() >= 1) {
              string groupName;
              typeName = callData.GetParamId(0);
              if (callData.GetParamNum() > 1) {
            groupName = callData.GetParamId(1);
              } else {
            groupName = defGroupName;
              }

              MessageDef messageDef = new MessageDef();
              messageDef.m_TypeName = typeName;
              messageDef.m_WrapName = typeName + "Wrap";
              messageDef.m_GroupName = groupName;
              messageDef.m_DontGenEnum = isInnerMessage;
              messageDef.m_DontGenDB = isInnerMessage;
              if (messages.ContainsKey(typeName)) {
            messages[typeName] = messageDef;
              } else {
            messages.Add(typeName, messageDef);
              }

              int nextOrder = 1;
              foreach (ISyntaxComponent comp in funcData.Statements) {
            CallData field = comp as CallData;
            if (null != field) {
              if (field.GetId() == "option") {
                if (field.GetParamId(0) == "dontgenenum")
                  messageDef.m_DontGenEnum = true;
                else if (field.GetParamId(0) == "dontgendb")
                  messageDef.m_DontGenDB = true;
              } else if (field.GetId() == "enumvalue") {
                messageDef.m_EnumValue = field.GetParamId(0);
              } else if (field.GetId() == "wrapname") {
                messageDef.m_WrapName = field.GetParamId(0);
              } else if (field.GetId() == "member") {
                if (field.GetParamNum() >= 3) {
                  MemberDef memberDef = new MemberDef();
                  memberDef.m_MemberName = field.GetParamId(0);
                  memberDef.m_TypeName = field.GetParamId(1);
                  memberDef.m_Modifier = field.GetParamId(2);
                  memberDef.m_Order = nextOrder++;
                  messageDef.m_Members.Add(memberDef);
                  messageDef.m_ColumnNames.Add(memberDef.m_MemberName);
                } else {
                  LogSystem.Error("member {0} must have name、type and modifier ! line {1} file {2}", comp.ToScriptString(), comp.GetLine(), dslFile);
                  haveError = true;
                }
              }
            } else {
              FunctionData customCode = comp as FunctionData;
              if (null != customCode) {
                if (customCode.GetId() == "enum") {
                  ParseEnum(dslFile, customCode, messageDef.m_GroupName, messageDef.m_EnumTypes, ref haveError);
                } if (customCode.GetId() == "message") {
                  ParseMessage(dslFile, customCode, messageDef.m_GroupName, true, messageDef.m_Messages, ref haveError);
                } if (customCode.GetId() == "member") {
                  CallData customField = customCode.Call;
                  if (null != customField && customField.GetParamNum() >= 3) {
                    MemberDef memberDef = new MemberDef();
                    memberDef.m_MemberName = customField.GetParamId(0);
                    memberDef.m_TypeName = customField.GetParamId(1);
                    memberDef.m_Modifier = customField.GetParamId(2);
                    memberDef.m_Order = nextOrder++;
                    messageDef.m_Members.Add(memberDef);
                    messageDef.m_ColumnNames.Add(memberDef.m_MemberName);

                    foreach (ISyntaxComponent comp2 in customCode.Statements) {
                      ValueData val = comp2 as ValueData;
                      if (null != val) {
                        if (val.GetId() == "primarykey") {
                          memberDef.m_IsPrimaryKey = true;
                          messageDef.m_PrimaryKeys.Add(memberDef.m_MemberName);
                        } else if (val.GetId() == "foreignkey") {
                          memberDef.m_IsForeignKey = true;
                          messageDef.m_ForeignKeys.Add(memberDef.m_MemberName);
                        }
                      } else {
                        CallData item = comp2 as CallData;
                        if (null != item) {
                          if (item.GetId() == "default") {
                            memberDef.m_Default = item.GetParamId(0);
                          } else if (item.GetId() == "maxsize") {
                            memberDef.m_MaxSize = int.Parse(item.GetParamId(0));
                          } else if (item.GetId() == "primarykey") {
                            memberDef.m_IsPrimaryKey = true;
                            messageDef.m_PrimaryKeys.Add(memberDef.m_MemberName);
                          } else if (item.GetId() == "foreignkey") {
                            memberDef.m_IsForeignKey = true;
                            messageDef.m_ForeignKeys.Add(memberDef.m_MemberName);
                          }
                        } else {
                          LogSystem.Error("message member options {0} must end with ';' ! line {1} file {2}", comp2.ToScriptString(), comp2.GetLine(), dslFile);
                          haveError = true;
                        }
                      }
                    }
                  }
                }
              } else {
                LogSystem.Error("message member {0} must have params and end with ';' ! line {1} file {2}", comp.ToScriptString(), comp.GetLine(), dslFile);
                haveError = true;
              }
            }
              }
            } else {
              LogSystem.Error("message {0} must have 1 or 2 params (name and group) ! line {1} file {2}", funcData.ToScriptString(), funcData.GetLine(), dslFile);
              haveError = true;
            }
              }
              return typeName;
        }