]> gitweb @ CieloNegro.org - Rakka.git/blobdiff - Rakka/Wiki/Interpreter.hs
Resurrection from bitrot
[Rakka.git] / Rakka / Wiki / Interpreter.hs
index bfaab67b0cd742d2ea0f02b7ebaf7b0913fffa9a..6bce1d06032f31277acf8be2a09285b2effa4adf 100644 (file)
@@ -1,58 +1,46 @@
+{-# LANGUAGE
+    UnicodeSyntax
+  #-}
 module Rakka.Wiki.Interpreter
     ( Interpreter(..)
+    , InterpreterContext(..)
 
     , commandName -- private
     , commandType -- private
-
-    , pureInlineInterp
-    , pureBlockInterp
     )
     where
-
-import           Rakka.Page
-import           Rakka.Storage
-import           Rakka.SystemConfig
-import           Rakka.Wiki
-
+import Data.Text (Text)
+import Rakka.Page
+import Rakka.Storage
+import Rakka.SystemConfig
+import Rakka.Wiki
+import Text.XML.HXT.DOM.TypeDefs
 
 data Interpreter
     = InlineCommandInterpreter {
-        iciName      :: String
-      , iciInterpret :: InlineCommand
-                     -> Maybe Page
-                     -> Storage
-                     -> SystemConfig
-                     -> IO InlineElement
+        iciName      ∷ !Text
+      , iciInterpret ∷ !(InterpreterContext → InlineCommand → IO InlineElement)
       }
     | BlockCommandInterpreter {
-        bciName      :: String
-      , bciInterpret :: BlockCommand
-                     -> Maybe Page
-                     -> Storage
-                     -> SystemConfig
-                     -> IO BlockElement
+        bciName      ∷ !Text
+      , bciInterpret ∷ !(InterpreterContext → BlockCommand → IO BlockElement)
       }
 
 
-commandName :: Interpreter -> String
+data InterpreterContext
+    = InterpreterContext {
+        ctxPageName   :: !(Maybe PageName)
+      , ctxMainPage   :: !(Maybe XmlTree)
+      , ctxMainWiki   :: !(Maybe WikiPage)
+      , ctxTargetWiki :: !WikiPage
+      , ctxStorage    :: !Storage
+      , ctxSysConf    :: !SystemConfig
+      }
+
+commandName ∷ Interpreter → Text
 commandName (InlineCommandInterpreter name _) = name
 commandName (BlockCommandInterpreter  name _) = name
 
-
-commandType :: Interpreter -> CommandType
+commandType ∷ Interpreter → CommandType
 commandType (InlineCommandInterpreter _ _) = InlineCommandType
 commandType (BlockCommandInterpreter  _ _) = BlockCommandType
-
-
-pureInlineInterp :: String
-                 -> (InlineCommand -> Maybe Page -> InlineElement)
-                 -> Interpreter
-pureInlineInterp name f
-    = InlineCommandInterpreter name $ \ cmd page _ _ -> return $ f cmd page
-
-
-pureBlockInterp :: String
-                -> (BlockCommand -> Maybe Page -> BlockElement)
-                -> Interpreter
-pureBlockInterp name f
-    = BlockCommandInterpreter name $ \ cmd page _ _ -> return $ f cmd page