mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
37 lines
740 B
PHP
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
|