Read this code:
const fs = require('fs');
const { spawn } = require('child_process');

const config = 'CONFIG';
let mainName = 'app.pypp';

if (fs.existsSync(config)) {
    fs.readFile(config, 'utf8', (err, data) => {
        if (err) throw err;
        const match = data.match(/APP_NAME=(.+)\.pypp/);
        if (match) {
            mainName = match[1] + '.pypp';
        } else {
            formatError(`Couldn't find the main file name in the config file.`);
            process.exit(1);
        }

        if (fs.existsSync(mainName)) {
            translate(mainName);
        } else {
            formatError(`Couldn't find the file '${mainName}' in directory.`);
            process.exit(1);
        }
    });
} else {
    if (fs.existsSync(mainName)) {
        translate(mainName);
    } else {
        formatError(`Couldn't find the file '${mainName}' in directory.`);
        process.exit(1);
    }
}

function formatError(error, color = '\x1b[31m') {
    console.error(`${color}ERROR: ${error}\x1b[37m`);
}

function translate(fileName) {
    fs.readFile(fileName, 'utf8', (err, data) => {
        if (err) throw err;

        const formattedData = processCode(data);

        fs.writeFile('app.py', formattedData, err => {
            if (err) throw err;

            const pythonProcess = spawn('python', ['app.py'], { stdio: 'inherit' });

            pythonProcess.on('close', () => {
                fs.unlink('app.py', err => {
                    if (err) throw err;
                });
            });
        });
    });
}

function processCode(code) {
    let functionCounter = 0;
    let output = '';
    let functionsCode = '';
    let i = 0;

    // Set to store readonly variable names
    let readonlyVars = new Set();

    while (i < code.length) {
        // Skip whitespace and accumulate it
        let whitespace = '';
        while (i < code.length && /\s/.test(code[i])) {
            whitespace += code[i++];
        }
        output += whitespace;

        // Check for 'readonly' keyword
        if (code.startsWith('readonly', i)) {
            let j = i + 'readonly'.length;

            // Skip any whitespace after 'readonly'
            while (j < code.length && /\s/.test(code[j])) j++;

            // Now extract variable name
            let varNameMatch = code.substr(j).match(/^([a-zA-Z_][a-zA-Z0-9_]*)/);
            if (varNameMatch) {
                let varName = varNameMatch[1];
                j += varName.length;

                // Skip whitespace
                while (j < code.length && /\s/.test(code[j])) j++;

                if (code[j] === '=') {
                    j++; // Skip '='

                    // Skip whitespace
                    while (j < code.length && /\s/.test(code[j])) j++;

                    // Extract value
                    let valueStart = j;
                    while (j < code.length && code[j] !== '\n') j++;
                    let value = code.substring(valueStart, j).trim();

                    // Add to readonlyVars
                    readonlyVars.add(varName);

                    // Replace 'readonly x = y' with 'x = y'
                    output += `${varName} = ${value}\n`;
                    i = j + 1; // Move to next character after the newline
                } else {
                    formatError('Expected "=" after readonly variable name');
                    return '';
                }
                continue;
            } else {
                formatError('Invalid readonly variable declaration');
                return '';
            }
        }
        // Check for 'def' keyword
        else if (code.startsWith('def', i) && (/\s|\(/.test(code[i + 3] || ''))) {
            let j = i + 3;
            // Skip any whitespace after 'def'
            while (j < code.length && /\s/.test(code[j])) j++;

            if (code[j] === '(') {
                // Anonymous function
                let { funcCode, funcName, newIndex } = extractAnonymousFunction(code, i, functionCounter++);
                functionsCode += funcCode + '\n';
                i = newIndex;
                output += funcName;
            } else if (/[a-zA-Z_]/.test(code[j])) {
                // Regular function
                let { funcCode, newIndex } = extractRegularFunction(code, i);
                output += funcCode;
                i = newIndex;
            } else {
                formatError('Invalid function definition after def');
                return '';
            }
        }
        else {
            // Handle assignments
            let assignmentMatch = code.substr(i).match(/^([a-zA-Z_][a-zA-Z0-9_]*)\s*=/);
            if (assignmentMatch) {
                let varName = assignmentMatch[1];

                if (readonlyVars.has(varName)) {
                    // Inject code to raise exception
                    output += `raise Exception("Cannot reassign readonly variable '${varName}'")\n`;
                    // Skip the assignment line
                    while (i < code.length && code[i] !== '\n') i++;
                    i++; // Skip '\n'
                    continue;
                } else {
                    // Copy the assignment
                    while (i < code.length && code[i] !== '\n') {
                        output += code[i++];
                    }
                    output += '\n';
                    i++; // Skip '\n'
                    continue;
                }
            }
            else {
                output += code[i++];
            }
        }
    }

    // Combine the function definitions and the rest of the code
    const finalOutput = functionsCode + output;

    return replaceCurlyBrackets(finalOutput);
}

function extractAnonymousFunction(code, i, functionCounter) {
    let funcName = `__anonymous_function_${functionCounter}`;
    let funcCode = '';
    let j = i; // Position in the code

    // Skip 'def'
    j += 3;

    // Skip whitespace
    while (j < code.length && /\s/.test(code[j])) j++;

    // Expect '()'
    if (code[j] === '(' && code[j + 1] === ')') {
        j += 2; // Skip '()'
    } else {
        formatError('Expected "()" after "def" in anonymous function definition');
        return {
            funcCode: '',
            funcName: '',
            newIndex: code.length
        };
    }

    // Skip whitespace
    while (j < code.length && /\s/.test(code[j])) j++;

    // Expect '{'
    if (code[j] !== '{') {
        formatError('Expected "{" after anonymous function definition');
        return {
            funcCode: '',
            funcName: '',
            newIndex: code.length
        };
    }
    j++; // Skip '{'

    // Extract function body
    let braceDepth = 1;
    let bodyStart = j;

    while (j < code.length && braceDepth > 0) {
        if (code[j] === '{') {
            braceDepth++;
        } else if (code[j] === '}') {
            braceDepth--;
        }
        j++;
    }

    if (braceDepth !== 0) {
        formatError('Unmatched braces in anonymous function');
        return {
            funcCode: '',
            funcName: '',
            newIndex: code.length
        };
    }

    let bodyEnd = j - 1;
    let funcBody = code.slice(bodyStart, bodyEnd);

    // Indent the function body
    let funcBodyLines = funcBody.split('\n');
    funcBodyLines = funcBodyLines.map(line => '    ' + line.trimRight());
    funcBody = funcBodyLines.join('\n');

    // Build the function code
    funcCode += `def ${funcName}():\n${funcBody}`;

    // Return the function code and the new index
    return {
        funcCode,
        funcName,
        newIndex: j
    };
}

function extractRegularFunction(code, i) {
    let j = i; // Position in the code
    let funcDef = '';

    // Build the function definition

    // Skip 'def'
    funcDef += code.substr(j, 3); // 'def'
    j += 3;

    // Accumulate until the opening brace '{'
    while (j < code.length && code[j] !== '{') {
        funcDef += code[j];
        j++;
    }

    if (j >= code.length) {
        formatError('Expected "{" after function declaration');
        return '';
    }

    // Replace '{' with ':'
    funcDef += ':';
    j++; // Skip '{'

    // Now find the matching closing brace '}'
    let braceDepth = 1;
    let functionBodyStart = j;
    while (j < code.length && braceDepth > 0) {
        if (code[j] === '{') braceDepth++;
        else if (code[j] === '}') braceDepth--;
        j++;
    }

    if (braceDepth !== 0) {
        formatError('Unmatched braces in function definition');
        return '';
    }

    let functionBodyEnd = j - 1;
    let functionBody = code.slice(functionBodyStart, functionBodyEnd);

    // Indent the function body
    let functionBodyLines = functionBody.split('\n');
    functionBodyLines = functionBodyLines.map(line => '    ' + line.trimRight());
    functionBody = functionBodyLines.join('\n');

    funcDef += '\n' + functionBody + '\n';

    return {
        funcCode: funcDef,
        newIndex: j
    };
}

function replaceCurlyBrackets(code) {
    let formattedCode = '';
    let indentLevel = 0;
    const indentSize = 4;
    let i = 0;

    // States
    let inSingleQuote = false;
    let inDoubleQuote = false;
    let inTripleSingleQuote = false;
    let inTripleDoubleQuote = false;
    let inSingleLineComment = false;
    let inMultiLineComment = false;
    let braceStack = [];

    while (i < code.length) {
        const char = code[i];
        const nextChars = code.substring(i, i + 3);

        // Handle multi-line comments start
        if (!inSingleQuote && !inDoubleQuote && !inSingleLineComment && !inMultiLineComment) {
            if (code.startsWith('/*', i)) {
                inMultiLineComment = true;
                formattedCode += '#';
                i += 2; // Skip '/*'
                continue;
            }
        }

        // Handle multi-line comments end
        if (inMultiLineComment) {
            if (code.startsWith('*/', i)) {
                inMultiLineComment = false;
                i += 2; // Skip '*/'
                continue;
            }

            if (char === '\n') {
                formattedCode += '\n#';
                i++;
            } else {
                formattedCode += char;
                i++;
            }
            continue;
        }

        // Handle string literals
        if (!inSingleQuote && !inDoubleQuote && !inTripleSingleQuote && !inTripleDoubleQuote) {
            if (nextChars === "'''") {
                inTripleSingleQuote = true;
                formattedCode += nextChars;
                i += 3;
                continue;
            } else if (nextChars === '"""') {
                inTripleDoubleQuote = true;
                formattedCode += nextChars;
                i += 3;
                continue;
            } else if (char === "'") {
                inSingleQuote = true;
                formattedCode += char;
                i++;
                continue;
            } else if (char === '"') {
                inDoubleQuote = true;
                formattedCode += char;
                i++;
                continue;
            }
        } else {
            // Inside string
            if (inTripleSingleQuote && nextChars === "'''") {
                inTripleSingleQuote = false;
                formattedCode += nextChars;
                i += 3;
                continue;
            } else if (inTripleDoubleQuote && nextChars === '"""') {
                inTripleDoubleQuote = false;
                formattedCode += nextChars;
                i += 3;
                continue;
            } else if (inSingleQuote && char === "'" && code[i - 1] !== '\\') {
                inSingleQuote = false;
                formattedCode += char;
                i++;
                continue;
            } else if (inDoubleQuote && char === '"' && code[i - 1] !== '\\') {
                inDoubleQuote = false;
                formattedCode += char;
                i++;
                continue;
            }
            formattedCode += char;
            i++;
            continue;
        }

        // Handle single-line comments
        if (!inSingleQuote && !inDoubleQuote && !inTripleSingleQuote && !inTripleDoubleQuote) {
            if (code.startsWith('//', i)) {
                // Single-line comment
                let endOfLine = code.indexOf('\n', i);
                if (endOfLine === -1) endOfLine = code.length;
                formattedCode += '#' + code.slice(i + 2, endOfLine);
                i = endOfLine;
                continue;
            }
        }

        // Skip semicolons
        if (char === ';') {
            i++;
            continue;
        }

        // Handle braces and code blocks
        if (char === '{') {
            // Determine if this is a code block or a data structure
            let isCodeBlock = false;

            // Look back to see if this is after a control statement or function definition
            let j = formattedCode.length - 1;
            while (j >= 0 && /\s/.test(formattedCode[j])) j--; // Skip whitespace

            if (j >= 0 && /[\):]/.test(formattedCode[j])) {
                isCodeBlock = true;
            } else if (j >= 0 && /[a-zA-Z0-9_]/.test(formattedCode[j])) {
                isCodeBlock = true;
            }

            if (isCodeBlock) {
                braceStack.push('block');
                formattedCode += ':';
                indentLevel++;
            } else {
                braceStack.push('data');
                formattedCode += char;
            }
            i++;
            continue;
        } else if (char === '}') {
            if (braceStack.length === 0) {
                formatError('Unmatched closing brace');
                return '';
            }
            let lastBrace = braceStack.pop();
            if (lastBrace === 'block') {
                indentLevel = Math.max(indentLevel - 1, 0);
            } else {
                formattedCode += char;
            }
            i++;
            continue;
        } else if (char === '\n') {
            // Handle newlines and indentation
            formattedCode += '\n' + ' '.repeat(indentLevel * indentSize);
            i++;
            continue;
        } else {
            formattedCode += char;
            i++;
            continue;
        }
    }

    if (braceStack.length > 0) {
        formatError('Unmatched opening brace(s)');
        return '';
    }

    return formattedCode.trimEnd();
}