module System.Debian.ControlParser(control, depPart)
where
import Text.ParserCombinators.Parsec
import Data.String.Utils (split)
eol, extline :: GenParser Char st String
eol = (try (string "\r\n"))
<|> string "\n" <?> "EOL"
extline = try (do char ' '
content <- many (noneOf "\r\n")
eol
return content )
entry :: GenParser Char st (String, String)
entry = do key <- many1 (noneOf ":\r\n")
char ':'
val <- many (noneOf "\r\n")
eol
exts <- many extline
return (key, unlines ([val] ++ exts))
control :: CharParser a [(String, String)]
control = do many header
retval <- many entry
return retval
headerPGP, blankLine, header, headerHash :: GenParser Char st ()
headerPGP = do string "-----BEGIN PGP"
manyTill (noneOf "\r\n") eol
return ()
blankLine = do many (oneOf " \t")
eol
return ()
headerHash = do string "Hash: "
manyTill (noneOf "\r\n") eol
return ()
header = (try headerPGP) <|> (try blankLine) <|> (try headerHash)
depPart :: CharParser a (String, (Maybe (String, String)), [String])
depPart = do packagename <- many1 (noneOf " (")
many (char ' ')
version <- (do char '('
op <- many1 (oneOf "<>=")
many (char ' ')
vers <- many1 (noneOf ") ")
many (char ' ')
char ')'
return $ Just (op, vers)
) <|> return Nothing
many (char ' ')
archs <- (do char '['
t <- many1 (noneOf "]")
many (char ' ')
char ']'
return (split " " t)
) <|> return []
return (packagename, version, archs)