@ -202,6 +202,10 @@ PEG.Grammar.ZeroOrMore = function(element) { this._element = element; };
PEG . Grammar . OneOrMore = function ( element ) { this . _element = element ; } ;
PEG . Grammar . AndPredicate = function ( expression ) {
this . _expression = expression ;
} ;
PEG . Grammar . NotPredicate = function ( expression ) {
this . _expression = expression ;
} ;
@ -245,6 +249,9 @@ PEG.Grammar.extendNodes("checkReferencedRulesExist", {
OneOrMore :
function ( grammar ) { this . _element . checkReferencedRulesExist ( grammar ) ; } ,
AndPredicate :
function ( grammar ) { this . _expression . checkReferencedRulesExist ( grammar ) ; } ,
NotPredicate :
function ( grammar ) { this . _expression . checkReferencedRulesExist ( grammar ) ; } ,
@ -298,6 +305,11 @@ PEG.Grammar.extendNodes("checkNoLeftRecursion", {
this . _element . checkNoLeftRecursion ( grammar , appliedRules ) ;
} ,
AndPredicate :
function ( grammar , appliedRules ) {
this . _expression . checkNoLeftRecursion ( grammar , appliedRules ) ;
} ,
NotPredicate :
function ( grammar , appliedRules ) {
this . _expression . checkNoLeftRecursion ( grammar , appliedRules ) ;
@ -917,6 +929,33 @@ PEG.Grammar.NotPredicate.prototype.compile = function(resultVar) {
) ;
} ;
PEG . Grammar . AndPredicate . prototype . compile = function ( resultVar ) {
var savedPosVar = PEG . Compiler . generateUniqueIdentifier ( "savedPos" ) ;
var savedReportMatchFailuresVar = PEG . Compiler . generateUniqueIdentifier ( "savedReportMatchFailuresVar" ) ;
var expressionResultVar = PEG . Compiler . generateUniqueIdentifier ( "result" ) ;
return PEG . Compiler . formatCode (
"var ${savedPosVar} = this._pos;" ,
"var ${savedReportMatchFailuresVar} = context.reportMatchFailures;" ,
"context.reportMatchFailures = false;" ,
"${expressionCode}" ,
"context.reportMatchFailures = ${savedReportMatchFailuresVar};" ,
"if (${expressionResultVar} !== null) {" ,
" var ${resultVar} = '';" ,
" this._pos = ${savedPosVar};" ,
"} else {" ,
" var ${resultVar} = null;" ,
"}" ,
{
expressionCode : this . _expression . compile ( expressionResultVar ) ,
expressionResultVar : expressionResultVar ,
savedPosVar : savedPosVar ,
savedReportMatchFailuresVar : savedReportMatchFailuresVar ,
resultVar : resultVar
}
) ;
} ;
PEG . Grammar . RuleRef . prototype . compile = function ( resultVar ) {
return PEG . Compiler . formatCode (
"var ${resultVar} = this.${ruleMethod}(context);" ,