Skip to content

Instantly share code, notes, and snippets.

@evilstreak
Created December 18, 2009 20:09
Show Gist options
  • Save evilstreak/259726 to your computer and use it in GitHub Desktop.
Save evilstreak/259726 to your computer and use it in GitHub Desktop.
// usage: flusspferd tree.js grammar.peg inputfile
const peg = require( "PEG_generator" ),
fs = require( "fs-base" ),
system = require( "system" );
var grammar = fs.rawOpen( system.args[ 1 ], "r" ).readWhole(),
input = fs.rawOpen( system.args[ 2 ], "r" ).readWhole(),
names = eval( peg.generateParserThrowing( grammar ) ),
root = names[ 0 ],
tree = this[ root ]( input );
if ( !tree[ 0 ] ) throw "Parsing failed";
print( peg.showTree( tree[ 1 ], names ) );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment