Paste: Ugly URL parser
Author: | slava |
Mode: | factor |
Date: | Fri, 26 Sep 2008 23:25:52 |
Plain Text |
<PRIVATE
EBNF: parse-url
protocol = [a-z]+ => [[ url-decode ]]
username = [^/:@#?]+ => [[ url-decode ]]
password = [^/:@#?]+ => [[ url-decode ]]
pathname = [^#?]+ => [[ url-decode ]]
query = [^#]+ => [[ query>assoc ]]
anchor = .+ => [[ url-decode ]]
hostname = [^/#?]+ => [[ url-decode ]]
hostname-spec = hostname ("/"|!(.)) => [[ first ]]
auth = (username (":" password => [[ second ]])? "@"
=> [[ first2 2array ]])?
url = ((protocol "://") => [[ first ]] auth hostname)?
(pathname)?
("?" query => [[ second ]])?
("#" anchor => [[ second ]])?
;EBNF
PRIVATE>
M: string >url
parse-url {
[
first [
[ first ]
[
second
[ first [ first2 ] [ f f ] if* ]
[ second parse-host ]
bi
] bi
] [ f f f f f ] if*
]
[ second ]
[ third ]
[ fourth ]
} cleave url boa
dup host>> [ [ "/" or ] change-path ] when ;
New Annotation