Created
March 10, 2015 16:27
-
-
Save hjkatz/e3b8f79dbcf23e16cd81 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
grammar URL | |
{ | |
token TOP | |
{ | |
<schema> '://' | |
[<ip> | <hostname> ] | |
[ ':' <port>]? | |
'/' <path>? | |
} | |
token byte | |
{ | |
(\d**1..3) <?{ $0 < 256 }> | |
} | |
token ip | |
{ | |
<byte> [\. <byte> ] ** 3 | |
} | |
token schema | |
{ | |
\w+ | |
} | |
token hostname | |
{ | |
(\w+) ( \. \w+ )* | |
} | |
token port | |
{ | |
\d+ | |
} | |
token path | |
{ | |
<[ a..z A..Z 0..9 \-_.!~*'():@&=+$,/ ]>+ | |
} | |
} | |
subset NonEmptyString of Str where *.chars >= 0; | |
subset UrlToken of NonEmptyString where { $_ ~~ /^TOP$/ | /^byte$/ | /^ip$/ | /^schema$/ | /^hostname$/ | /^port$/ | /^path$/ }; | |
sub MAIN( NonEmptyString $string, UrlToken $token ) | |
{ | |
my $match = URL.parse($string); | |
say $match{$token}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment