aboutsummaryrefslogtreecommitdiff
path: root/lib/node.js
blob: 571cdd80046241abe73c4b6e86f8e500842427da (about) (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#! /usr/bin/env node

(function(){

    var fs = require("fs");
    var vm = require("vm");
    var sys = require("util");

    function load_global(file) {
        var code = fs.readFileSync(file, "utf8");
        return vm.runInThisContext(code, file);
    };

    load_global("./utils.js");
    load_global("./output.js");
    load_global("./ast.js");
    load_global("./parse.js");

    ///

    var filename = process.argv[2];
    console.time("parse");
    var ast = parse(fs.readFileSync(filename, "utf8"));
    console.timeEnd("parse");

    console.time("walk");
    var w = new TreeWalker(function(node){
        console.log(node.TYPE + " [ start: " + node.start.line + ":" + node.start.col + ", end: " + node.end.line + ":" + node.end.col + "]");
    });
    ast.walk(w);
    console.timeEnd("walk");

})();