@ -16,48 +16,6 @@ var arrays = require("../../utils/arrays"),
* it can lead to left recursion .
* it can lead to left recursion .
* /
* /
function reportLeftRecursion ( ast ) {
function reportLeftRecursion ( ast ) {
function matchesEmptyTrue ( ) { return true ; }
function matchesEmptyFalse ( ) { return false ; }
function matchesEmptyExpression ( node ) {
return matchesEmpty ( node . expression ) ;
}
var matchesEmpty = visitor . build ( {
rule : matchesEmptyExpression ,
choice : function ( node ) {
return arrays . some ( node . alternatives , matchesEmpty ) ;
} ,
action : matchesEmptyExpression ,
sequence : function ( node ) {
return arrays . every ( node . elements , matchesEmpty ) ;
} ,
labeled : matchesEmptyExpression ,
text : matchesEmptyExpression ,
simple _and : matchesEmptyTrue ,
simple _not : matchesEmptyTrue ,
optional : matchesEmptyTrue ,
zero _or _more : matchesEmptyTrue ,
one _or _more : matchesEmptyExpression ,
semantic _and : matchesEmptyTrue ,
semantic _not : matchesEmptyTrue ,
rule _ref : function ( node ) {
return matchesEmpty ( asts . findRule ( ast , node . name ) ) ;
} ,
literal : function ( node ) {
return node . value === "" ;
} ,
"class" : matchesEmptyFalse ,
any : matchesEmptyFalse
} ) ;
var check = visitor . build ( {
var check = visitor . build ( {
rule : function ( node , visitedRules ) {
rule : function ( node , visitedRules ) {
check ( node . expression , visitedRules . concat ( node . name ) ) ;
check ( node . expression , visitedRules . concat ( node . name ) ) ;
@ -69,7 +27,7 @@ function reportLeftRecursion(ast) {
check ( element , visitedRules ) ;
check ( element , visitedRules ) ;
}
}
return matchesEmpty( element ) ;
return asts. matchesEmpty( ast , element ) ;
} ) ;
} ) ;
} ,
} ,