protected override bool Load(FunctionData funcData) { if (funcData.IsHighOrder) { var cd = funcData.LowerOrderFunction; LoadCall(cd); } else if (funcData.HaveParam()) { LoadCall(funcData); } if (funcData.HaveStatement()) { foreach (var comp in funcData.Params) { var fcd = comp as Dsl.FunctionData; if (null != fcd) { var key = fcd.GetId(); StoryValue val = new StoryValue(); val.InitFromDsl(fcd.GetParam(0)); m_LoadedOptArgs[key] = val; } } } return(true); }
protected override bool Load(FunctionData funcData) { if (!funcData.IsHighOrder && funcData.HaveParam()) { m_Func = funcData.GetId(); int num = funcData.GetParamNum(); for (int ix = 0; ix < num; ++ix) { Dsl.ISyntaxComponent param = funcData.GetParam(ix); m_Args.Add(Interpreter.Load(param)); } return(true); } return(false); }
private void endStatement() { StatementData statement = popStatement(); if ((null != mSetStringDelimiter || null != mSetScriptDelimiter) && statement.GetId() == "@@delimiter" && statement.Functions.Count == 1 && (statement.First.GetParamNum() == 1 || statement.First.GetParamNum() == 3) && !statement.First.IsHighOrder) { FunctionData call = statement.First; string type = call.GetParamId(0); if (call.GetParamNum() == 3) { string begin = call.GetParamId(1); string end = call.GetParamId(2); if (type == "string") { setStringDelimiter(begin, end); } else if (type == "script") { setScriptDelimiter(begin, end); } else { //invalid } } else { if (type == "string") { setStringDelimiter(string.Empty, string.Empty); } else if (type == "script") { setScriptDelimiter(string.Empty, string.Empty); } else { //invalid } } return; } bool commentOnNewLine; IList <string> cmts = GetComments(out commentOnNewLine); if (cmts.Count > 0) { if (statement.LastComments.Count <= 0) { statement.LastCommentOnNewLine = commentOnNewLine; } statement.LastComments.AddRange(cmts); } if (mStatementSemanticStack.Count == 0) { //化简只需要处理一级,参数与语句部分应该在添加到语句时已经处理了 AbstractSyntaxComponent statementSyntax = simplifyStatement(statement); ValueData vdSyntax = statementSyntax as ValueData; if (!statementSyntax.IsValid()) { //_epsilon_表达式无语句语义 if (mScriptDatas.Count > 0) { ISyntaxComponent last = mScriptDatas[mScriptDatas.Count - 1]; if (last.LastComments.Count <= 0) { last.LastCommentOnNewLine = statementSyntax.FirstCommentOnNewLine; } last.LastComments.AddRange(statementSyntax.FirstComments); last.LastComments.AddRange(statementSyntax.LastComments); } return; } else if (null != vdSyntax) { //如果语句是普通值,注释挪到上一语句 if (mScriptDatas.Count > 0) { ISyntaxComponent last = mScriptDatas[mScriptDatas.Count - 1]; if (last.LastComments.Count <= 0) { last.LastCommentOnNewLine = statement.FirstCommentOnNewLine; } last.LastComments.AddRange(statement.FirstComments); last.LastComments.AddRange(statement.LastComments); } } else { //上一行语句的注释挪到上一行语句 if (mScriptDatas.Count > 0 && !statementSyntax.FirstCommentOnNewLine && statementSyntax.FirstComments.Count > 0) { string cmt = statementSyntax.FirstComments[0]; statementSyntax.FirstComments.RemoveAt(0); statementSyntax.FirstCommentOnNewLine = true; ISyntaxComponent last = mScriptDatas[mScriptDatas.Count - 1]; if (last.LastComments.Count <= 0) { last.LastCommentOnNewLine = false; } last.LastComments.Add(cmt); } } //顶层元素结束 mScriptDatas.Add(statementSyntax); } else { //化简只需要处理一级,参数与语句部分应该在添加到语句时已经处理了 AbstractSyntaxComponent statementSyntax = simplifyStatement(statement); ValueData vdSyntax = statementSyntax as ValueData; FunctionData func = getLastFunction(); if (func.HaveParam()) { //如果是参数里的注释,保持原样。普通值上的注释会丢弃,嵌入的注释如果挪到行尾会比较莫名其妙。 if (!statementSyntax.IsValid()) { return; } } else if (!statement.IsValid()) { //_epsilon_表达式无语句语义 if (func.Params.Count > 0 && statementSyntax.FirstComments.Count > 0) { AbstractSyntaxComponent last = func.Params[func.Params.Count - 1] as AbstractSyntaxComponent; if (last.LastComments.Count <= 0) { last.LastCommentOnNewLine = statementSyntax.FirstCommentOnNewLine; } last.LastComments.AddRange(statementSyntax.FirstComments); last.LastComments.AddRange(statementSyntax.LastComments); } return; } else if (null != vdSyntax) { //如果语句是普通值,注释挪到上一语句 if (func.Params.Count > 0) { AbstractSyntaxComponent last = func.Params[func.Params.Count - 1] as AbstractSyntaxComponent; if (last.LastComments.Count <= 0) { last.LastCommentOnNewLine = statement.FirstCommentOnNewLine; } last.LastComments.AddRange(statement.FirstComments); last.LastComments.AddRange(statement.LastComments); } else { func.Comments.AddRange(statement.FirstComments); func.Comments.AddRange(statement.LastComments); } } else { //上一行语句的注释挪到上一行语句或外层函数头或外层函数 if (!statementSyntax.FirstCommentOnNewLine && statementSyntax.FirstComments.Count > 0) { string cmt = statementSyntax.FirstComments[0]; statementSyntax.FirstComments.RemoveAt(0); statementSyntax.FirstCommentOnNewLine = true; if (func.Params.Count > 0) { AbstractSyntaxComponent last = func.Params[func.Params.Count - 1] as AbstractSyntaxComponent; if (last.LastComments.Count <= 0) { last.LastCommentOnNewLine = false; } last.LastComments.Add(cmt); } else if (func.IsHighOrder) { func.LowerOrderFunction.Comments.Add(cmt); } else { func.Comments.Add(cmt); } } } func.AddParam(statementSyntax); } }