X-Git-Url: http://git.cielonegro.org/gitweb.cgi?p=Lucu.git;a=blobdiff_plain;f=Network%2FHTTP%2FLucu%2FParser%2FHttp.hs;h=c1b30fc208c1d6bbbb787911f642c52de7ef3288;hp=021ced85d9856cef8d48d7ffb3bcef4575854ffa;hb=3c7a58ab749a55a30466a033b170536bcdf18b98;hpb=9961a721f98b101825ef154a2122c1fc2fa6d1ac diff --git a/Network/HTTP/Lucu/Parser/Http.hs b/Network/HTTP/Lucu/Parser/Http.hs index 021ced8..c1b30fc 100644 --- a/Network/HTTP/Lucu/Parser/Http.hs +++ b/Network/HTTP/Lucu/Parser/Http.hs @@ -1,7 +1,12 @@ module Network.HTTP.Lucu.Parser.Http ( isCtl -- Char -> Bool , isSeparator -- Char -> Bool - , token -- Parser Char + , isChar -- Char -> Bool + , token -- Parser String + , lws -- Parser String + , text -- Parser Char + , separator -- Parser Char + , quotedStr -- Parser String ) where @@ -21,5 +26,41 @@ isSeparator :: Char -> Bool isSeparator c = elem c "()<>@,;:\\\"/[]?={} \t" -token :: Parser Char -token = satisfy (\ c -> not (isCtl c || isSeparator c)) +isChar :: Char -> Bool +isChar c + | c <= '\x7f' = True + | otherwise = False + + +token :: Parser String +token = many1 $ satisfy (\ c -> not (isCtl c || isSeparator c)) + + +lws :: Parser String +lws = do s <- option "" crlf + xs <- many1 (sp <|> ht) + return (s ++ xs) + + +text :: Parser Char +text = satisfy (\ c -> not (isCtl c)) + + +separator :: Parser Char +separator = satisfy isSeparator + + +quotedStr :: Parser String +quotedStr = do char '"' + xs <- many (qdtext <|> quotedPair) + char '"' + return $ foldr (++) "" (["\""] ++ xs ++ ["\""]) + where + qdtext = char '"' >> fail "" + <|> + do c <- text + return [c] + + quotedPair = do q <- char '\\' + c <- satisfy isChar + return [q, c]