@ -16,27 +16,14 @@ module.exports = {
generateJavascript : require ( "./compiler/passes/generate-javascript" )
} ,
/ *
* Names of passes that will get run during the compilation ( in the specified
* order ) .
* /
appliedPassNames : [
"reportMissingRules" ,
"reportLeftRecursion" ,
"removeProxyRules" ,
"generateBytecode" ,
"generateJavascript"
] ,
/ *
* Generates a parser from a specified grammar AST . Throws | PEG . GrammarError |
* if the AST contains a semantic error . Note that not all errors are detected
* during the generation and some may protrude to the generated parser and
* cause its malfunction .
* /
compile : function ( ast ) {
var that = this ,
options = arguments . length > 1 ? utils . clone ( arguments [ 1 ] ) : { } ;
compile : function ( ast , passes ) {
var options = arguments . length > 2 ? utils . clone ( arguments [ 2 ] ) : { } ;
utils . defaults ( options , {
allowedStartRules : [ ast . rules [ 0 ] . name ] ,
@ -45,9 +32,7 @@ module.exports = {
output : "parser"
} ) ;
utils . each ( this . appliedPassNames , function ( passName ) {
that . passes [ passName ] ( ast , options ) ;
} ) ;
utils . each ( passes , function ( p ) { p ( ast , options ) ; } ) ;
switch ( options . output ) {
case "parser" : return eval ( ast . code ) ;