public static void FinalParse(Dsl.DslInfo dslInfo) { string id = dslInfo.GetId(); if (id == "command") { if (dslInfo.Functions.Count == 2) { Dsl.FunctionData first = dslInfo.First; string name = first.Call.GetParamId(0); IStoryCommandFactory factory = StoryCommandManager.Instance.FindFactory(name); if (null != factory) { StorySystem.CommonCommands.CompositeCommand cmd = factory.Create() as StorySystem.CommonCommands.CompositeCommand; Dsl.FunctionData second = dslInfo.Second; cmd.InitialCommands.Clear(); for (int ix = 0; ix < second.GetStatementNum(); ++ix) { Dsl.ISyntaxComponent syntaxComp = second.GetStatement(ix); IStoryCommand sub = StoryCommandManager.Instance.CreateCommand(syntaxComp); cmd.InitialCommands.Add(sub); } } else { LogSystem.Error("Can't find command factory '{0}'", name); } } } else if (id == "value") { if (dslInfo.Functions.Count == 3) { Dsl.FunctionData first = dslInfo.First; string name = first.Call.GetParamId(0); IStoryValueFactory factory = StoryValueManager.Instance.FindFactory(name); if (null != factory) { StorySystem.CommonValues.CompositeValue val = factory.Build() as StorySystem.CommonValues.CompositeValue; Dsl.FunctionData second = dslInfo.Second; Dsl.FunctionData third = dslInfo.Functions[2]; val.InitialCommands.Clear(); for (int ix = 0; ix < third.GetStatementNum(); ++ix) { Dsl.ISyntaxComponent syntaxComp = third.GetStatement(ix); IStoryCommand sub = StoryCommandManager.Instance.CreateCommand(syntaxComp); val.InitialCommands.Add(sub); } } else { LogSystem.Error("Can't find value factory '{0}'", name); } } } }
public static void FinalParse(Dsl.ISyntaxComponent dslInfo) { string id = dslInfo.GetId(); if (id == "command") { string name = string.Empty; var first = dslInfo as Dsl.FunctionData; var statement = dslInfo as Dsl.StatementData; if (null != first) { name = first.Call.GetParamId(0); } else { if (null != statement) { first = statement.First; name = first.Call.GetParamId(0); } } IStoryCommandFactory factory = StoryCommandManager.Instance.FindFactory(name); if (null != factory) { StorySystem.CommonCommands.CompositeCommand cmd = factory.Create() as StorySystem.CommonCommands.CompositeCommand; cmd.InitialCommands.Clear(); Dsl.FunctionData bodyFunc = null; if (null != statement) { for (int i = 0; i < statement.GetFunctionNum(); ++i) { var funcData = statement.GetFunction(i); var fid = funcData.GetId(); if (funcData.HaveStatement() && fid != "opts") { bodyFunc = funcData; } } } else { bodyFunc = first; } if (null != bodyFunc) { for (int ix = 0; ix < bodyFunc.GetStatementNum(); ++ix) { Dsl.ISyntaxComponent syntaxComp = bodyFunc.GetStatement(ix); IStoryCommand sub = StoryCommandManager.Instance.CreateCommand(syntaxComp); cmd.InitialCommands.Add(sub); } } else { LogSystem.Error("Can't find command {0}'s body", name); } } else { LogSystem.Error("Can't find command {0}'s factory", name); } } else if (id == "value") { string name = string.Empty; var first = dslInfo as Dsl.FunctionData; var statement = dslInfo as Dsl.StatementData; if (null != first) { name = first.Call.GetParamId(0); } else { if (null != statement) { first = statement.First; name = first.Call.GetParamId(0); } } IStoryValueFactory factory = StoryValueManager.Instance.FindFactory(name); if (null != factory) { StorySystem.CommonValues.CompositeValue val = factory.Build() as StorySystem.CommonValues.CompositeValue; val.InitialCommands.Clear(); Dsl.FunctionData bodyFunc = null; if (null != statement) { for (int i = 0; i < statement.GetFunctionNum(); ++i) { var funcData = statement.GetFunction(i); var fid = funcData.GetId(); if (funcData.HaveStatement() && fid != "opts") { bodyFunc = funcData; } } } else { bodyFunc = first; } if (null != bodyFunc) { for (int ix = 0; ix < bodyFunc.GetStatementNum(); ++ix) { Dsl.ISyntaxComponent syntaxComp = bodyFunc.GetStatement(ix); IStoryCommand sub = StoryCommandManager.Instance.CreateCommand(syntaxComp); val.InitialCommands.Add(sub); } } else { LogSystem.Error("Can't find value {0}'s body", name); } } else { LogSystem.Error("Can't find value {0}'s factory", name); } } }
public IStoryValue <object> CalcValue(Dsl.ISyntaxComponent param) { lock (m_Lock) { if (param.IsValid() && param.GetId().Length == 0) { //处理括弧 Dsl.CallData callData = param as Dsl.CallData; if (null != callData) { switch (callData.GetParamClass()) { case (int)Dsl.CallData.ParamClassEnum.PARAM_CLASS_PARENTHESIS: if (callData.GetParamNum() > 0) { int ct = callData.GetParamNum(); return(CalcValue(callData.GetParam(ct - 1))); } else { //不支持的语法 return(null); } case (int)Dsl.CallData.ParamClassEnum.PARAM_CLASS_BRACKET: { IStoryValue <object> ret = null; IStoryValueFactory factory = GetFactory("jsonarray"); if (null != factory) { try { ret = factory.Build(); ret.InitFromDsl(param); } catch (Exception ex) { GameFramework.LogSystem.Error("value:{0} line:{1} failed.", param.ToScriptString(), param.GetLine()); throw ex; } } return(ret); } default: return(null); } } else { Dsl.FunctionData funcData = param as Dsl.FunctionData; if (null != funcData && funcData.HaveStatement()) { callData = funcData.Call; if (null == callData || !callData.HaveParam()) { IStoryValue <object> ret = null; IStoryValueFactory factory = GetFactory("jsonobject"); if (null != factory) { try { ret = factory.Build(); ret.InitFromDsl(param); } catch (Exception ex) { GameFramework.LogSystem.Error("value:{0} line:{1} failed.", param.ToScriptString(), param.GetLine()); throw ex; } } return(ret); } else { //不支持的语法 return(null); } } else { //不支持的语法 return(null); } } } else { Dsl.CallData callData = param as Dsl.CallData; if (null != callData) { Dsl.CallData innerCall = callData.Call; if (callData.IsHighOrder && callData.GetParamClass() == (int)Dsl.CallData.ParamClassEnum.PARAM_CLASS_PARENTHESIS && ( innerCall.GetParamClass() == (int)Dsl.CallData.ParamClassEnum.PARAM_CLASS_PERIOD || innerCall.GetParamClass() == (int)Dsl.CallData.ParamClassEnum.PARAM_CLASS_BRACKET || innerCall.GetParamClass() == (int)Dsl.CallData.ParamClassEnum.PARAM_CLASS_PERIOD_BRACE || innerCall.GetParamClass() == (int)Dsl.CallData.ParamClassEnum.PARAM_CLASS_PERIOD_BRACKET || innerCall.GetParamClass() == (int)Dsl.CallData.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,...) Dsl.CallData newCall = new Dsl.CallData(); newCall.Name = new Dsl.ValueData("dotnetcall", Dsl.ValueData.ID_TOKEN); newCall.SetParamClass((int)Dsl.CallData.ParamClassEnum.PARAM_CLASS_PARENTHESIS); if (innerCall.IsHighOrder) { newCall.Params.Add(innerCall.Call); newCall.Params.Add(innerCall.GetParam(0)); 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(innerCall.GetParam(0)); 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.CallData.ParamClassEnum.PARAM_CLASS_PERIOD || callData.GetParamClass() == (int)Dsl.CallData.ParamClassEnum.PARAM_CLASS_BRACKET || callData.GetParamClass() == (int)Dsl.CallData.ParamClassEnum.PARAM_CLASS_PERIOD_BRACE || callData.GetParamClass() == (int)Dsl.CallData.ParamClassEnum.PARAM_CLASS_PERIOD_BRACKET || callData.GetParamClass() == (int)Dsl.CallData.ParamClassEnum.PARAM_CLASS_PERIOD_PARENTHESIS) { //obj.property or obj[property] or obj.(property) or obj.[property] or obj.{property} -> dotnetget(obj,property) Dsl.CallData newCall = new Dsl.CallData(); newCall.Name = new Dsl.ValueData("dotnetget", Dsl.ValueData.ID_TOKEN); newCall.SetParamClass((int)Dsl.CallData.ParamClassEnum.PARAM_CLASS_PARENTHESIS); if (callData.IsHighOrder) { newCall.Params.Add(callData.Call); newCall.Params.Add(callData.GetParam(0)); } else { newCall.Params.Add(callData.Name); newCall.Params.Add(callData.GetParam(0)); } return(CalcValue(newCall)); } } IStoryValue <object> ret = null; string id = param.GetId(); IStoryValueFactory factory = GetFactory(id); if (null != factory) { try { ret = factory.Build(); ret.InitFromDsl(param); } catch (Exception ex) { GameFramework.LogSystem.Error("value:{0} line:{1} failed.", param.ToScriptString(), param.GetLine()); throw ex; } } return(ret); } } }
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); } } } }
public static void FinalParse(Dsl.DslInfo dslInfo) { string id = dslInfo.GetId(); if (id == "command") { Dsl.FunctionData first = dslInfo.First; string name = first.Call.GetParamId(0); IStoryCommandFactory factory = StoryCommandManager.Instance.FindFactory(name); if (null != factory) { StorySystem.CommonCommands.CompositeCommand cmd = factory.Create() as StorySystem.CommonCommands.CompositeCommand; cmd.InitialCommands.Clear(); Dsl.FunctionData last = dslInfo.Last; var bodyId = last.GetId(); if (bodyId == "body" || bodyId != "opts") { for (int ix = 0; ix < last.GetStatementNum(); ++ix) { Dsl.ISyntaxComponent syntaxComp = last.GetStatement(ix); IStoryCommand sub = StoryCommandManager.Instance.CreateCommand(syntaxComp); cmd.InitialCommands.Add(sub); } } else { LogSystem.Error("Can't find command body '{0}'", name); } } else { LogSystem.Error("Can't find command factory '{0}'", name); } } else if (id == "value") { Dsl.FunctionData first = dslInfo.First; string name = first.Call.GetParamId(0); IStoryValueFactory factory = StoryValueManager.Instance.FindFactory(name); if (null != factory) { StorySystem.CommonValues.CompositeValue val = factory.Build() as StorySystem.CommonValues.CompositeValue; val.InitialCommands.Clear(); Dsl.FunctionData last = dslInfo.Last; var bodyId = last.GetId(); if (bodyId == "body" || bodyId != "opts") { for (int ix = 0; ix < last.GetStatementNum(); ++ix) { Dsl.ISyntaxComponent syntaxComp = last.GetStatement(ix); IStoryCommand sub = StoryCommandManager.Instance.CreateCommand(syntaxComp); val.InitialCommands.Add(sub); } } else { LogSystem.Error("Can't find value body '{0}'", name); } } else { LogSystem.Error("Can't find value factory '{0}'", name); } } }