dmajda/pegjs — pull request #211 by Mingun (2013-09-22 11:15:26+00:00)
Title: Decompiler of bytecode

Small function in compilator to decompile bytecode. May be used as (in Node.JS):
```js
var utils = require('/lib/utils');
function convertPasses(passes) {
var converted = {}, stage;
for (stage in passes) {
converted[stage] = utils.values(passes[stage]);
}
return converted;
}
function disasmRule(bc) {
var result = PEG.compiler.decompile(bc);//<< IT IS!!
for (var i = 0; i < result.length; ++i) {
console.log(result[i].join('\t'))
}
}

var ast = PEG.parser.parse(data);
var passes = convertPasses(PEG.compiler.passes);
var code = PEG.compiler.compile(ast, passes, {output:'source'});
// Print bytecode of each rule in grammar
for (var i = 0; i < ast.rules.length; ++i) {
console.log(ast.rules[i].name);
disasm(ast.rules[i].bytecode);
}
```