Exemple #1
0
        public override string ToScriptString()
        {
#if FULL_VERSION
            //与write方法不同,这里输出无缩进单行表示
            FunctionData tempData = First;
            CallData     callData = null;
            callData = tempData.Call;
            if (null != callData && callData.GetParamClass() == (int)CallData.ParamClassEnum.PARAM_CLASS_TERNARY_OPERATOR)
            {
                if (callData.HaveId() && callData.HaveParam() && tempData.HaveStatement())
                {
                    string line = string.Format("{0} {1} {2}", callData.GetParam(0).ToScriptString(), callData.GetId(), tempData.GetStatement(0).ToScriptString());
                    if (Functions.Count == 2)
                    {
                        FunctionData funcData = Functions[1];
                        if (funcData.HaveId() && funcData.HaveStatement())
                        {
                            line = string.Format("{0} {1} {2}", line, funcData.GetId(), funcData.GetStatement(0).ToScriptString());
                        }
                    }
                    return(line);
                }
                else
                {
                    return("");
                }
            }
            else
            {
                StringBuilder stream = new StringBuilder();
                int           ct     = Functions.Count;
                for (int i = 0; i < ct; ++i)
                {
                    FunctionData funcData = Functions[i];
                    stream.Append(funcData.ToScriptString());
                }
                return(stream.ToString());
            }
#else
            return(ToString());
#endif
        }
Exemple #2
0
        public static void writeStatementData(StringBuilder stream, StatementData data, int indent)
        {
#if FULL_VERSION
            FunctionData tempData = data.First;
            CallData     callData = tempData.Call;
            if (null != callData && callData.GetParamClass() == (int)CallData.ParamClassEnum.PARAM_CLASS_TERNARY_OPERATOR)
            {
                if (callData.HaveId() && callData.HaveParam() && tempData.HaveStatement())
                {
                    string line = string.Format("{0} {1} {2}", callData.GetParam(0).ToScriptString(), callData.GetId(), tempData.GetStatement(0).ToScriptString());
                    if (data.Functions.Count == 2)
                    {
                        FunctionData funcData = data.Functions[1];
                        if (funcData.HaveId() && funcData.HaveStatement())
                        {
                            line = string.Format("{0} {1} {2}", line, funcData.GetId(), funcData.GetStatement(0).ToScriptString());
                        }
                    }
                    writeLine(stream, line + ";", indent);
                }
            }
            else
            {
                int  ct = data.Functions.Count;
                bool isLastOfStatement = false;
                if (ct == 0)
                {
                    isLastOfStatement = true;
                }
                for (int i = 0; i < ct; ++i)
                {
                    if (i == ct - 1)
                    {
                        isLastOfStatement = true;
                    }
                    FunctionData func = data.Functions[i];
                    writeFunctionData(stream, func, indent, isLastOfStatement);
                }
            }
#endif
        }
Exemple #3
0
        public static string getCallString(CallData data)
        {
#if FULL_VERSION
            string lineNo = "";//formatString("/* %d */",data.GetLine());
            string line   = "";
            if (data.IsHighOrder)
            {
                line = getCallString(data.Call);
            }
            else if (data.HaveId())
            {
                line = quoteString(data.GetId(), data.GetIdType());
            }
            if (data.HaveParam())
            {
                int paramClass = data.GetParamClass();
                if ((int)CallData.ParamClassEnum.PARAM_CLASS_OPERATOR == paramClass)
                {
                    switch (data.GetParamNum())
                    {
                    case 1:
                        return(string.Format("{0} {1}", line, data.GetParam(0).ToScriptString()));

                    case 2:
                        return(string.Format("{0} {1} {2}", data.GetParam(0).ToScriptString(), line, data.GetParam(1).ToScriptString()));

                    default:
                        return(line);
                    }
                }
                else
                {
                    string lbracket = "";
                    string rbracket = "";
                    switch (paramClass)
                    {
                    case (int)CallData.ParamClassEnum.PARAM_CLASS_PARENTHESIS:
                        lbracket = "(";
                        rbracket = ")";
                        break;

                    case (int)CallData.ParamClassEnum.PARAM_CLASS_BRACKET:
                        lbracket = "[";
                        rbracket = "]";
                        break;

                    case (int)CallData.ParamClassEnum.PARAM_CLASS_PERIOD:
                        lbracket = ".";
                        rbracket = "";
                        break;

                    case (int)CallData.ParamClassEnum.PARAM_CLASS_PERIOD_PARENTHESIS:
                        lbracket = ".(";
                        rbracket = ")";
                        break;

                    case (int)CallData.ParamClassEnum.PARAM_CLASS_PERIOD_BRACKET:
                        lbracket = ".[";
                        rbracket = "]";
                        break;

                    case (int)CallData.ParamClassEnum.PARAM_CLASS_PERIOD_BRACE:
                        lbracket = ".{";
                        rbracket = "}";
                        break;
                    }
                    StringBuilder stream = new StringBuilder();
                    stream.Append(lbracket);
                    int ct = data.GetParamNum();
                    for (int i = 0; i < ct; ++i)
                    {
                        if (i > 0)
                        {
                            stream.Append(",");
                        }
                        ISyntaxComponent param = data.GetParam(i);
                        if ((int)CallData.ParamClassEnum.PARAM_CLASS_PERIOD == paramClass)
                        {
                            stream.Append(unquoteString(param.ToScriptString()));
                        }
                        else
                        {
                            stream.Append(param.ToScriptString());
                        }
                    }
                    stream.Append(rbracket);
                    return(string.Format("{0}{1}{2}", lineNo, line, stream.ToString()));
                }
            }
            else
            {
                return(string.Format("{0}{1}", lineNo, line));
            }
#else
            return("");
#endif
        }