示例#1
0
        public object Clone()
        {
            var c = new ParameterConfig(index)
            {
                isConfig      = isConfig,
                isString      = isString,
                isFixedNumber = isFixedNumber,
                isTable       = isTable,
            };

            if (fields != null)
            {
                c.fields = new List <Token>();
                foreach (var field in fields)
                {
                    c.fields.Add((Token)field.Clone());
                }
            }
            return(c);
        }
示例#2
0
        public override string ToString()
        {
            StringBuilder sb = new StringBuilder();

            switch (pType)
            {
            case FCodeNodeType.Function:
                AppendLocal(sb);
                sb.Append(fcodeFunctionName);
                sb.Append('(');
                if (parameterConfigs != null && parameterConfigs.Count > 0)
                {
                    parameterConfigs.Sort((a, b) => a.index - b.index);
                    ParameterConfig prev = null;
                    foreach (var pc in parameterConfigs)
                    {
                        if (pc.fields == null || pc.fields.Count == 0 || pc.index - prev?.index > 1 || (prev == null && pc.index > 0))
                        {
                            continue;
                        }
                        var varSb = new StringBuilder();
                        foreach (var fieldToken in pc.fields)
                        {
                            varSb.Append(fieldToken.Original());
                        }
                        if (string.IsNullOrWhiteSpace(varSb.ToString()))
                        {
                            continue;
                        }
                        if (pc.index > 0)
                        {
                            sb.Append(", ");
                        }
                        var configPrefix = pc.isConfig? "config.": "";
                        if (pc.isString)
                        {
                            sb.Append('\'');
                        }
                        sb.Append(configPrefix);
                        sb.Append(varSb);
                        if (pc.isString)
                        {
                            sb.Append('\'');
                        }
                        prev = pc;
                    }
                }
                sb.Append(')');
                break;

            case FCodeNodeType.If:
                sb.Append($"if {expression} then");
                break;

            case FCodeNodeType.Expression:
                if (isReturnValue)
                {
                    AppendLocal(sb);
                }
                sb.Append(expression);
                break;

            case FCodeNodeType.Foreach:
                sb.Append($"for {foreachPairsKey}, {foreachPairsVal} in pairs({expression}) do");
                break;

            case FCodeNodeType.End:
                sb.Append("end");
                break;

            default:
                Debug.LogWarning($"DisplayName for FCodeNodeType : {pType.ToString()} not found !");
                break;
            }

            return(sb.ToString());
        }