<commit_before>var _ = require("lodash");
var scope_helper = require("./scope_helper");
var utils = require("../utility/utils");

var get_symbol_table = function(parse_tree){
    if(parse_tree === null){
        return {
            "Error": "Syntax Error"
        };
    }
    else{
        var sym_table = scope_helper.populate_scope(parse_tree);
        return sym_table;
    }
};
module.exports.get_symbol_table = get_symbol_table;

var get_scope_list = function(sym_table){
    var scope_list = {};
    var scope_type_count = {};
    var traverse = function(scope, parent){
        if(scope_type_count[scope.scope_type]) scope_type_count[scope.scope_type]++;
        else scope_type_count[scope.scope_type] = 0;

        var scope_name = scope.scope_type+scope_type_count[scope.scope_type];

        if(parent) scope_name =  parent + "/" + scope_name;

        scope_list[scope_name] = _.clone(scope);
        delete scope_list[scope_name].scopes;

        for(var i = 0; i < scope.scopes.length; i++) traverse(scope.scopes[i], scope_name);
    };
    traverse(sym_table, null);
    return scope_list;
};
module.exports.get_scope_list = get_scope_list;

var get_function_list = function(sym_table){
    var function_list = _.filter(sym_table.namespace.ordinary_ids, {"name_type": "function"});
    var function_scope_list = _.filter(sym_table.scopes, {"scope_type": "function_scope"});
    for( var i = 0; i < function_list.length; i++){
        for(var j = 0; j < function_scope_list.length; j++){
            var declaration_location = {
                "row": function_list[i].token.row,
                "col": function_list[i].token.col
            };
            if(utils.is_enclosed_inside(declaration_location, function_scope_list[j].range)){
                function_list[i]["parameters"] = _.filter(function_scope_list[j].namespace.ordinary_ids,
                                                        {"name_type": "function", "parameter": true});
                function_list[i]["range"] = _.clone(function_scope_list[j].range);
                break;
            }
        }
    }
    return function_list;
};
module.exports.get_function_list = get_function_list;<commit_msg>Changes response format for get_function_list API<commit_after>var _ = require("lodash");
var scope_helper = require("./scope_helper");
var utils = require("../utility/utils");

var get_symbol_table = function(parse_tree){
    if(parse_tree === null){
        return {
            "Error": "Syntax Error"
        };
    }
    else{
        var sym_table = scope_helper.populate_scope(parse_tree);
        return sym_table;
    }
};
module.exports.get_symbol_table = get_symbol_table;

var get_scope_list = function(sym_table){
    var scope_list = {};
    var scope_type_count = {};
    var traverse = function(scope, parent){
        if(scope_type_count[scope.scope_type]) scope_type_count[scope.scope_type]++;
        else scope_type_count[scope.scope_type] = 0;

        var scope_name = scope.scope_type+scope_type_count[scope.scope_type];

        if(parent) scope_name =  parent + "/" + scope_name;

        scope_list[scope_name] = _.clone(scope);
        delete scope_list[scope_name].scopes;

        for(var i = 0; i < scope.scopes.length; i++) traverse(scope.scopes[i], scope_name);
    };
    traverse(sym_table, null);
    return scope_list;
};
module.exports.get_scope_list = get_scope_list;

var get_function_list = function(sym_table){
    var function_list = _.filter(sym_table.namespace.ordinary_ids, {"name_type": "function"});
    var function_scope_list = _.filter(sym_table.scopes, {"scope_type": "function_scope"});
    for( var i = 0; i < function_list.length; i++){
        for(var j = 0; j < function_scope_list.length; j++){
            function_list[i]["declaration_location"] = {
                "row": function_list[i].token.row,
                "col": function_list[i].token.col
            };
            delete function_list[i].token;
            if(utils.is_enclosed_inside(function_list[i].declaration_location, function_scope_list[j].range)){
                function_list[i]["parameters"] = _.filter(function_scope_list[j].namespace.ordinary_ids,
                                                        {"name_type": "function", "parameter": true});
                function_list[i]["range"] = _.clone(function_scope_list[j].range);
                break;
            }
        }
    }
    return function_list;
};
module.exports.get_function_list = get_function_list;
{'fraction_non_alphanumeric': 0.12916851934192974, 'fraction_numerical': 0.0017785682525566918, 'mean_word_length': 2.87510766580534, 'pattern_counts': {'":': 14, '<': 9, '<?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': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2114448', 'n_tokens_mistral': 1405, 'n_tokens_neox': 1363, 'n_words': 231}