Skip to content

Instantly share code, notes, and snippets.

@RayMPerry
Created December 17, 2020 21:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save RayMPerry/520fc9762fd3a49cd0e5d7ba34766b1a to your computer and use it in GitHub Desktop.
Save RayMPerry/520fc9762fd3a49cd0e5d7ba34766b1a to your computer and use it in GitHub Desktop.
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