Example #1
0
        internal void endStatement()
        {
            StatementData statement = popStatement();

            if (mStatementSemanticStack.Count == 0)
            {
                simplifyStatementData(statement);
                if (!statement.IsValid())
                {
                    //_epsilon_表达式无语句语义
                    return;
                }
                //顶层元素结束
                ScriptableDataInfo scriptData = new ScriptableDataInfo();
                scriptData.CopyFrom(statement);
                scriptData.SetLoaded(true);
                mScriptDatas.Add(scriptData);
            }
            else
            {
                ISyntaxComponent statementSyntax = simplifyStatement(statement);

                FunctionData func = getLastFunction();
                switch (func.GetExtentClass())
                {
                case (int)FunctionData.ExtentClassEnum.EXTENT_CLASS_NOTHING:
                {
                    /*这段先暂时注掉,忘记原来为啥要允许空语句作函数参数了(现在对于明确的空串参数不会判断为无效语句了)
                     *        if(func.Call.getParamClass()==(int)CallData.ParamClassEnum.PARAM_CLASS_OPERATOR && !statement.IsValid())
                     *            return;//操作符就不支持空语句作参数了
                     *        //函数参数,允许空语句,用于表达默认状态(副作用是a()与a[]将总是会有一个空语句参数)。
                     */
                    if (statement.IsValid())
                    {
                        func.Call.AddParams(statementSyntax);
                    }
                }
                break;

                case (int)FunctionData.ExtentClassEnum.EXTENT_CLASS_STATEMENT:
                {
                    if (!statement.IsValid())
                    {
                        //_epsilon_表达式无语句语义
                        return;
                    }
                    //函数扩展语句部分
                    func.AddStatement(statementSyntax);
                }
                break;
                }
            }
        }
Example #2
0
        internal void endStatement()
        {
            StatementData statement = popStatement();

            if (statement.GetId() == "@@delimiter" && statement.Functions.Count == 1 && (statement.First.Call.GetParamNum() == 1 || statement.First.Call.GetParamNum() == 3) && !statement.First.Call.IsHighOrder)
            {
                CallData call = statement.First.Call;
                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)
            {
                simplifyStatementData(statement);
                if (!statement.IsValid())
                {
                    //_epsilon_表达式无语句语义
                    if (mScriptDatas.Count > 0 && statement.FirstComments.Count > 0)
                    {
                        DslInfo last = mScriptDatas[mScriptDatas.Count - 1];
                        if (last.LastComments.Count <= 0)
                        {
                            last.LastCommentOnNewLine = statement.FirstCommentOnNewLine;
                        }
                        last.LastComments.AddRange(statement.FirstComments);
                    }
                    return;
                }
                else
                {
                    if (mScriptDatas.Count > 0 && !statement.FirstCommentOnNewLine && statement.FirstComments.Count > 0)
                    {
                        string cmt = statement.FirstComments[0];
                        statement.FirstComments.RemoveAt(0);
                        statement.FirstCommentOnNewLine = true;
                        DslInfo last = mScriptDatas[mScriptDatas.Count - 1];
                        if (last.LastComments.Count <= 0)
                        {
                            last.LastCommentOnNewLine = false;
                        }
                        last.LastComments.Add(cmt);
                    }
                }
                //顶层元素结束
                DslInfo scriptData = new DslInfo();
                scriptData.CopyFrom(statement);
                scriptData.SetLoaded(true);
                mScriptDatas.Add(scriptData);
            }
            else
            {
                AbstractSyntaxComponent statementSyntax = simplifyStatement(statement);

                FunctionData func = getLastFunction();
                switch (func.GetExtentClass())
                {
                case (int)FunctionData.ExtentClassEnum.EXTENT_CLASS_NOTHING: {
                    /*这段先暂时注掉,忘记原来为啥要允许空语句作函数参数了(现在对于明确的空串参数不会判断为无效语句了)
                     * if(func.Call.getParamClass()==(int)CallData.ParamClassEnum.PARAM_CLASS_OPERATOR && !statement.IsValid())
                     * return;//操作符就不支持空语句作参数了
                     * //函数参数,允许空语句,用于表达默认状态(副作用是a()与a[]将总是会有一个空语句参数)。
                     */
                    if (statementSyntax.IsValid())
                    {
                        func.Call.AddParams(statementSyntax);
                    }
                    else if (statementSyntax.FirstComments.Count > 0)
                    {
                        func.Call.Comments.AddRange(statementSyntax.FirstComments);
                    }
                }
                break;

                case (int)FunctionData.ExtentClassEnum.EXTENT_CLASS_STATEMENT: {
                    if (!statementSyntax.IsValid())
                    {
                        //_epsilon_表达式无语句语义
                        if (func.Statements.Count > 0 && statementSyntax.FirstComments.Count > 0)
                        {
                            AbstractSyntaxComponent last = func.Statements[func.Statements.Count - 1] as AbstractSyntaxComponent;
                            if (last.LastComments.Count <= 0)
                            {
                                last.LastCommentOnNewLine = statementSyntax.FirstCommentOnNewLine;
                            }
                            last.LastComments.AddRange(statementSyntax.FirstComments);
                        }
                        return;
                    }
                    else
                    {
                        if (!statementSyntax.FirstCommentOnNewLine && statementSyntax.FirstComments.Count > 0)
                        {
                            string cmt = statementSyntax.FirstComments[0];
                            statementSyntax.FirstComments.RemoveAt(0);
                            statementSyntax.FirstCommentOnNewLine = true;
                            if (func.Statements.Count > 0)
                            {
                                AbstractSyntaxComponent last = func.Statements[func.Statements.Count - 1] as AbstractSyntaxComponent;
                                if (last.LastComments.Count <= 0)
                                {
                                    last.LastCommentOnNewLine = false;
                                }
                                last.LastComments.Add(cmt);
                            }
                            else
                            {
                                func.Call.Comments.Add(cmt);
                            }
                        }
                    }
                    //函数扩展语句部分
                    func.AddStatement(statementSyntax);
                }
                break;
                }
            }
        }