Skip to content

Instantly share code, notes, and snippets.

Tokenizer.prototype.padTokens = function(text) {
tokenized = text.replace(/ ?([,\(\)\/\[\]\+\*\-]+) ?/g, " $1 ");
tokenized = tokenized.replace(/ ?([,]) ?/g, " $1 ");
tokenized = tokenized.replace(/- >/g, "->")
tokenized = tokenized.replace(/ ?(==) ?/g, " $1 ");
tokenized = tokenized.replace(/;/g, " ;");
tokenized = tokenized.replace(/\s{2,}/g, " ");
return tokenized;
}
Tokenizer.prototype.resetNewlines = function(text) {
nlText = text.replace(/\n/g, "").replace(/\;/g, ";\n");
nlText = nlText.replace(/\}/g, "}\n").replace(/\{/g, "\n{\n");
nlText = nlText.replace(/\n[ ]+/g, "\n");
nlText = nlText.replace(/\n$/, "");
return nlText;
}
Tokenizer.prototype.trimWhitespace = function(text) {
cleanedText = text.replace(/\n+/g, "\n");
cleanedText = cleanedText.replace(/[ ]+/g, " ");
cleanedText = cleanedText.trim();
return cleanedText;
}
Tokenizer.prototype.stripComments = function(text) {
return text.replace(/\/\/[^\n]+/g, "");
}
@backupbrain
backupbrain / 0_reuse_code.js
Created November 15, 2016 00:29
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console