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 buildFirstTernaryOperator()
        {
            int    type;
            string name = pop(out type);

            StatementData arg = popStatement();

            StatementData _statement = newStatement();
            FunctionData  first      = _statement.First;

            first.Call.Name.SetLine(getLastLineNumber());

            _statement.CopyFirstComments(arg);
            arg.FirstComments.Clear();

            mStatementSemanticStack.Push(_statement);

            StatementData statement = getCurStatement();
            FunctionData  func      = getLastFunction();

            if (!func.IsValid())
            {
                func.Call.SetParamClass((int)CallData.ParamClassEnum.PARAM_CLASS_TERNARY_OPERATOR);
                func.SetExtentClass((int)FunctionData.ExtentClassEnum.EXTENT_CLASS_STATEMENT);

                func.Call.Name.SetId(name);
                func.Call.Name.SetType(type);

                if (arg.IsValid())
                {
                    func.Call.AddParams(arg);
                }
            }
        }
Example #3
0
        internal void buildOperator()
        {
            int    type;
            string name = pop(out type);

            StatementData arg = popStatement();

            StatementData _statement = newStatement();
            FunctionData  first      = _statement.First;

            first.Call.Name.SetLine(getLastLineNumber());
            mStatementSemanticStack.Push(_statement);

            StatementData statement = getCurStatement();
            FunctionData  func      = getLastFunction();

            if (!func.IsValid())
            {
                func.Call.SetParamClass((int)CallData.ParamClassEnum.PARAM_CLASS_OPERATOR);

                func.Call.Name.SetId(name);
                func.Call.Name.SetType(type);

                if (arg.IsValid())
                {
                    func.Call.AddParams(arg);
                }
            }
        }
Example #4
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;
                }
            }
        }
Example #5
0
        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);
            }
        }