<commit_before>var VCs;
var verifying = false;

function submitAnswer() {
    /* Protect against multiple requests */
//    if(verifying)
//        return;
//    verifying = true;
//    $("#right .footette").attr("class", "footetteDisabled");

    // Get student's code
    var content = createEditor.getValue();
    console.log(content);

    // Find all the confirm statements
    var regex = new RegExp("Confirm [^;]*;", "mg");
    var confirms = content.match(regex);
    console.log(confirms);

    // Remove the "Confirm " so that we can find the variable names
    var statement = confirms[0];
    statement = statement.substr(8);
    console.log(statement);

    // Split the string at the conditional
    regex = new RegExp("[<>=]");
    var parts = statement.split(regex);
    console.log(parts);

    // Find the variables use on the left side
    var left = parts[0];
    var right = parts[0];
    regex = new RegExp("[a-zA-Z]", "g");
    var variables = left.match(regex);
    console.log(variables);

    // Search for these variables on the right side
    variable = variables[0];
    regex = new RegExp("[^#]" + variable, "g");
    var trivials = right.match(regex);
    console.log(trivials);

//    getVCLines(createEditor.getValue());
}

function getVCLines(content) {
    removeAllVCMarkers();
    var socket = new WebSocket("wss://resolve.cs.clemson.edu/teaching/Compiler?job=genVCs&project=Teaching_Project");

    socket.onmessage = function(message) {
        if(!verifying) return;

        // Extract the array of VCs from the message (trust me, this works)
        message = JSON.parse(message.data);
        if(message.status == "error") {
            $("#dialog-message").html("Your code is syntactically incorrect and thus could not be verified.");
            $("#dialog-box").dialog("open");
            verifying = false;
            $("#right .footetteDisabled").attr("class", "footette");

            createEditor.focus();
            return;
        }
        if(message.status != "complete") {
            return;
        }

        if(message.result == "") {
            $("#dialog-message").html("Your code could not be verified; try a simpler answer and only use declared variables.");
            $("#dialog-box").dialog("open");
        verifying = false;
        $("#right .footetteDisabled").attr("class", "footette");

        createEditor.focus();
        return;
        }

        message = decode(message.result);
        message = $(message).text();
        message = JSON.parse(message);

        // Simplify the VC information
        VCs = [];
        $.each(message.vcs, function (index, obj) {
            if (typeof obj.vc !== "undefined") VCs.push(obj);
        });

        addVCMarkers();
        verifyVCs(createEditor.getValue());
    };

    content = encode(content);<commit_msg>Finished initial regex check for trivials.<commit_after>var VCs;
var verifying = false;

function submitAnswer() {
    /* Protect against multiple requests */
    if(verifying)
        return;
    verifying = true;
    $("#right .footette").attr("class", "footetteDisabled");

    // Get student's code
    var content = createEditor.getValue();
    
    // Find all the confirm statements
    var regex = new RegExp("Confirm [^;]*;", "mg");
    var confirms = content.match(regex);
    if (confirms.length == 0) {
        $("#dialog-message").html("Sorry! Could not find Confirm statements.");
        $("#dialog-box").dialog("open");
        verifying = false;
        $("#right .footetteDisabled").attr("class", "footette");
            
        createEditor.focus();
        return;
    }
    
    var i;
    for (i = 0 ; i < confirms.length ; i++) {
        // Remove the "Confirm " so that we can find the variable names
        var statement = confirms[i];
        statement = statement.substr(8);
        
        // Split the string at the conditional
        regex = new RegExp("[<>=]");
        var parts = statement.split(regex);
        if (parts.length != 2) {
            $("#dialog-message").html("Sorry! That is not what we are looking for.");
            $("#dialog-box").dialog("open");
            verifying = false;
            $("#right .footetteDisabled").attr("class", "footette");
                
            createEditor.focus();
            return;
        }
        
        // Find the variables used on the left side
        var left = parts[0];
        var right = parts[1];
        regex = new RegExp("[a-zA-Z]", "g");
        var variables = left.match(regex);
        if (variables == null)
            continue;
        
        // Search for these variables on the right side
        var j;
        for (j = 0 ; j < variables.length ; j++) {
            variable = variables[j];
            regex = new RegExp("[^#]" + variable, "g");
            if (right.search(regex) > -1) {
                $("#dialog-message").html("Sorry! Cannot use a variable to define itself.");
                $("#dialog-box").dialog("open");
                verifying = false;
                $("#right .footetteDisabled").attr("class", "footette");
                
                createEditor.focus();
                return;
            }
        }
    }

    getVCLines(createEditor.getValue());
}

function getVCLines(content) {
    removeAllVCMarkers();
    var socket = new WebSocket("wss://resolve.cs.clemson.edu/teaching/Compiler?job=genVCs&project=Teaching_Project");

    socket.onmessage = function(message) {
        if(!verifying) return;

        // Extract the array of VCs from the message (trust me, this works)
        message = JSON.parse(message.data);
        if(message.status == "error") {
            $("#dialog-message").html("Your code is syntactically incorrect and thus could not be verified.");
            $("#dialog-box").dialog("open");
            verifying = false;
            $("#right .footetteDisabled").attr("class", "footette");

            createEditor.focus();
            return;
        }
        if(message.status != "complete") {
            return;
        }

        if(message.result == "") {
            $("#dialog-message").html("Your code could not be verified; try a simpler answer and only use declared variables.");
            $("#dialog-box").dialog("open");
            verifying = false;
            $("#right .footetteDisabled").attr("class", "footette");
            
            createEditor.focus();
            return;
        }

        message = decode(message.result);
        message = $(message).text();
        message = JSON.parse(message);

        // Simplify the VC information
        VCs = [];
        $.each(message.vcs, function (index, obj) {
            if (typeof obj.vc !== "undefined") VCs.push(obj);
        });

        addVCMarkers();
        verifyVCs(createEditor.getValue());
    };

    content = encode(content);
{'fraction_non_alphanumeric': 0.1481427530954115, 'fraction_numerical': 0.0018936635105608157, 'mean_word_length': 2.120909090909091, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 6, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '476849', 'n_tokens_mistral': 1897, 'n_tokens_neox': 1841, 'n_words': 488}