-
-
Save RayMPerry/520fc9762fd3a49cd0e5d7ba34766b1a 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; | |
use Grammar::Debugger; | |
use Grammar::Tracer; | |
grammar PasswordChecker { | |
# rule TOP { ^^ <minimum> '-' <maximum> <ws>* <letter> ':' <ws>* <password> $$ } | |
rule TOP { <digit>+ '-' <digit>+ <ws>* <alpha> ':' <ws>* <alnum>+ } | |
} | |
sub check-password-validity(@inputs) { | |
PasswordChecker.parse(@inputs[0]);# for @inputs; | |
} | |
sub MAIN() { | |
# my $pattern = / <digit>+ '-' <digit>+ <ws>* <alpha> ':' <ws>* <alnum>+ /; | |
my @passwords = '1-3 a: abcde', '1-3 b: cdefg', '2-9 c: ccccccccc'; | |
return @passwords[0] ~~ $pattern; # for @inputs; | |
} | |
DOC CHECK { | |
use Test; | |
subtest 'Example input' => { | |
my @passwords = '1-3 a: abcde', '1-3 b: cdefg', '2-9 c: ccccccccc'; | |
check-password-validity(@passwords).&is(2); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment