Skip to content

Instantly share code, notes, and snippets.

@dalinaum
Created January 16, 2011 23:54
Show Gist options
  • Save dalinaum/782278 to your computer and use it in GitHub Desktop.
Save dalinaum/782278 to your computer and use it in GitHub Desktop.
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 \-_.!~*'():@&=+$,/ ]>+
}
}
my $match = URL.parse('http://perl6.org/documentation/');
say $match<hostname>; # perl6.org
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment