3 ms·
As someone who likes both Go and Perl 6, this reminds me a lot of Perl 6 grammars; I look forward to using this in Go. Here's a rough equivalent in P6, although
by muraiki 11y ago
As someone who likes both Go and Perl 6, this reminds me a lot of Perl 6 grammars; I look forward to using this in Go. Here's a rough equivalent in P6, although I don't think the Go one or mine are completely legit in terms of internationalization and whatnot:
grammar email-address {
token TOP { ^ <user> '@' <hostname> $ }
token user { <[ \w \d . _ % + - ]>+ }
token hostname { <domain> '.' <TLD> }
token domain { \w+ }
token TLD { \w+ }
}
if (my $email = email-address.parse('joe@猫.com')) {
say $email<user>;
say $email<hostname><domain>;
say $email<hostname><TLD>;
}
It's also possible to turn the captured parts into their own objects ($email has a type of Match; it's not just a hash).