Skip to content

Instantly share code, notes, and snippets.

@samcv
Created November 20, 2016 03:53
Show Gist options
  • Save samcv/5ee9cf0aa6386902e49016f6e4a672f7 to your computer and use it in GitHub Desktop.
Save samcv/5ee9cf0aa6386902e49016f6e4a672f7 to your computer and use it in GitHub Desktop.
grammar url {
regex TOP { <anyprotocol> '://' <base> [ ['/' <term>]+ ]? '/'? }
token anyprotocol { <[ a..z A..Z ]> <[ a..z A..Z 0..9 . + - ]>+ }
token protocol {:i [http|https|ftp|git|ssh] }
token baseascii { [ <[a..z A..Z 0..9 \- . ]> ]+ }
token base { [ <:Number + :Letter + [ . - ]> ]+ }
token protected { <[ $ + ! * ( ) , . ; ? @ = % & # " ' ]> }
token allowed { \S }
regex term { <allowed>+ <!after <protected>> }
# token after { '/' <term> }
}
say url.parse("https://google.com");
say url.parse("https://google.com/something");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment