<commit_before>/*Loads various types of files for the gadget, as well as the gadget and API themselves.*/
function load(url, type) {
   load.loaders[type.split("/")[0]](url, load.loaders[type])
}
load.loaders = {}
load.loaders.text = function(url, loader) {
    $.get(url, "", loader);
}

load.loaders["text/javascript"] = function(text) {
    function replaceRegex(pattern, params, callback) {
      //find pattern in text
      //find params
      //replace matched string with return of callback
   }
   function insertAfter(text, after, text) {
      //find charactor
      //insert after it.
   }

   var sharedMethods = sharedMethods.keys();
   replaceRegex(/^;\w*sharedMethods\.\n+\w*=\w*function(.*) {.*}$/, [/^\.\n$/, /^(.*)$/], function(text, method, args) {
      sharedMethods.push(method.substr(1,method.length);
      //do not overwrite existing.
      text = insertAfter(text, "{", "if (this"+method+") this"+method+args+";//PRESERVE");
      return text;
   }
   replaceRegex(/^;.+=[.|\{.*\}|(.*)|'.*'|".*"]+;$/, [], function(text) {
      //replace = with .set()
   }
   for (var i=0; i < sharedMethods.length; i++) {
      method = sharedMethods[i];
      replaceRegex("."+method, [/;.*;/, /^\\\\PRESERVE$/], function(text, preserve) {
         if (preserve) return text;
         //split by method
         //place call at beginning and call "sharedMethods."method".call(" obj", " args")"
      }
   }

    eval(text);
    return self;
}
var sharedMethods = {}
sharedMethods.keys = function() {
   var keys = ["keys",];
   for (var key in this) keys.push key;
   return keys;
}<commit_msg>Documenting PyOfWave's client gadget environment's resource loader.<commit_after>/*Loads various types of files for the gadget, as well as the gadget and API themselves.*/

/*Load a resource at URL with a MIME type of type.*/
function load(url, type) {
   load.loaders[type.split("/")[0]](url, load.loaders[type])
}
load.loaders = {}
/*The plain text loader.*/
load.loaders.text = function(url, loader) {
    $.get(url, "", loader);
}

/*The JavaScript generator.
  TODO: Figure out how to write this tidily, perhaps by Python or a hint from CoffeeScript.*/
load.loaders["text/javascript"] = function(text) {
    function replaceRegex(pattern, params, callback) {
      //find pattern in text
      //find params
      //replace matched string with return of callback
   }
   function insertAfter(text, after, text) {
      //find charactor
      //insert after it.
   }

   var sharedMethods = sharedMethods.keys();
   replaceRegex(/^;\w*sharedMethods\.\n+\w*=\w*function(.*) {.*}$/, [/^\.\n$/, /^(.*)$/], function(text, method, args) {
      sharedMethods.push(method.substr(1,method.length);
      //do not overwrite existing.
      text = insertAfter(text, "{", "if (this"+method+") this"+method+args+";//PRESERVE");
      return text;
   });
   replaceRegex(/^;.+=[.|\{.*\}|(.*)|'.*'|".*"]+;$/, [], function(text) {
      //replace = with .set()
   });
   for (var i=0; i < sharedMethods.length; i++) {
      method = sharedMethods[i];
      replaceRegex("."+method, [/;.*;/, /^\\\\PRESERVE$/], function(text, preserve) {
         if (preserve) return text;
         //split by method
         //place call at beginning and call "sharedMethods."method".call(" obj", " args")"
      });
   }

    eval(text);
    return self;
}

/*Create shared methods for use by JavaScript interpretor.*/
var sharedMethods = {}
/*Get all keys of an object.*/
sharedMethods.keys = function() {
   var keys = ["keys",];
   for (var key in this) keys.push key;
   return keys;
}
{'fraction_non_alphanumeric': 0.18840985442329228, 'fraction_numerical': 0.0016797312430011197, 'mean_word_length': 2.943708609271523, 'pattern_counts': {'":': 0, '<': 5, '<?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': '4417070', 'n_tokens_mistral': 1147, 'n_tokens_neox': 1121, 'n_words': 308}