silverstripe-framework/thirdparty/php-peg/examples/EqualRepeat.peg.inc
2011-02-14 14:58:57 +13:00

37 lines
740 B
PHP

<?php
require '../Parser.php' ;
class EqualRepeat extends Packrat {
/* Any number of a followed by the same number of b and the same number of c characters
* aabbcc - good
* aaabbbccc - good
* aabbc - bad
* aabbacc - bad
*/
/*!* Grammar1
A: "a" A? "b"
B: "b" B? "c"
T: !"b"
X: &(A !"b") "a"+ B !("a" | "b" | "c")
*/
}
function match( $str ) {
$p = new EqualRepeat( $str ) ;
$r = $p->match_X() ;
print "$str\n" ;
print $r ? print_r( $r, true ) : 'No Match' ;
print "\n\n" ;
}
match( 'aabbcc' ) ; // Should match
match( 'aaabbbccc' ) ; // Should match
match( 'aabbbccc' ) ; // Should not match
match( 'aaabbccc' ) ; // Should not match
match( 'aaabbbcc' ) ; // Should not match
match( 'aaabbbcccc' ) ; // Should not match