X-Git-Url: https://ruin.nu/git/?a=blobdiff_plain;f=Wiki.hs;h=64c46028bdcd8dd51d204037457e5bba4302866b;hb=d18786bdb428f24b6a5aea32c1b1e64339591708;hp=bcfd23694a025b65363372dbb3f4f1ac0fa48978;hpb=80f11c089c02ef7a3f13404121715ca0f4d4d281;p=yawbih.git diff --git a/Wiki.hs b/Wiki.hs index bcfd236..64c4602 100644 --- a/Wiki.hs +++ b/Wiki.hs @@ -1,17 +1,22 @@ module Wiki ( - Backend + Backend (getCurrent,getList,get,setCurrent,update) ,PGB + ,createPGB + ,Markup (Text, Paragraph, Link) + ,Document + ,wikiParser ) where import Dbconnect import Data.Char +import Text.ParserCombinators.Parsec class Backend a where --Keyword -> (Full text,date) getCurrent :: a -> String -> IO (Maybe (String,String)) - --Keyword -> [(id,date)] + --Keyword -> [(id,date,author,comment)] getList :: a -> String -> IO [(String, String, String, String)] --Keyword -> id -> Full text @@ -23,6 +28,52 @@ class Backend a where --Keyword -> Full text -> id update :: a -> String -> String -> String -> String -> IO String +data Markup = Text String + | Paragraph + | Link String String + +type Document = [Markup] + +wikiParser :: GenParser Char st Document +wikiParser = do + s <- (try (pPara) + <|> pOneEol + <|> try (pLinkLong) + <|> pLink + <|> pText) + ss <- (wikiParser <|> return []) + return (s:ss) + +pPara = do + pEol + pEol + return (Paragraph) + +pOneEol = do + pEol + return (Text " ") + +pEol = char '\n' <|> do + char '\r' + char '\n' + +pLinkLong = do + string "[[" + l <- many1 $ noneOf ['|','[',']'] + char '|' + d <- many1 $ noneOf ['|','[',']'] + string "]]" + return (Link l d) +pLink = do + string "[[" + l <- many1 $ noneOf ['|','[',']'] + string "]]" + return (Link l l) + +pText = do + t <- many1 (noneOf ['\n','\r','[',']']) + return (Text t) + newtype PGB = PGB DBService createPGB :: String -> String -> String -> String -> IO PGB @@ -47,20 +98,16 @@ instance Backend PGB where setCurrent (PGB db) key id = do full <- selectReturnTuples db $ "SELECT keyword FROM fulltexts WHERE keyword="++tov key++" AND id='"++id++"'" - cur <- selectReturnTuples db $ "SELECT keyword FROM curtexts WHERE keyword='"++tov key++"'" + cur <- selectReturnTuples db $ "SELECT keyword FROM curtexts WHERE keyword="++tov key case full of [[]] -> do - print "No text found with this id and key" return False _ -> do rows <- case cur of - [] -> do - print "No link found in current, inserting" - execute db $ "INSERT INTO current (keyword, id) VALUES ("++tov id++","++tov key++")" + [[]] -> do + execute db $ "INSERT INTO current (keyword, id) VALUES ("++tov key++","++tov id++")" _ -> do - print "Link found in current, updating" execute db $ "UPDATE current SET id = "++tov id++" WHERE keyword = "++tov key - print rows if rows == 1 then return True else return False