]> ruin.nu Git - yawbih.git/blobdiff - Wiki.hs
More cleanup
[yawbih.git] / Wiki.hs
diff --git a/Wiki.hs b/Wiki.hs
index a2b6548509f8282f73af4d2059216c4b91c23673..a2d2ff220b019e2b2b02d791da408f1300938a50 100644 (file)
--- 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 "</pre>"
        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