public IStoryCommand CreateCommand(Dsl.ISyntaxComponent commandConfig) { IStoryCommand command = null; lock (m_Lock) { Dsl.StatementData statementData = commandConfig as Dsl.StatementData; if (null != statementData) { Dsl.FunctionData func; if (DslSyntaxTransformer.TryTransformCommandLineLikeSyntax(statementData, out func)) { commandConfig = func; } } Dsl.FunctionData callData = commandConfig as Dsl.FunctionData; if (null != callData) { if (callData.IsHighOrder) { Dsl.FunctionData innerCall = callData.LowerOrderFunction; if (innerCall.GetParamClass() == (int)Dsl.FunctionData.ParamClassEnum.PARAM_CLASS_PERIOD || innerCall.GetParamClass() == (int)Dsl.FunctionData.ParamClassEnum.PARAM_CLASS_BRACKET || innerCall.GetParamClass() == (int)Dsl.FunctionData.ParamClassEnum.PARAM_CLASS_PERIOD_BRACE || innerCall.GetParamClass() == (int)Dsl.FunctionData.ParamClassEnum.PARAM_CLASS_PERIOD_BRACKET || innerCall.GetParamClass() == (int)Dsl.FunctionData.ParamClassEnum.PARAM_CLASS_PERIOD_PARENTHESIS) { if (callData.GetParamClass() == (int)Dsl.FunctionData.ParamClassEnum.PARAM_CLASS_PARENTHESIS) { //obj.member(a,b,...) or obj[member](a,b,...) or obj.(member)(a,b,...) or obj.[member](a,b,...) or obj.{member}(a,b,...) -> execinstance(obj,member,a,b,...) Dsl.FunctionData newCall = new Dsl.FunctionData(); newCall.Name = new Dsl.ValueData("dotnetexec", Dsl.ValueData.ID_TOKEN); newCall.SetParamClass((int)Dsl.FunctionData.ParamClassEnum.PARAM_CLASS_PARENTHESIS); if (innerCall.IsHighOrder) { newCall.Params.Add(innerCall.LowerOrderFunction); newCall.Params.Add(ObjectMemberConverter.Convert(innerCall.GetParam(0), innerCall.GetParamClass())); for (int i = 0; i < callData.GetParamNum(); ++i) { Dsl.ISyntaxComponent p = callData.Params[i]; newCall.Params.Add(p); } } else { newCall.Params.Add(innerCall.Name); newCall.Params.Add(ObjectMemberConverter.Convert(innerCall.GetParam(0), innerCall.GetParamClass())); for (int i = 0; i < callData.GetParamNum(); ++i) { Dsl.ISyntaxComponent p = callData.Params[i]; newCall.Params.Add(p); } } return(CreateCommand(newCall)); } } } else if ((callData.GetParamClass() == (int)Dsl.FunctionData.ParamClassEnum.PARAM_CLASS_OPERATOR || callData.GetParamClass() == (int)Dsl.FunctionData.ParamClassEnum.PARAM_CLASS_BRACKET || callData.GetParamClass() == (int)Dsl.FunctionData.ParamClassEnum.PARAM_CLASS_PERIOD_BRACE || callData.GetParamClass() == (int)Dsl.FunctionData.ParamClassEnum.PARAM_CLASS_PERIOD_BRACKET || callData.GetParamClass() == (int)Dsl.FunctionData.ParamClassEnum.PARAM_CLASS_PERIOD_PARENTHESIS) && callData.GetId() == "=") { Dsl.FunctionData innerCall = callData.GetParam(0) as Dsl.FunctionData; if (null != innerCall) { //obj.property = val or obj[property] = val or obj.(property) = val or obj.[property] = val or obj.{property} = val -> setinstance(obj,property,val) Dsl.FunctionData newCall = new Dsl.FunctionData(); newCall.Name = new Dsl.ValueData("dotnetset", Dsl.ValueData.ID_TOKEN); newCall.SetParamClass((int)Dsl.FunctionData.ParamClassEnum.PARAM_CLASS_PARENTHESIS); if (innerCall.IsHighOrder) { newCall.Params.Add(innerCall.LowerOrderFunction); newCall.Params.Add(ObjectMemberConverter.Convert(innerCall.GetParam(0), innerCall.GetParamClass())); newCall.Params.Add(callData.GetParam(1)); } else { newCall.Params.Add(innerCall.Name); newCall.Params.Add(ObjectMemberConverter.Convert(innerCall.GetParam(0), innerCall.GetParamClass())); newCall.Params.Add(callData.GetParam(1)); } return(CreateCommand(newCall)); } } } string type = commandConfig.GetId(); if (commandConfig.GetIdType() == Dsl.ValueData.ID_TOKEN) { IStoryCommandFactory factory = GetFactory(type); if (null != factory) { try { command = factory.Create(); if (!command.Init(commandConfig)) { GameFramework.LogSystem.Error("[LoadStory] command:{0}[{1}] line:{2} failed.", type, commandConfig.ToScriptString(false), commandConfig.GetLine()); } } catch (Exception ex) { var msg = string.Format("[LoadStory] command:{0}[{1}] line:{2} failed.", type, commandConfig.ToScriptString(false), commandConfig.GetLine()); throw new Exception(msg, ex); } } else { #if DEBUG string err = string.Format("[LoadStory] CreateCommand failed, line:{0} command:{1}[{2}]", commandConfig.GetLine(), type, commandConfig.ToScriptString(false)); GameFramework.LogSystem.Error("{0}", err); throw new Exception(err); #else GameFramework.LogSystem.Error("[LoadStory] CreateCommand failed, type:{0} line:{1}", type, commandConfig.GetLine()); #endif } if (null != command) { //GameFramework.LogSystem.Debug("[LoadStory] CreateCommand, type:{0} command:{1}", type, command.GetType().Name); } else { #if DEBUG string err = string.Format("[LoadStory] CreateCommand failed, line:{0} command:{1}[{2}]", commandConfig.GetLine(), type, commandConfig.ToScriptString(false)); GameFramework.LogSystem.Error("{0}", err); throw new Exception(err); #else GameFramework.LogSystem.Error("[LoadStory] CreateCommand failed, type:{0} line:{1}", type, commandConfig.GetLine()); #endif } } } return(command); }
public IStoryValue CalcValue(Dsl.ISyntaxComponent param) { lock (m_Lock) { Dsl.FunctionData callData = param as Dsl.FunctionData; if (null != callData && callData.IsValid() && callData.GetId().Length == 0 && !callData.IsHighOrder && (callData.GetParamClass() == (int)Dsl.FunctionData.ParamClassEnum.PARAM_CLASS_PARENTHESIS || callData.GetParamClass() == (int)Dsl.FunctionData.ParamClassEnum.PARAM_CLASS_BRACKET)) { //处理圆括弧与方括弧 switch (callData.GetParamClass()) { case (int)Dsl.FunctionData.ParamClassEnum.PARAM_CLASS_PARENTHESIS: if (callData.GetParamNum() > 0) { int ct = callData.GetParamNum(); return(CalcValue(callData.GetParam(ct - 1))); } else { return(null); } case (int)Dsl.FunctionData.ParamClassEnum.PARAM_CLASS_BRACKET: { IStoryValue ret = null; IStoryValueFactory factory = GetFactory("array"); if (null != factory) { try { ret = factory.Build(); ret.InitFromDsl(param); } catch (Exception ex) { var msg = string.Format("[LoadStory] value:{0} line:{1} failed.", param.ToScriptString(false), param.GetLine()); throw new Exception(msg, ex); } } return(ret); } default: return(null); } } else { Dsl.FunctionData funcData = param as Dsl.FunctionData; if (null != funcData && funcData.HaveStatement()) { //处理大括弧 callData = funcData; if (null == callData || !callData.HaveParam()) { IStoryValue ret = null; IStoryValueFactory factory = GetFactory("hashtable"); if (null != factory) { try { ret = factory.Build(); ret.InitFromDsl(param); } catch (Exception ex) { var msg = string.Format("[LoadStory] value:{0} line:{1} failed.", param.ToScriptString(false), param.GetLine()); throw new Exception(msg, ex); } } return(ret); } else { //不支持的语法 return(null); } } else { if (null != callData) { Dsl.FunctionData innerCall = callData.LowerOrderFunction; if (callData.IsHighOrder && callData.GetParamClass() == (int)Dsl.FunctionData.ParamClassEnum.PARAM_CLASS_PARENTHESIS && ( innerCall.GetParamClass() == (int)Dsl.FunctionData.ParamClassEnum.PARAM_CLASS_PERIOD || innerCall.GetParamClass() == (int)Dsl.FunctionData.ParamClassEnum.PARAM_CLASS_BRACKET || innerCall.GetParamClass() == (int)Dsl.FunctionData.ParamClassEnum.PARAM_CLASS_PERIOD_BRACE || innerCall.GetParamClass() == (int)Dsl.FunctionData.ParamClassEnum.PARAM_CLASS_PERIOD_BRACKET || innerCall.GetParamClass() == (int)Dsl.FunctionData.ParamClassEnum.PARAM_CLASS_PERIOD_PARENTHESIS )) { //obj.member(a,b,...) or obj[member](a,b,...) or obj.(member)(a,b,...) or obj.[member](a,b,...) or obj.{member}(a,b,...) -> dotnetcall(obj,member,a,b,...) string method = innerCall.GetParamId(0); string apiName; if (method == "orderby" || method == "orderbydesc" || method == "where" || method == "top") { apiName = "linq"; } else { apiName = "dotnetcall"; } Dsl.FunctionData newCall = new Dsl.FunctionData(); newCall.Name = new Dsl.ValueData(apiName, Dsl.ValueData.ID_TOKEN); newCall.SetParamClass((int)Dsl.FunctionData.ParamClassEnum.PARAM_CLASS_PARENTHESIS); if (innerCall.IsHighOrder) { newCall.Params.Add(innerCall.LowerOrderFunction); newCall.Params.Add(ObjectMemberConverter.Convert(innerCall.GetParam(0), innerCall.GetParamClass())); for (int i = 0; i < callData.GetParamNum(); ++i) { Dsl.ISyntaxComponent p = callData.Params[i]; newCall.Params.Add(p); } } else { newCall.Params.Add(innerCall.Name); newCall.Params.Add(ObjectMemberConverter.Convert(innerCall.GetParam(0), innerCall.GetParamClass())); for (int i = 0; i < callData.GetParamNum(); ++i) { Dsl.ISyntaxComponent p = callData.Params[i]; newCall.Params.Add(p); } } return(CalcValue(newCall)); } else if (callData.GetParamClass() == (int)Dsl.FunctionData.ParamClassEnum.PARAM_CLASS_PERIOD || callData.GetParamClass() == (int)Dsl.FunctionData.ParamClassEnum.PARAM_CLASS_BRACKET || callData.GetParamClass() == (int)Dsl.FunctionData.ParamClassEnum.PARAM_CLASS_PERIOD_BRACE || callData.GetParamClass() == (int)Dsl.FunctionData.ParamClassEnum.PARAM_CLASS_PERIOD_BRACKET || callData.GetParamClass() == (int)Dsl.FunctionData.ParamClassEnum.PARAM_CLASS_PERIOD_PARENTHESIS) { //obj.property or obj[property] or obj.(property) or obj.[property] or obj.{property} -> dotnetget(obj,property) Dsl.FunctionData newCall = new Dsl.FunctionData(); newCall.Name = new Dsl.ValueData("dotnetget", Dsl.ValueData.ID_TOKEN); newCall.SetParamClass((int)Dsl.FunctionData.ParamClassEnum.PARAM_CLASS_PARENTHESIS); if (callData.IsHighOrder) { newCall.Params.Add(callData.LowerOrderFunction); newCall.Params.Add(ObjectMemberConverter.Convert(callData.GetParam(0), callData.GetParamClass())); } else { newCall.Params.Add(callData.Name); newCall.Params.Add(ObjectMemberConverter.Convert(callData.GetParam(0), callData.GetParamClass())); } return(CalcValue(newCall)); } } IStoryValue ret = null; string id = param.GetId(); if (param.GetIdType() == Dsl.ValueData.ID_TOKEN) { IStoryValueFactory factory = GetFactory(id); if (null != factory) { try { ret = factory.Build(); ret.InitFromDsl(param); } catch (Exception ex) { var msg = string.Format("[LoadStory] value:{0}[{1}] line:{2} failed.", id, param.ToScriptString(false), param.GetLine()); throw new Exception(msg, ex); } } else { #if DEBUG string err = string.Format("[LoadStory] value:{0}[{1}] line:{2} failed.", id, param.ToScriptString(false), param.GetLine()); GameFramework.LogSystem.Error("{0}", err); throw new Exception(err); #else GameFramework.LogSystem.Error("[LoadStory] value:{0} line:{1} failed.", id, param.GetLine()); #endif } } return(ret); } } } }