SOURCE

let arr = [
    "V3(Os, wA)",
    "V3(EG, HG), jZ), sZ), Tj), nj)",
    "V3(LA, Rl), LA), Rl), LC = V3(V3(V3(V3(V3(hg, Gg), Rl), Mg(QK, z3(Jm, [vM, KA, LC]))), Rl), LC))"
];


let originArr = [
    "V3(Os, wA)",
    "V3(EG, HG), jZ), sZ), Tj), nj)",
    "V3(LA, Rl), LA), Rl), LC = V3(V3(V3(V3(V3(hg, Gg), Rl), Mg(QK, z3(Jm, [vM, KA, LC]))), Rl), LC))"
];

for(let i = 0; i < arr.length; i++){
    // console.log(arr[i]);
    let FArr = arr[i].match(eval(`/V3\\((?!V3)(.*?)\\)/gm`));
    // console.log(FArr);

    for(let m = 0; m < FArr.length; m ++){
        let startIndex = arr[i].indexOf(FArr[m]);
        let leftbreak = [], rightbreak = [] ,sk = 0, dk = 0;

        for(let n = startIndex; n < arr[i].length; n++){
            
            if(arr[i][n] == '"'){
                if(arr[i][n - 1] != "\\"){
                    sk++;
                    sk % 2 == 0 ? dk = 0 : '';
                }else{
                    if(arr[i][n - 2] == "\\"){
                        sk++;
                        sk % 2 == 0 ? dk = 0 : '';
                    }
                }
            }

            if(arr[i][n] == "'"){
                if(arr[i][n - 1] != "\\"){
                    dk++;
                    dk % 2 == 0 ? sk = 0 : '';
                }else{
                    if(arr[i][n - 2] == "\\"){
                        dk++;
                        dk % 2 == 0 ? sk = 0 : '';
                    }
                }
            }

            if(arr[i][n] == "(" && sk % 2 == 0 && dk % 2 == 0){
                leftbreak.push("(");
            }

            if(arr[i][n] == ")" && sk % 2 == 0 && dk % 2 == 0){
                rightbreak.push(")");
            }

            if(leftbreak.length === rightbreak.length && leftbreak.length && rightbreak.length){
                let prev = `${arr[i].substring(startIndex ,n + 1)}`;
                // console.log(startIndex ,n);
                // console.log(arr[i].substring(startIndex,n + 1));
                //console.log(ParseArguments(arr[i].substring(startIndex,n + 1) , '+'));
                arr[i] = arr[i].replace(prev ,ParseArguments(arr[i].substring(startIndex,n + 1) , '+'));
                console.log(arr[i]);
                break;
            }
        }
    }
}


function ParseArguments(str ,sym){
    let arr = str.substring(3, str.length - 1).split(', ');
    if(str.split(',').length === 2){
        return `(${arr[0]} ${sym} ${arr[1]})`
    }else{
        let cand = [];
        arr.forEach((el ,i) => {
            if(/^[a-z|A-Z|0-9]{2,3}$/.test(el)) cand.push(i);
        });
        
        let strings = '(';
        if(cand.length == 0){ // 啥情况都有

            let T = arr.toString().match(/[a-z|A-Z|0-9]{2,3}\([a-z|A-Z|0-9]{2,3}\(/gm);
            let prev = 0;

            if(T){
                for(let i = 0; i < arr.length; i++){
                    if(arr[i].match(/.*?(\]\))$/gm)){
                        prev = i;
                        break;
                    } 
                }
            }else{
                for(let i = 0; i < arr.length; i++){
                    if(arr[i].match(/.*?(\))$/gm)){
                        prev = i;
                        break;
                    } 
                }
            }

            arr.forEach((item ,it)=>{
                if(it == arr.length - 1){
                    strings += item + ')';
                }else if(it == prev){
                    strings += item + ' ' + sym + ' ';
                }else{
                    strings += item + ',' + ' ';
                }
            });
            return strings


        }else if(cand.length == 1 && cand[0] == arr.length - 1){ //目标在最后一位
            arr.forEach((item ,it)=>{
                if(it == cand[0]){
                    strings += ' ' + item + ')';
                }else if(it == cand[0] - 1){
                    strings += item + ` ${sym}`;
                }else{
                    strings += item + ',';
                }
            });
            return strings
        }else if(cand.length == 1 && cand[0] == 0){ //目标在第一位
            arr.forEach((item ,it)=>{
                if(it == 0){
                    strings += item + ' ' + sym + ' '
                }else if(it == arr.length - 1){
                    strings += ' ' + item + ')';
                }else{
                    strings += item + ',';
                }
            });
            return strings
        }else{
            if(cand[0] === 0){
                arr.forEach((item ,it)=>{
                    if(it == 0){
                        strings += item + ' ' + sym + ' '
                    }else if(it == arr.length - 1){
                        strings += ' ' + item + ')';
                    }else{
                        strings += item + ',';
                    }
                });
                return strings
            }else{
                let num = -1;
                cand.forEach((item ,it)=>{
                    let fu = arr[item - 1][arr[item - 1].length - 1];
                    if(fu == ']' || fu == ')' || fu == ')]' || fu == '])' || fu == '))' || fu == ']]'){
                        num = item;
                    }
                });

                if(num != -1){
                    if(num == 0){
                        strings += arr[num] + sym + ' ';
                        arr.splice(0,1);
                        arr.forEach((item ,it)=>{
                            if(it == arr.length - 1){
                                strings += ' ' + item + ')';
                            }else{
                                strings += item + ',';
                            }
                        });
                        return strings
                    }else if(num == arr.length - 1){
                        arr.forEach((item ,it)=>{
                            if(it == arr.length - 1){
                                strings += ' ' + item + ')';
                            }else if(it == arr.length - 2){
                                strings += item + ' ' + sym + ' ';
                            }else{
                                strings += item + ',';
                            }
                        });
                        return strings
                    }
                }else{
                    let prev = 0;
                    for(var i = 0; i < arr.length; i++){
                        if(arr[i].match(/.*?(\)|\]|(\)\])|(\]\)))$/gm)){
                            prev = i;
                            break;
                        } 
                    }
                    arr.forEach((item ,it)=>{
                        if(it == arr.length - 1){
                            strings += item + ')';
                        }else if(it == prev){
                            strings += item + ' ' + sym + ' ';
                        }else{
                            strings += item + ',' + ' ';
                        }
                    });
                    return strings
                }
            }
        }
    }
}
console 命令行工具 X clear

                    
>
console