X-Git-Url: https://ruin.nu/git/?a=blobdiff_plain;f=Wiki.hs;h=a2d2ff220b019e2b2b02d791da408f1300938a50;hb=6bb9a6da06d8911d0fc2dd821705323fa3beb0dc;hp=a2b6548509f8282f73af4d2059216c4b91c23673;hpb=64b58e5b75b4c8e95574fa9080166f5cf1079005;p=yawbih.git diff --git a/Wiki.hs b/Wiki.hs index a2b6548..a2d2ff2 100644 --- a/Wiki.hs +++ b/Wiki.hs @@ -46,20 +46,16 @@ data Markup = Text String type Document = [Markup] wikiParser :: GenParser Char st Document -wikiParser = do - s <- pMain - ss <- (wikiParser <|> return []) - return (s:ss) +wikiParser = many1 pMain pPara = do pEol pEol return (Paragraph) - pSpace = do - space - return (Text " ") + c <- space + return (Text (c:[])) pEol = char '\n' <|> do char '\r' @@ -92,17 +88,9 @@ pS s f = do s <- pStopAt s return (f s) -pStopAt xs = do - try (string xs >> return []) <|> (do - s <- pMain - ss <- pStopAt xs - return (s:ss)) - -pString xs = do - try (string xs >> return []) <|> (do - s <- anyChar - ss <- pString xs - return (s:ss)) +pStopAt xs = pUntil pMain xs +pString xs = pUntil anyChar xs +pUntil p xs = manyTill p (try $ string xs) pHeading = do many1 pEol @@ -122,36 +110,34 @@ pPre = do s <- pString "" return (Pre s) -pMain = try (pHeading) - <|> (try (pPara) - <|> pSpace - <|> try(pPre) - <|> try(pBold) - <|> try(pEmph) - <|> try(pUnderline) - <|> try(pStrike) - <|> try (pLink) - <|> try (pURL) - <|> pOtherChar - <|> pText) +pMain = choice [ + try (pHeading) + ,try (pPara) + ,pSpace + ,try(pPre) + ,try(pBold) + ,try(pEmph) + ,try(pUnderline) + ,try(pStrike) + ,try (pLink) + ,try (pURL) + ,pOtherChar + ,pText + ] pOtherChar = do c <- oneOf "*,;.:!?[]()'\"=-%$£<>/\\|" return (Text (c:[])) pText = do - t <- many1 alphaNum--(noneOf ['\n','\r','[',']']) + t <- many1 alphaNum return (Text t) - newtype PGB = PGB DBService createPGB :: String -> String -> String -> String -> IO PGB createPGB host database user password = let db = createDBService host database "" user password Nothing in return (PGB db) - -testDB = createPGB "wave" "wiki" "wiki" "12wiki34db" - instance Backend PGB where getCurrent (PGB db) key = do @@ -196,7 +182,7 @@ instance Backend PGB where return id listKeys (PGB db) = do - list <- selectReturnTuples db $ "SELECT keyword FROM fulltexts GROUP BY keyword ORDER BY lower(keyword)" + list <- selectReturnTuples db $ "SELECT keyword FROM current keyword ORDER BY lower(keyword)" case list of [[]] -> return [] _ -> mapM (\[key] -> return key) list