1e296fba177a36ba945bdd1eafd99d7bd1491afc
[hs-java.git] / Java / META / Spec.hs
1 module Java.META.Spec where
2
3 import Control.Monad
4 import Control.Monad.Error
5 import qualified Data.Map as M
6 import Data.Map ((!))
7 import Data.Char (toLower)
8
9 import Java.META.Types
10
11 class MetaSpec s where
12   loadFirstSection :: Section -> s
13
14   loadOtherSection :: s -> Section -> s
15   loadOtherSection s _ = s
16
17   storeMeta :: s -> META
18
19 loadSpec :: (MetaSpec s) => META -> s
20 loadSpec [] = error "Cannot load empty metadata"
21 loadSpec (s:ss) =
22   let x = loadFirstSection s
23   in  foldl loadOtherSection x ss
24
25 lookupList :: String -> Maybe String -> [(String, String)]
26 lookupList _ Nothing = []
27 lookupList name (Just val) = [(name, val)]
28
29 bool2string :: Bool -> String
30 bool2string True = "true"
31 bool2string False = "false"
32
33 string2bool :: String -> Bool
34 string2bool s
35   | map toLower s == "true" = True
36   | otherwise = False
37