コード例 #1
0
        private bool LoadCall(Dsl.FunctionData callData)
        {
            m_LoadedOptArgs = new Dictionary <string, IStoryValue>();
            foreach (var pair in m_OptArgs)
            {
                StoryValue val = new StoryValue();
                val.InitFromDsl(pair.Value);
                m_LoadedOptArgs.Add(pair.Key, val);
            }
            m_LoadedArgs = new List <IStoryValue>();
            int num = callData.GetParamNum();

            for (int i = 0; i < num; ++i)
            {
                StoryValue val = new StoryValue();
                val.InitFromDsl(callData.GetParam(i));
                m_LoadedArgs.Add(val);
            }
            if (null == m_PrologueCommand)
            {
                m_PrologueCommand = new CompositePrologueCommandHelper(this);
            }
            if (null == m_EpilogueCommand)
            {
                m_EpilogueCommand = new CompositeEpilogueCommandHelper(this);
            }
            return(true);
        }
コード例 #2
0
 protected override bool Load(Dsl.FunctionData callData)
 {
     Dsl.ISyntaxComponent param1 = callData.GetParam(0);
     Dsl.ISyntaxComponent param2 = callData.GetParam(1);
     m_VarId = param1.GetId();
     m_Val   = Interpreter.Load(param2);
     return(true);
 }
コード例 #3
0
        protected override void Load(Dsl.FunctionData callData)
        {
            int num = callData.GetParamNum();

            if (num > 1)
            {
                m_Id.InitFromDsl(callData.GetParam(0));
                m_SubstId.InitFromDsl(callData.GetParam(1));
            }
        }
コード例 #4
0
 public bool Load(Dsl.ISyntaxComponent dsl, Interpreter interpreter)
 {
     m_Interpreter = interpreter;
     m_Dsl         = dsl;
     Dsl.ValueData valueData = dsl as Dsl.ValueData;
     if (null != valueData)
     {
         return(Load(valueData));
     }
     else
     {
         Dsl.FunctionData funcData = dsl as Dsl.FunctionData;
         if (null != funcData)
         {
             if (funcData.HaveParam())
             {
                 var  callData = funcData;
                 bool ret      = Load(callData);
                 if (!ret)
                 {
                     int num = callData.GetParamNum();
                     List <IExpression> args = new List <IExpression>();
                     for (int ix = 0; ix < num; ++ix)
                     {
                         Dsl.ISyntaxComponent param = callData.GetParam(ix);
                         args.Add(interpreter.Load(param));
                     }
                     return(Load(args));
                 }
                 return(ret);
             }
             else
             {
                 return(Load(funcData));
             }
         }
         else
         {
             Dsl.StatementData statementData = dsl as Dsl.StatementData;
             if (null != statementData)
             {
                 return(Load(statementData));
             }
         }
     }
     return(false);
 }
コード例 #5
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);
 }
コード例 #6
0
 protected override bool Load(Dsl.StatementData statementData)
 {
     Dsl.FunctionData funcData1 = statementData.First;
     Dsl.FunctionData funcData2 = statementData.Second;
     if (funcData1.IsHighOrder && funcData1.HaveLowerOrderParam() && funcData2.GetId() == ":" && funcData2.HaveParamOrStatement())
     {
         Dsl.ISyntaxComponent cond = funcData1.LowerOrderFunction.GetParam(0);
         Dsl.ISyntaxComponent op1  = funcData1.GetParam(0);
         Dsl.ISyntaxComponent op2  = funcData2.GetParam(0);
         m_Op1 = Interpreter.Load(cond);
         m_Op2 = Interpreter.Load(op1);
         m_Op3 = Interpreter.Load(op2);
     }
     else
     {
         //error
         Interpreter.Log("Interpreter error, {0} line {1}", statementData.ToScriptString(false), statementData.GetLine());
     }
     return(true);
 }
コード例 #7
0
ファイル: Dsl.cs プロジェクト: dreamanlan/DSL
 internal static void readBinary(byte[] bytes, ref int curCodeIndex, List<string> identifiers, ref int curIdIndex, StatementData data)
 {
     byte code = readByte(bytes, curCodeIndex++);
     if (code == (byte)DslBinaryCode.BeginStatement) {
         for (; ; ) {
             code = readByte(bytes, curCodeIndex);
             if (code == (byte)DslBinaryCode.BeginFunction) {
                 FunctionData funcData = new FunctionData();
                 readBinary(bytes, ref curCodeIndex, identifiers, ref curIdIndex, funcData);
                 data.Functions.Add(funcData);
             } else if (code == (byte)DslBinaryCode.EndStatement) {
                 ++curCodeIndex;
                 break;
             } else {
                 break;
             }
         }
     }
 }
コード例 #8
0
ファイル: Dsl.cs プロジェクト: dreamanlan/DSL
        internal static void readBinary(byte[] bytes, ref int curCodeIndex, List<string> identifiers, ref int curIdIndex, FunctionData data)
        {
            byte code = readByte(bytes, curCodeIndex++);
            if (code == (byte)DslBinaryCode.BeginFunction) {
                code = readByte(bytes, curCodeIndex);
                if (code == (byte)DslBinaryCode.BeginCall) {
                    CallData callData = new CallData();
                    readBinary(bytes, ref curCodeIndex, identifiers, ref curIdIndex, callData);
                    data.Call = callData;
                }
                code = readByte(bytes, curCodeIndex);
                if (code == (byte)DslBinaryCode.BeginExternScript) {
                    ++curCodeIndex;
                    data.SetExtentClass((int)FunctionData.ExtentClassEnum.EXTENT_CLASS_EXTERN_SCRIPT);
                    data.SetExternScript(readIdentifier(identifiers, curIdIndex++));

                    code = readByte(bytes, curCodeIndex);
                    if (code == (byte)DslBinaryCode.EndExternScript) {
                        ++curCodeIndex;
                    }
                } else {
                    data.SetExtentClass((int)FunctionData.ExtentClassEnum.EXTENT_CLASS_STATEMENT);
                    for (; ; ) {
                        code = readByte(bytes, curCodeIndex);
                        if (code == (byte)DslBinaryCode.EndFunction) {
                            ++curCodeIndex;
                            break;
                        } else {
                            ISyntaxComponent syntaxData = readBinary(bytes, ref curCodeIndex, identifiers, ref curIdIndex);
                            if (null != syntaxData) {
                                data.Statements.Add(syntaxData);
                            } else {
                                break;
                            }
                        }
                    }
                }
            }
        }
コード例 #9
0
ファイル: Dsl.cs プロジェクト: dreamanlan/DSL
 internal static ISyntaxComponent readBinary(byte[] bytes, ref int curCodeIndex, List<string> identifiers, ref int curIdIndex)
 {
     ISyntaxComponent ret = null;
     byte code = readByte(bytes, curCodeIndex);
     if (code == (byte)DslBinaryCode.BeginValue) {
         ValueData data = new ValueData();
         readBinary(bytes, ref curCodeIndex, identifiers, ref curIdIndex, data);
         ret = data;
     } else if (code == (byte)DslBinaryCode.BeginCall) {
         CallData data = new CallData();
         readBinary(bytes, ref curCodeIndex, identifiers, ref curIdIndex, data);
         ret = data;
     } else if (code == (byte)DslBinaryCode.BeginFunction) {
         FunctionData data = new FunctionData();
         readBinary(bytes, ref curCodeIndex, identifiers, ref curIdIndex, data);
         ret = data;
     } else if (code == (byte)DslBinaryCode.BeginStatement) {
         StatementData data = new StatementData();
         readBinary(bytes, ref curCodeIndex, identifiers, ref curIdIndex, data);
         ret = data;
     }
     return ret;
 }
コード例 #10
0
ファイル: Dsl.cs プロジェクト: dreamanlan/DSL
        public static void writeFunctionData(StringBuilder stream, FunctionData data, int indent, bool isLastOfStatement)
        {
            #if FULL_VERSION
            string line = string.Empty;
            if (null != data.Call) {
                line = data.Call.ToScriptString(false) + data.Call.CalcComment();
            }
            if (data.HaveStatement()) {
                if (line.Length > 0) {
                    writeLine(stream, line, indent);
                }
                writeLine(stream, "{", indent);
                ++indent;

                int ct = data.GetStatementNum();
                for (int i = 0; i < ct; ++i) {
                    ISyntaxComponent tempData = data.GetStatement(i);
                    writeSyntaxComponent(stream, tempData, indent);
                }

                --indent;
                if (isLastOfStatement)
                    writeContent(stream, "};", indent);
                else
                    writeContent(stream, "}", indent);
            } else if (data.HaveExternScript()) {
                if (line.Length > 0) {
                    writeLine(stream, line, indent);
                }
                foreach (string cmt in data.Call.Comments) {
                    writeLine(stream, cmt, indent);
                }
                string script = data.GetExternScript();
                if (script.IndexOf('\n') >= 0) {
                    writeLine(stream, "{:", indent);
                } else {
                    writeContent(stream, "{:", indent);
                }
                stream.Append(script);
                if (script.Length>0 && script[script.Length - 1] == '\n') {
                    if (isLastOfStatement)
                        writeContent(stream, ":};", indent);
                    else
                        writeContent(stream, ":}", indent);
                } else {
                    if (isLastOfStatement)
                        stream.Append(":};");
                    else
                        stream.Append(":}");
                }
            } else {
                if (isLastOfStatement)
                    writeContent(stream, line + ";", indent);
                else
                    writeContent(stream, line, indent);
            }
            #endif
        }
コード例 #11
0
ファイル: Dsl.cs プロジェクト: dreamanlan/DSL
 public void SetFunction(int index, FunctionData funcData)
 {
     if (index < 0 || index >= m_Functions.Count)
         return;
     m_Functions[index] = funcData;
 }
コード例 #12
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;
            }
              }
        }
コード例 #13
0
 protected virtual bool Load(Dsl.FunctionData funcData)
 {
     return(false);
 }
コード例 #14
0
ファイル: Dsl.cs プロジェクト: dreamanlan/DSL
 public void AddStatement(FunctionData statement)
 {
     m_Statements.Add(statement);
     if ((int)ExtentClassEnum.EXTENT_CLASS_STATEMENT != m_ExtentClass) {
         m_ExtentClass = (int)ExtentClassEnum.EXTENT_CLASS_STATEMENT;
     }
 }
コード例 #15
0
ファイル: Dsl.cs プロジェクト: dreamanlan/DSL
 internal static void writeBinary(MemoryStream stream, List<string> identifiers, FunctionData data)
 {
     stream.WriteByte((byte)DslBinaryCode.BeginFunction);
     writeBinary(stream, identifiers, data.Call);
     if (data.HaveExternScript()) {
         stream.WriteByte((byte)DslBinaryCode.BeginExternScript);
         identifiers.Add(data.GetExternScript());
         stream.WriteByte((byte)DslBinaryCode.EndExternScript);
     } else {
         foreach (ISyntaxComponent syntaxData in data.Statements) {
             writeBinary(stream, identifiers, syntaxData);
         }
     }
     stream.WriteByte((byte)DslBinaryCode.EndFunction);
 }
コード例 #16
0
 protected override bool Load(Dsl.FunctionData callData)
 {
     m_ArgIndex = Interpreter.Load(callData.GetParam(0));
     return(true);
 }
コード例 #17
0
ファイル: Dsl.cs プロジェクト: CQiao/DSL
    public static void writeFunctionData(StringBuilder stream, FunctionData data, int indent, bool isLastOfStatement)
    {
#if FULL_VERSION
      string line = "";
      if (null != data.Call)
        line = data.Call.ToScriptString();
      if (data.HaveStatement()) {
        if (line.Length > 0) {
          writeLine(stream, line, indent);
        }
        writeLine(stream, "{", indent);
        ++indent;

        int ct = data.GetStatementNum();
        for (int i = 0; i < ct; ++i) {
          ISyntaxComponent tempData = data.GetStatement(i);
          writeSyntaxComponent(stream, tempData, indent, true);
        }

        --indent;
        if (isLastOfStatement)
          writeLine(stream, "};", indent);
        else
          writeLine(stream, "}", indent);
      } else if (data.HaveExternScript()) {
        if (line.Length > 0) {
          writeLine(stream, line, indent);
        }
        writeContent(stream, "{:", indent);
        stream.Append(data.GetExternScript());
        if (isLastOfStatement)
          stream.AppendLine(":};");
        else
          stream.AppendLine(":}");
      } else {
        if (isLastOfStatement)
          writeLine(stream, line + ";", indent);
        else
          writeLine(stream, line, indent);
      }
#endif
    }
コード例 #18
0
        public IExpression Load(Dsl.ISyntaxComponent comp)
        {
            Dsl.ValueData    valueData = comp as Dsl.ValueData;
            Dsl.FunctionData funcData  = null;
            if (null != valueData)
            {
                int idType = valueData.GetIdType();
                if (idType == Dsl.ValueData.ID_TOKEN)
                {
                    string id = valueData.GetId();
                    if (id == "true" || id == "false")
                    {
                        ConstGet constExp = new ConstGet();
                        constExp.Load(comp, this);
                        return(constExp);
                    }
                    else
                    {
                        NamedVarGet varExp = new NamedVarGet();
                        varExp.Load(comp, this);
                        return(varExp);
                    }
                }
                else
                {
                    ConstGet constExp = new ConstGet();
                    constExp.Load(comp, this);
                    return(constExp);
                }
            }
            else
            {
                funcData = comp as Dsl.FunctionData;
                if (null != funcData && funcData.HaveParam())
                {
                    var    callData = funcData;
                    string op       = callData.GetId();
                    if (op == "=")  //赋值
                    {
                        IExpression exp  = null;
                        string      name = callData.GetParamId(0);
                        exp = new NamedVarSet();
                        if (null != exp)
                        {
                            exp.Load(comp, this);
                        }
                        else
                        {
                            //error
                            Log("Interpreter error, {0} line {1}", callData.ToScriptString(false), callData.GetLine());
                        }
                        return(exp);
                    }
                }
            }
            IExpression ret   = null;
            string      expId = comp.GetId();

            if (null != funcData && !funcData.IsHighOrder && m_Funcs.ContainsKey(expId))
            {
                ret = new FuncCallExp();
            }
            else
            {
                IExpressionFactory factory;
                if (m_Apis.TryGetValue(expId, out factory))
                {
                    ret = factory.Create();
                }
            }
            if (null != ret)
            {
                if (!ret.Load(comp, this))
                {
                    //error
                    Log("Interpreter error, {0} line {1}", comp.ToScriptString(false), comp.GetLine());
                }
            }
            else
            {
                //error
                Log("Interpreter error, {0} line {1}", comp.ToScriptString(false), comp.GetLine());
            }
            return(ret);
        }
コード例 #19
0
ファイル: Dsl.cs プロジェクト: dreamanlan/DSL
 public void AddParams(FunctionData param)
 {
     m_Params.Add(param);
     if ((int)ParamClassEnum.PARAM_CLASS_NOTHING == m_ParamClass) {
         m_ParamClass = (int)ParamClassEnum.PARAM_CLASS_PARENTHESIS;
     }
 }
コード例 #20
0
 protected override void Load(Dsl.FunctionData callData)
 {
     int num = callData.GetParamNum();
 }
コード例 #21
0
ファイル: Dsl.cs プロジェクト: dreamanlan/DSL
 public void CopyFrom(FunctionData other)
 {
     m_Call = other.m_Call;
     m_Statements = other.m_Statements;
     m_ExtentClass = other.m_ExtentClass;
     m_ExternScript = other.m_ExternScript;
 }
コード例 #22
0
ファイル: Dsl.cs プロジェクト: dreamanlan/DSL
 public void AddFunction(FunctionData funcData)
 {
     m_Functions.Add(funcData);
 }
コード例 #23
0
        protected override bool Load(Dsl.FunctionData callData)
        {
            int num = callData.GetParamNum();

            return(true);
        }
コード例 #24
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;
        }