var fs = require('fs'),
    util = require('util'),
    jison = require('jison');

var lexer = require('./lib/parser/bison/lexer'),
    grammar = require('./lib/parser/bison/grammar'),
    operators = require('./lib/parser/bison/operators');

var gen = new jison.Generator({
    lex: lexer,
    bnf: grammar,
    operators: operators.reverse(),
    startSymbol: 'Root'
});

var source = gen.generateModule();
source += '\nvar nodes = require("./nodes/all");\nexports.parse = function(source) { var p = new parser.Parser(); p.yy = nodes; return p.parse(source);};';
fs.writeFileSync('lib/parser/parser.generated.js', source);


// Test -----------------------------------------------------------------------
// ----------------------------------------------------------------------------

// Some simple tests
var Ast = require('./lib/parser/Ast');

var source = 'l += (!foo.bar[2]((2 ** 2 // 2), foo, 4))[2:@foo]';
var tree = new Ast(source);
console.log(util.inspect(tree.tree, false, 10));

//console.log(tree.toString());

tree.visit(function(node, parent, depth) {
    console.log(new Array(depth * 4).join(' '), ' -', node.type, '=>', node.toString());

}, true);

//var code = '~!(+true) + (-2) * (++e) / 5 * foo()[2..(1 - 3)] + @foo.bar[2 + 2] - (a ? b : c) // 2 + @ + a > b && c < d || 4 != 5 - foo(1, 2, 3, foo = 2 + 2, bla...)';


@@ -802,16 +802,42 @@
 e tests%0A
+function testAST() %7B%0A%0A    
 var Ast 
@@ -864,24 +864,28 @@
 ser/Ast');%0A%0A
+    
 var source =
@@ -938,16 +938,20 @@
 @foo%5D';%0A
+    
 var tree
@@ -970,16 +970,20 @@
 ource);%0A
+    
 console.
@@ -1024,16 +1024,20 @@
  10));%0A%0A
+    
 //consol
@@ -1061,16 +1061,20 @@
 ng());%0A%0A
+    
 tree.vis
@@ -1108,24 +1108,28 @@
 epth) %7B%0A    
+   
+ 
 console.log(
@@ -1202,16 +1202,20 @@
 ng());%0A%0A
+    
 %7D, true)
@@ -1217,16 +1217,20 @@
 true);%0A%0A
+    
 //var co
@@ -1391,8 +1391,339 @@
 ...)';%0A%0A
+%0A%7D%0A%0Avar Compiler = require('./lib/compiler/Compiler');%0A%0Avar emblem = new Compiler();%0A%0A// Test name resolving%0Aemblem.compile('modules.mod'); // File%0Aemblem.compile('modules.bar.test'); // File%0Aemblem.compile('modules.bar.ignore'); // file%0Aemblem.compile('modules.bar.lum'); // Index%0Aemblem.compile('modules.bar.foo.test'); // File%0A%0A

Make use of the compiler for testing