I have a feeling that you are applying Perl approach to Raku (underscore naming, not being explicit about unicode awareness, escaping instead of quoting constants in regexps).
There is nothing wrong with that - TIMTOWTDI. However grammars are first class citizens in Raku and that allows to write it in normalized manner:
sub parse-date($_) {
my token year { <[0..9]> ** 4 }
my token month { <[0..9]> ** 2 }
my token day { <[0..9]> ** 2 }
if /
<year> '-' <month> '-' <day> |
<year> '/' <month> '/' <day> |
<day> '/' <month> '/' <year>
/ {
[+$<year>, +$<month>, +$<day>]
}
}
It took me a while to unlearn creating bulky Perl regexps. Old habits die hard. Regexp interpolation in Perl was tricky and normalization was often avoided. But it is really worth it as it produces much cleaner and less error prone code in Raku.
BTW: token do not backtrack as opposed to regex.
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
I have a feeling that you are applying Perl approach to Raku (underscore naming, not being explicit about unicode awareness, escaping instead of quoting constants in regexps).
There is nothing wrong with that - TIMTOWTDI. However grammars are first class citizens in Raku and that allows to write it in normalized manner:
It took me a while to unlearn creating bulky Perl regexps. Old habits die hard. Regexp interpolation in Perl was tricky and normalization was often avoided. But it is really worth it as it produces much cleaner and less error prone code in Raku.
BTW:
token
do not backtrack as opposed toregex
.