コード例 #1
0
ファイル: DslAction.cs プロジェクト: wangyonghui888/DSL
        private void buildOperator()
        {
            int    type;
            string name = pop(out type);

            StatementData    arg     = popStatement();
            ISyntaxComponent argComp = simplifyStatement(arg);

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

            first.Name.SetLine(getLastLineNumber());

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

            mStatementSemanticStack.Push(_statement);

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

            if (!func.IsValid())
            {
                if (name.Length > 0 && name[0] == '`')
                {
                    func.SetParamClass((int)(FunctionData.ParamClassEnum.PARAM_CLASS_WRAP_INFIX_CALL_MASK | FunctionData.ParamClassEnum.PARAM_CLASS_OPERATOR));

                    func.Name.SetId(name.Substring(1));
                    func.Name.SetType(type);
                }
                else
                {
                    func.SetParamClass((int)FunctionData.ParamClassEnum.PARAM_CLASS_OPERATOR);

                    func.Name.SetId(name);
                    func.Name.SetType(type);
                }
                if (argComp.IsValid())
                {
                    func.AddParam(argComp);
                }
            }
        }
コード例 #2
0
ファイル: DslAction.cs プロジェクト: wangyonghui888/DSL
        private void setExternScript()
        {
            FunctionData func = getLastFunction();

            func.AddParam(getLastToken());
        }
コード例 #3
0
ファイル: DslAction.cs プロジェクト: wangyonghui888/DSL
        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);
            }
        }