Skip to content

Instantly share code, notes, and snippets.

@samcv
Created November 18, 2016 00:14
Show Gist options
  • Save samcv/7c1fc86a742880a8234c208c642a0ea8 to your computer and use it in GitHub Desktop.
Save samcv/7c1fc86a742880a8234c208c642a0ea8 to your computer and use it in GitHub Desktop.
#!/usr/bin/env perl6
grammar http {
regex TOP { .* <url> .* }
regex url { <protocol> <protocoldel> <body>? (<after>+)? }
token protocol { (http)|(https)|(ftp)|(git)|(ssh) }
token protocoldel { '://' }
token body { <units>+ }
token units { <:Letter>|'.' }
token after { <seperator> (<allowed>+)? }
token seperator { '/' }
token allowed { <[a..z A..Z % & . = ? ]> }
}
sub MAIN ( Str $string ) {
my $match = http.parse($string);
say $match.gist;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment