]> gitweb @ CieloNegro.org - Rakka.git/blob - Rakka/Wiki/Interpreter.hs
bfaab67b0cd742d2ea0f02b7ebaf7b0913fffa9a
[Rakka.git] / Rakka / Wiki / Interpreter.hs
1 module Rakka.Wiki.Interpreter
2     ( Interpreter(..)
3
4     , commandName -- private
5     , commandType -- private
6
7     , pureInlineInterp
8     , pureBlockInterp
9     )
10     where
11
12 import           Rakka.Page
13 import           Rakka.Storage
14 import           Rakka.SystemConfig
15 import           Rakka.Wiki
16
17
18 data Interpreter
19     = InlineCommandInterpreter {
20         iciName      :: String
21       , iciInterpret :: InlineCommand
22                      -> Maybe Page
23                      -> Storage
24                      -> SystemConfig
25                      -> IO InlineElement
26       }
27     | BlockCommandInterpreter {
28         bciName      :: String
29       , bciInterpret :: BlockCommand
30                      -> Maybe Page
31                      -> Storage
32                      -> SystemConfig
33                      -> IO BlockElement
34       }
35
36
37 commandName :: Interpreter -> String
38 commandName (InlineCommandInterpreter name _) = name
39 commandName (BlockCommandInterpreter  name _) = name
40
41
42 commandType :: Interpreter -> CommandType
43 commandType (InlineCommandInterpreter _ _) = InlineCommandType
44 commandType (BlockCommandInterpreter  _ _) = BlockCommandType
45
46
47 pureInlineInterp :: String
48                  -> (InlineCommand -> Maybe Page -> InlineElement)
49                  -> Interpreter
50 pureInlineInterp name f
51     = InlineCommandInterpreter name $ \ cmd page _ _ -> return $ f cmd page
52
53
54 pureBlockInterp :: String
55                 -> (BlockCommand -> Maybe Page -> BlockElement)
56                 -> Interpreter
57 pureBlockInterp name f
58     = BlockCommandInterpreter name $ \ cmd page _ _ -> return $ f cmd page