Last active
December 11, 2015 15:47
-
-
Save lucs/cd3e912f20d6953f480b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use v6; | |
# Match : X aX baX | |
# No match : cX aaX | |
grammar Goo { | |
my %seen; | |
# Allow at most only one each of 'a' or 'b' per match. | |
token TOP { | |
<!{ %seen = () }> <ab>? <ab>? 'X' | |
} | |
token ab { | |
('a' | 'b') <?{ | |
sub ($a_or_b) { | |
my $seen = $a_or_b ~~ %seen; | |
%seen{$a_or_b} = True; | |
! $seen; | |
}.($0) | |
}> | |
} | |
} | |
for ( :X, :aX, :baX, :!bbX, :!cX, ) { | |
my ($str, $should-match) = $_.kv; | |
my $match = Goo.parse($str); | |
say ($match.Bool == $should-match) | |
?? "Okay: $str" | |
!! ($should-match ?? "? " !! "! ") ~ "{$str}" | |
; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment