module ParseURL where import ParsOps1 import URL import Data.Char(isAlpha,isDigit) parseURL s = parse url s where url = absolute <$> proto <*> host <*> port <*> path <*> fragment proto = maybeP (chars isAlpha <* lit ':') host = maybeP (lits "//" *> chars (`notElem` ":/")) port = maybeP (lit ':' *> (read <$> chars isDigit)) path = chars0 (/='#') fragment = maybeP (lit '#' *> some token) -- absolute "file" Nothing Nothing path = Relative path absolute proto host port path fragment = URL proto host port path' fragment where path' = if path=="" && host/=Nothing then "/" else path