Skip to content

Instantly share code, notes, and snippets.

@gagern
Created July 7, 2015 17:38
Show Gist options
  • Select an option

  • Save gagern/ea839d9a12e3bdf357c9 to your computer and use it in GitHub Desktop.

Select an option

Save gagern/ea839d9a12e3bdf357c9 to your computer and use it in GitHub Desktop.
Call graph for the KaTeX Parser
"use strict";
var fs = require("fs");
var src = fs.readFileSync("src/Parser.js", "utf-8");
var match;
var defined = {};
var callers = {};
var curMethod = "TOP";
var re = /Parser\.prototype\.([A-Za-z0-9_]+)|this\.([A-Za-z0-9_]+)/g;
while ((match = re.exec(src))) {
if (match[1]) {
curMethod = match[1];
defined[curMethod] = true;
} else {
var name = match[2];
callers[name] = callers[name] || {};
callers[name][curMethod] = true;
}
}
defined = Object.keys(defined);
defined.sort();
defined.forEach(function(name) {
var c = Object.keys(callers[name] || {});
c.sort();
c.forEach(function(caller) {
console.log(caller + " -> " + name + ";");
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment