<commit_before>/*
 *
 */
"use strict";

goog.provide("Entry.PyToBlockParser");

Entry.PyToBlockParser = function(blockSyntax) {
    this.blockSyntax = blockSyntax;
};

(function(p){
    p.Program = function(node) {
        if(node.type != 'Program') return;
        var code = [];
        var thread = []; 

        var nodes = node.body;

        for(var index in nodes) {
            var node = nodes[index];
            var result = this[node.type](node);
            
            thread.push({
                type: result.block
            });
        }

        code.push(thread);

        return code;
    };

    p.Identifier = function(node) {
        console.log("Identifier", node);
        var name = node.name;
        return {
            name: name
        };
    };

    p.Literal = function(node) {
        console.log("Literal", node);
        console.log("typeof node at Literal", typeof node.value);

        var value;
        if(typeof node.value === 'string') {
            value = node.value; 
        } 
        else if(typeof node.value === 'boolean') {
            value = node.value;
        } 
        else if(typeof node.value === null) {
            value = node.value;
        }
        else if(typeof node.value === 'number') {
            value = node.value;
        } 
        else if(typeof node.value === 'RegExp') {
            var value = this[typeof node.value](node);
            value = value.regex.pattern;
        }
        else {
            value = null;
        }

        console.log("value", value);

        return {
            value: value 
        };

    };

    p.RegExp = function(node) {
        console.log("RegExp", node);
        var regex = node.regex;
        return {
            regex: regex
        };
    };

    p.Function = function(node) {
        console.log("Function", node);
        var id = this[node.id](node);
        
        var params = [];
        for(var index in node.params){
            var param = node.params[index];
            params.push(param);
        }

        var body = this[node.body](node);

        return {
            id: id,
            params: params,
            body: body
        };
    };

    p.ExpressionStatement = function(node) { 
        console.log("ExpressionStatement", node);
        var expression = this[node.expression.type](node.expression);
        console.log("ExpressionStatement", expression);

        console.log("expression", expression);

        var targetSyntax = String(expression.callee.object.name).concat(".").concat(expression.callee.property.name);
        console.log("ts", targetSyntax);

        var block = this.blockSyntax[targetSyntax];

        console.log("block", block);

        return {
            block: block
        }        

        /*return {
            expresstion: expression
        }*/
    };

    p.BlockStatement = function(node) {
        console.log("BlockStatement", node);
       var bodies = [];
       for(var index in node.body) {
            var statment = node.body[index];
            var body = this[statement.type](statement);
            bodies.push(body);
        }

        return {
            body: bodies 
        };
    };

    p.EmptyStatement = function(node) {
        console.log("EmptyStatement", node);<commit_msg>pyToBlock<commit_after>/*
 *
 */
"use strict";

goog.provide("Entry.PyToBlockParser");

Entry.PyToBlockParser = function(blockSyntax) {
    this.blockSyntax = blockSyntax;
};

(function(p){
    p.Program = function(node) {
        if(node.type != 'Program') return;
        var code = [];
        var thread = []; 

        var nodes = node.body;

        for(var index in nodes) {
            var node = nodes[index];
            var result = this[node.type](node);
            
            thread.push({
                type: result.block
            });
        }

        code.push(thread);

        return code;
    };

    p.Identifier = function(node) {
        console.log("Identifier", node);
        var name = node.name;
        return {
            name: name
        };
    };

    p.Literal = function(node) {
        console.log("Literal", node);
        console.log("typeof node at Literal", typeof node.value);

        var value;
        if(typeof node.value === 'string') {
            value = node.value; 
        } 
        else if(typeof node.value === 'boolean') {
            value = node.value;
        } 
        else if(typeof node.value === null) {
            value = node.value;
        }
        else if(typeof node.value === 'number') {
            value = node.value;
        } 
        else if(typeof node.value === 'RegExp') {
            var value = this[typeof node.value](node);
            value = value.regex.pattern;
        }
        else {
            value = null;
        }

        console.log("value", value);

        return {
            value: value 
        };

    };

    p.RegExp = function(node) {
        console.log("RegExp", node);
        var regex = node.regex;
        return {
            regex: regex
        };
    };

    p.Function = function(node) {
        console.log("Function", node);
        var id = this[node.id](node);
        
        var params = [];
        for(var index in node.params){
            var param = node.params[index];
            params.push(param);
        }

        var body = this[node.body](node);

        return {
            id: id,
            params: params,
            body: body
        };
    };

    p.ExpressionStatement = function(node) { 
        console.log("ExpressionStatement", node);
        var expression = this[node.expression.type](node.expression);
        console.log("ExpressionStatement", expression);

        console.log("expression", expression);

        var targetSyntax = String(expression.callee.object.name).concat(".").concat(expression.callee.property.name);
        console.log("target syntax", targetSyntax);

        var block = this.blockSyntax[targetSyntax];

        console.log("block", block);

        return {
            block: block
        }        

        /*return {
            expresstion: expression
        }*/
    };

    p.BlockStatement = function(node) {
        console.log("BlockStatement", node);
       var bodies = [];
       for(var index in node.body) {
            var statment = node.body[index];
            var body = this[statement.type](statement);
            bodies.push(body);
        }

        return {
            body: bodies 
        };
    };

    p.EmptyStatement = function(node) {
        console.log("EmptyStatement", node);
{'fraction_non_alphanumeric': 0.1304282039642911, 'fraction_numerical': 0.0, 'mean_word_length': 1.5659937888198758, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '4803296', 'n_tokens_mistral': 1838, 'n_tokens_neox': 1767, 'n_words': 376}